[writer] remove nix outputting, remove support for raw storage
This commit is contained in:
parent
cb1c7772e8
commit
222c3a9ce1
106
writer.cpp
106
writer.cpp
@ -2,6 +2,12 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <pylon/VideoWriter.h>
|
#include <pylon/VideoWriter.h>
|
||||||
|
#include <chrono>
|
||||||
|
using namespace std::chrono;
|
||||||
|
typedef high_resolution_clock Time;
|
||||||
|
typedef milliseconds ms;
|
||||||
|
typedef duration<float> fsec;
|
||||||
|
|
||||||
|
|
||||||
void Writer::setVideoSpecs(VideoSpecs specs) {
|
void Writer::setVideoSpecs(VideoSpecs specs) {
|
||||||
videoSpecs = specs;
|
videoSpecs = specs;
|
||||||
@ -41,111 +47,35 @@ void Writer::run() {
|
|||||||
qDebug() << "checks done!";
|
qDebug() << "checks done!";
|
||||||
|
|
||||||
Pylon::CVideoWriter videoWriter;
|
Pylon::CVideoWriter videoWriter;
|
||||||
if (specs_valid) {
|
if (specs_valid && videoSpecs.format != VideoFormat::raw) {
|
||||||
stop_request = false;
|
stop_request = false;
|
||||||
stopNow = false;
|
stopNow = false;
|
||||||
if (videoSpecs.format == VideoFormat::raw) {
|
videoWriter.SetParameter((uint32_t)videoSpecs.width, (uint32_t)videoSpecs.height,
|
||||||
myFile.open(videoSpecs.filename, std::ios::out | std::ios::binary);
|
videoSpecs.pixelType, (double)videoSpecs.fps, videoSpecs.quality);
|
||||||
myFile.write((char*)&videoSpecs.width, 4);
|
videoWriter.Open(videoSpecs.filename.c_str());
|
||||||
myFile.write((char*)&videoSpecs.height, 4);
|
|
||||||
} else {
|
|
||||||
qDebug() << "setting parameters for video";
|
|
||||||
videoWriter.SetParameter((uint32_t)videoSpecs.width, (uint32_t)videoSpecs.height, videoSpecs.pixelType, (double)videoSpecs.fps, videoSpecs.quality);
|
|
||||||
videoWriter.Open(videoSpecs.filename.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
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::Section s = nix_file.createSection("Recording", "nix.recording");
|
|
||||||
b.metadata(s);
|
|
||||||
nix::Value v(nix::util::timeToStr(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())));
|
|
||||||
s.createProperty("date", v);
|
|
||||||
|
|
||||||
nix::Value fn(videoSpecs.filename);
|
|
||||||
s.createProperty("moviefile", fn);
|
|
||||||
nix::Section sw_sec = s.createSection("PylonRecorder", "nix.software");
|
|
||||||
sw_sec.createProperty("version", nix::Value(1));
|
|
||||||
|
|
||||||
nix::Section hw_sec = s.createSection("Basler ACA2040-120um", "nix.hardware.camera");
|
|
||||||
hw_sec.createProperty("type", nix::Value("monochrome"));
|
|
||||||
hw_sec.createProperty("manufacturer", nix::Value("Basler AG"));
|
|
||||||
nix::Property p = hw_sec.createProperty("framerate", nix::Value(static_cast<int>(videoSpecs.fps)));
|
|
||||||
p.unit("Hz");
|
|
||||||
nix::Property p1 = hw_sec.createProperty("exposure time", nix::Value(static_cast<int>(videoSpecs.exposureTime)));
|
|
||||||
p1.unit("us");
|
|
||||||
nix::Property p2 = hw_sec.createProperty("detector gain", nix::Value(static_cast<int>(videoSpecs.detectorGain)));
|
|
||||||
p2.unit("dB");
|
|
||||||
|
|
||||||
if (metadata_valid) {
|
|
||||||
writeMetadata(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
nix::NDSize initial_shape(1, chunksize);
|
|
||||||
nix::DataArray frametimes = b.createDataArray("frametimes", "nix.imaging.frametimes", nix::DataType::String, initial_shape);
|
|
||||||
frametimes.label("time");
|
|
||||||
frametimes.appendSetDimension();
|
|
||||||
nix::DataArray frameindices = b.createDataArray("frameindex", "nix.imaging.frameid", nix::DataType::Int64, initial_shape);
|
|
||||||
frameindices.appendSetDimension();
|
|
||||||
|
|
||||||
std::vector<std::string> stamps_buffer(chunksize);
|
|
||||||
std::vector<int64_t> ids_buffer(chunksize);
|
|
||||||
|
|
||||||
nix::NDSize offset(1, 0);
|
|
||||||
nix::NDSize current_shape(initial_shape);
|
|
||||||
nix::NDSize chunk_shape(1, chunksize);
|
|
||||||
|
|
||||||
qDebug() << "preparations done, starting loop!";
|
qDebug() << "preparations done, starting loop!";
|
||||||
while ((!stop_request || buffer->bufferLoad() > 0) && !stopNow) {
|
while ((!stop_request || buffer->bufferLoad() > 0) && !stopNow) {
|
||||||
if (buffer->bufferLoad() > 0 ) {
|
if (buffer->bufferLoad() > 0 ) {
|
||||||
size_t framecount = 0;
|
size_t framecount = 0;
|
||||||
MyImage *img = buffer->read(framecount);
|
MyImage *img = buffer->read(framecount);
|
||||||
if (img != nullptr) {
|
if (img != nullptr) {
|
||||||
if (videoSpecs.format == VideoFormat::raw) {
|
Pylon::CPylonImage pyImage;
|
||||||
myFile.write((char*)img->data(), img->size());
|
try {
|
||||||
} else {
|
pyImage.AttachUserBuffer(img->data(), videoSpecs.width * videoSpecs.height, videoSpecs.pixelType, videoSpecs.width, videoSpecs.height, 0, videoSpecs.orientation);
|
||||||
Pylon::CPylonImage pyImage;
|
videoWriter.Add(pyImage);
|
||||||
try {
|
} catch (const Pylon::GenericException &e) {
|
||||||
pyImage.AttachUserBuffer(img->data(), videoSpecs.width * videoSpecs.height, videoSpecs.pixelType, videoSpecs.width, videoSpecs.height, 0, videoSpecs.orientation);
|
std::cerr << "Writer::run: An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
||||||
videoWriter.Add(pyImage);
|
|
||||||
} catch (const Pylon::GenericException &e) {
|
|
||||||
std::cerr << "Writer::run: An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (count < chunksize) {
|
|
||||||
try {
|
|
||||||
stamps_buffer[count] = nix::util::timeToStr(img->timestamp());
|
|
||||||
} catch (...) {
|
|
||||||
std::cerr << "Bad time to string conversion " << img->timestamp() << std::endl;
|
|
||||||
stamps_buffer[count] = "invalid";
|
|
||||||
}
|
|
||||||
ids_buffer[count] = img->index();
|
|
||||||
count ++;
|
|
||||||
} else {
|
|
||||||
frametimes.setData(nix::DataType::String, stamps_buffer.data(), chunk_shape, offset);
|
|
||||||
frameindices.setData(nix::DataType::Int64, ids_buffer.data(), chunk_shape, offset);
|
|
||||||
current_shape += initial_shape;
|
|
||||||
frametimes.dataExtent(current_shape);
|
|
||||||
frameindices.dataExtent(current_shape);
|
|
||||||
offset[0] += chunksize;
|
|
||||||
count = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (buffer->bufferLoad() < 1 && !stop_request) {
|
while (buffer->bufferLoad() < 1 && !stop_request) {
|
||||||
msleep(5);
|
msleep(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count > 0) {
|
|
||||||
chunk_shape[0] = count;
|
|
||||||
frametimes.setData(nix::DataType::String, stamps_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();
|
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Got no video specifications, not writing!" << std::endl;
|
qDebug() << "Got no video specifications, not writing!";
|
||||||
}
|
}
|
||||||
emit writingDone();
|
emit writingDone();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user