[writer] write raw data to file
This commit is contained in:
parent
af29f526f2
commit
80c3555f87
@ -689,7 +689,7 @@ std::string PylonRecorder::createFilename() {
|
|||||||
QDateTime dt(QDateTime::currentDateTimeUtc());
|
QDateTime dt(QDateTime::currentDateTimeUtc());
|
||||||
QDate date = dt.date();
|
QDate date = dt.date();
|
||||||
std::string base = (date.toString("yyyy.MM.dd") + "_").toStdString();
|
std::string base = (date.toString("yyyy.MM.dd") + "_").toStdString();
|
||||||
std::string extension = ".avi";
|
std::string extension = ".raw";
|
||||||
QString idx = QString::number(movieCount);
|
QString idx = QString::number(movieCount);
|
||||||
std::string fname = base + idx.toStdString() + extension;
|
std::string fname = base + idx.toStdString() + extension;
|
||||||
while (QFile::exists(QString::fromStdString(fname))) {
|
while (QFile::exists(QString::fromStdString(fname))) {
|
||||||
|
55
writer.cpp
55
writer.cpp
@ -1,6 +1,8 @@
|
|||||||
#include "writer.h"
|
#include "writer.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
using namespace std::chrono;
|
||||||
|
|
||||||
void Writer::setVideoSpecs(VideoSpecs specs) {
|
void Writer::setVideoSpecs(VideoSpecs specs) {
|
||||||
videoSpecs = specs;
|
videoSpecs = specs;
|
||||||
@ -25,14 +27,22 @@ void Writer::writeMetadata(nix::Section &s){
|
|||||||
void Writer::run() {
|
void Writer::run() {
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
size_t chunksize = 256;
|
size_t chunksize = 256;
|
||||||
|
// size_t framecount = 0;
|
||||||
if (specs_valid) {
|
if (specs_valid) {
|
||||||
stop_request = false;
|
stop_request = false;
|
||||||
stopNow = false;
|
stopNow = false;
|
||||||
Pylon::CVideoWriter videoWriter;
|
|
||||||
videoWriter.SetParameter(videoSpecs.width, videoSpecs.height, videoSpecs.pixelType,
|
std::ofstream myFile;
|
||||||
videoSpecs.fps, videoSpecs.quality);
|
myFile.open(videoSpecs.filename, std::ios::out | std::ios::binary);
|
||||||
videoWriter.Open(videoSpecs.filename.c_str());
|
myFile.write((char*)&videoSpecs.width, 4);
|
||||||
|
myFile.write((char*)&videoSpecs.height, 4);
|
||||||
|
// Pylon::CVideoWriter videoWriter;
|
||||||
|
// videoWriter.SetParameter(videoSpecs.width, videoSpecs.height, videoSpecs.pixelType,
|
||||||
|
// videoSpecs.fps, videoSpecs.quality);
|
||||||
|
// std::cout << !Pylon::CVideoWriter::IsSupported() << std::endl;
|
||||||
|
// videoWriter.SetParameter();
|
||||||
|
// videoWriter.Open(videoSpecs.filename.c_str());
|
||||||
|
// std::cerr << "Video writer is open!" << videoWriter.IsOpen() << std::endl;
|
||||||
nix::File nix_file =nix::File::open(videoSpecs.filename + ".nix", nix::FileMode::Overwrite, "hdf5", nix::Compression::DeflateNormal);
|
nix::File nix_file =nix::File::open(videoSpecs.filename + ".nix", nix::FileMode::Overwrite, "hdf5", nix::Compression::DeflateNormal);
|
||||||
nix::Block b = nix_file.createBlock("Recording", "nix.recording");
|
nix::Block b = nix_file.createBlock("Recording", "nix.recording");
|
||||||
nix::Section s = nix_file.createSection("Recording", "nix.recording");
|
nix::Section s = nix_file.createSection("Recording", "nix.recording");
|
||||||
@ -72,21 +82,29 @@ void Writer::run() {
|
|||||||
nix::NDSize offset(1, 0);
|
nix::NDSize offset(1, 0);
|
||||||
nix::NDSize current_shape(initial_shape);
|
nix::NDSize current_shape(initial_shape);
|
||||||
nix::NDSize chunk_shape(1, chunksize);
|
nix::NDSize chunk_shape(1, chunksize);
|
||||||
MyImage img;
|
|
||||||
while ((!stop_request || buffer->bufferLoad() > 0) && !stopNow) {
|
while ((!stop_request || buffer->bufferLoad() > 0) && !stopNow) {
|
||||||
if (buffer->bufferLoad() > 0 ) {
|
if (buffer->bufferLoad() > 0 ) {
|
||||||
bool valid = buffer->pop(img);
|
MyImage *img = buffer->pop();
|
||||||
if (valid) {
|
if (img != nullptr) {
|
||||||
Pylon::CPylonImage pyImage;
|
auto start = high_resolution_clock::now();
|
||||||
try {
|
// framecount += 1;
|
||||||
pyImage.AttachUserBuffer(img.data(), videoSpecs.width * videoSpecs.height, videoSpecs.pixelType, videoSpecs.width, videoSpecs.height, 0, videoSpecs.orientation);
|
myFile.write((char*)img->data(), img->size());
|
||||||
videoWriter.Add( pyImage );
|
|
||||||
} catch (const Pylon::GenericException &e) {
|
// Pylon::CPylonImage pyImage;
|
||||||
std::cerr << "Writer::run: An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
// try {
|
||||||
}
|
// pyImage.AttachUserBuffer(img->data(), videoSpecs.width * videoSpecs.height, videoSpecs.pixelType, videoSpecs.width, videoSpecs.height, 0, videoSpecs.orientation);
|
||||||
|
// // Test duration of writing...
|
||||||
|
// videoWriter.Add( pyImage );
|
||||||
|
|
||||||
|
// } catch (const Pylon::GenericException &e) {
|
||||||
|
// std::cerr << "Writer::run: An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
||||||
|
// }
|
||||||
|
auto stop = high_resolution_clock::now();
|
||||||
|
auto duration = duration_cast<microseconds>(stop - start);
|
||||||
|
std::cerr << "wrote binary to file " << duration.count() << std::endl;
|
||||||
if (count < chunksize) {
|
if (count < chunksize) {
|
||||||
stamps_buffer[count] = nix::util::timeToStr(img.timestamp());
|
stamps_buffer[count] = nix::util::timeToStr(img->timestamp());
|
||||||
ids_buffer[count] = img.index();
|
ids_buffer[count] = img->index();
|
||||||
count ++;
|
count ++;
|
||||||
} else {
|
} else {
|
||||||
frametimes.setData(nix::DataType::String, stamps_buffer.data(), chunk_shape, offset);
|
frametimes.setData(nix::DataType::String, stamps_buffer.data(), chunk_shape, offset);
|
||||||
@ -109,7 +127,8 @@ void Writer::run() {
|
|||||||
frametimes.setData(nix::DataType::String, stamps_buffer.data(), chunk_shape, offset);
|
frametimes.setData(nix::DataType::String, stamps_buffer.data(), chunk_shape, offset);
|
||||||
frameindices.setData(nix::DataType::Int64, ids_buffer.data(), chunk_shape, offset);
|
frameindices.setData(nix::DataType::Int64, ids_buffer.data(), chunk_shape, offset);
|
||||||
}
|
}
|
||||||
videoWriter.Close();
|
// videoWriter.Close();
|
||||||
|
myFile.close();
|
||||||
nix_file.close();
|
nix_file.close();
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Got no video specifications, not writing!" << std::endl;
|
std::cerr << "Got no video specifications, not writing!" << std::endl;
|
||||||
|
3
writer.h
3
writer.h
@ -9,10 +9,11 @@
|
|||||||
#include "pylonwrapper.h"
|
#include "pylonwrapper.h"
|
||||||
#include "imagebuffer.h"
|
#include "imagebuffer.h"
|
||||||
#include "projectsettings.h"
|
#include "projectsettings.h"
|
||||||
|
#include <opencv2/opencv.hpp>
|
||||||
|
|
||||||
struct VideoSpecs {
|
struct VideoSpecs {
|
||||||
std::string filename;
|
std::string filename;
|
||||||
uint32_t width, height, quality = 95;
|
uint32_t width, height, quality = 10 ;
|
||||||
int fps;
|
int fps;
|
||||||
double exposureTime;
|
double exposureTime;
|
||||||
double detectorGain;
|
double detectorGain;
|
||||||
|
Loading…
Reference in New Issue
Block a user