[writer] add nix to dependencies, add nix output for timestamps
This commit is contained in:
parent
efe357e8ea
commit
f31d6d4119
@ -22,10 +22,12 @@ SOURCES = \
|
|||||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/imageviewer
|
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/widgets/imageviewer
|
||||||
INSTALLS += target
|
INSTALLS += target
|
||||||
|
|
||||||
unix:!macx: LIBS += -L$$/opt/pylon5/lib64/ -Wl,-E -lpylonbase -lpylonutility -lGenApi_gcc_v3_1_Basler_pylon -lGCBase_gcc_v3_1_Basler_pylon
|
unix:!macx: LIBS += -L$$/opt/pylon5/lib64/ -Wl,-E -lpylonbase -lpylonutility -lGenApi_gcc_v3_1_Basler_pylon -lGCBase_gcc_v3_1_Basler_pylon -lnix
|
||||||
|
|
||||||
|
# pylon includes
|
||||||
INCLUDEPATH += $$/opt/pylon5/include
|
INCLUDEPATH += $$/opt/pylon5/include
|
||||||
DEPENDPATH += $$/opt/pylon5/include
|
DEPENDPATH += $$/opt/pylon5/include
|
||||||
|
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
resources.qrc
|
resources.qrc
|
||||||
|
60
writer.cpp
60
writer.cpp
@ -1,4 +1,7 @@
|
|||||||
#include "writer.h"
|
#include "writer.h"
|
||||||
|
#include <nix.hpp>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
|
||||||
void Writer::setVideoSpecs(VideoSpecs specs) {
|
void Writer::setVideoSpecs(VideoSpecs specs) {
|
||||||
videoSpecs = specs;
|
videoSpecs = specs;
|
||||||
@ -6,7 +9,9 @@ void Writer::setVideoSpecs(VideoSpecs specs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Writer::run() {
|
void Writer::run() {
|
||||||
int64_t count = 0;
|
size_t count = 0;
|
||||||
|
size_t chunksize = 1024;
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
stop_request = false;
|
stop_request = false;
|
||||||
stopNow = false;
|
stopNow = false;
|
||||||
@ -14,18 +19,61 @@ void Writer::run() {
|
|||||||
videoWriter.SetParameter(videoSpecs.width, videoSpecs.height, videoSpecs.pixelType,
|
videoWriter.SetParameter(videoSpecs.width, videoSpecs.height, videoSpecs.pixelType,
|
||||||
videoSpecs.fps, videoSpecs.quality);
|
videoSpecs.fps, videoSpecs.quality);
|
||||||
videoWriter.Open(videoSpecs.filename.c_str());
|
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("Recroding", "nix.recording");
|
||||||
|
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 ACE", "nix.hardware.camera");
|
||||||
|
hw_sec.createProperty("type", nix::Value("monochrome"));
|
||||||
|
nix::Property p = hw_sec.createProperty("framerate", nix::DataType::Int16);
|
||||||
|
nix::Value fr(videoSpecs.fps);
|
||||||
|
p.unit("Hz");
|
||||||
|
p.values({v});
|
||||||
|
|
||||||
|
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);
|
||||||
|
frametimes.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);
|
||||||
|
|
||||||
MyImage img;
|
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);
|
bool valid = buffer->pop(img);
|
||||||
if (valid) {
|
if (valid) {
|
||||||
count ++;
|
|
||||||
Pylon::CPylonImage pyImage;
|
Pylon::CPylonImage pyImage;
|
||||||
try {
|
try {
|
||||||
pyImage.AttachUserBuffer(img.data(), videoSpecs.width * videoSpecs.height, videoSpecs.pixelType, videoSpecs.width, videoSpecs.height, 0, videoSpecs.orientation);
|
pyImage.AttachUserBuffer(img.data(), videoSpecs.width * videoSpecs.height, videoSpecs.pixelType, videoSpecs.width, videoSpecs.height, 0, videoSpecs.orientation);
|
||||||
videoWriter.Add( pyImage );
|
videoWriter.Add( pyImage );
|
||||||
} catch (const Pylon::GenericException &e) {
|
} catch (const Pylon::GenericException &e) {
|
||||||
std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
std::cerr << "Writer::run: An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
||||||
|
}
|
||||||
|
if (count < chunksize) {
|
||||||
|
stamps_buffer[count] = nix::util::timeToStr(img.timestamp());
|
||||||
|
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 {
|
||||||
@ -34,7 +82,13 @@ void Writer::run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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();
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user