Compare commits
No commits in common. "dadce6994403939ade24689be293c5cb6216a8b7" and "fe20326953dd3011cd0dc9ede2668a6b2a5d6876" have entirely different histories.
dadce69944
...
fe20326953
@ -2,11 +2,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <pylon/PylonIncludes.h>
|
#include <pylon/PylonIncludes.h>
|
||||||
#include <stitchimage.h>
|
#include <stitchimage.h>
|
||||||
#include <chrono>
|
|
||||||
using namespace std::chrono;
|
|
||||||
typedef high_resolution_clock Time;
|
|
||||||
typedef milliseconds ms;
|
|
||||||
typedef duration<float> fsec;
|
|
||||||
|
|
||||||
void DualcamGrabber::run() {
|
void DualcamGrabber::run() {
|
||||||
stop_request = false;
|
stop_request = false;
|
||||||
@ -14,10 +9,9 @@ void DualcamGrabber::run() {
|
|||||||
|
|
||||||
if (wrapper->isOpen()) {
|
if (wrapper->isOpen()) {
|
||||||
Pylon::CInstantCameraArray &cameras = wrapper->getCameraArray();
|
Pylon::CInstantCameraArray &cameras = wrapper->getCameraArray();
|
||||||
wrapper->frameRate(static_cast<uint>(framerate), -1);
|
wrapper->frameRate(static_cast<uint>(framerate));
|
||||||
wrapper->exposureTime(exposure);
|
wrapper->exposureTime(exposure);
|
||||||
wrapper->gain(gain);
|
wrapper->gain(gain);
|
||||||
|
|
||||||
cameras.StartGrabbing();
|
cameras.StartGrabbing();
|
||||||
Pylon::CGrabResultPtr frame0, frame1;
|
Pylon::CGrabResultPtr frame0, frame1;
|
||||||
Pylon::CPylonImage leftImage;
|
Pylon::CPylonImage leftImage;
|
||||||
@ -25,27 +19,14 @@ void DualcamGrabber::run() {
|
|||||||
Pylon::CPylonImage stitchedImage;
|
Pylon::CPylonImage stitchedImage;
|
||||||
std::string errorMessage = "";
|
std::string errorMessage = "";
|
||||||
|
|
||||||
// int ifi = 0;
|
|
||||||
// int deviation = 0;
|
|
||||||
// std::cerr << wrapper->frameRate(0) << "\t" << wrapper->frameRate(1) << "\t" << framerate << std::endl;
|
|
||||||
// int desired_ifi = (1./wrapper->frameRate(0) * 1000000);
|
|
||||||
// auto framestart = high_resolution_clock::now();
|
|
||||||
while (cameras.IsGrabbing() && !stop_request) {
|
while (cameras.IsGrabbing() && !stop_request) {
|
||||||
// if (counter > 0) {
|
|
||||||
// deviation = desired_ifi - ifi;
|
|
||||||
// if (deviation > 0)
|
|
||||||
// // usleep(deviation);
|
|
||||||
// std::cerr << desired_ifi << "\t" << deviation << std::endl;
|
|
||||||
// }
|
|
||||||
// auto start = high_resolution_clock::now();
|
|
||||||
MyImage *img = new MyImage();
|
MyImage *img = new MyImage();
|
||||||
// auto stop1 = high_resolution_clock::now();
|
|
||||||
cameras[0].RetrieveResult( 5000, frame0, Pylon::TimeoutHandling_ThrowException );
|
cameras[0].RetrieveResult( 5000, frame0, Pylon::TimeoutHandling_ThrowException );
|
||||||
// auto stop2 = high_resolution_clock::now();
|
|
||||||
cameras[1].RetrieveResult( 5000, frame1, Pylon::TimeoutHandling_ThrowException );
|
cameras[1].RetrieveResult( 5000, frame1, Pylon::TimeoutHandling_ThrowException );
|
||||||
// auto stop3 = high_resolution_clock::now();
|
|
||||||
leftImage.AttachGrabResultBuffer( frame0 );
|
leftImage.AttachGrabResultBuffer( frame0 );
|
||||||
rightImage.AttachGrabResultBuffer( frame1 );
|
rightImage.AttachGrabResultBuffer( frame1 );
|
||||||
|
|
||||||
if (leftImage.IsValid() && rightImage.IsValid()) {
|
if (leftImage.IsValid() && rightImage.IsValid()) {
|
||||||
try {
|
try {
|
||||||
StitchImage::StitchToRight(leftImage, rightImage, &stitchedImage, errorMessage);
|
StitchImage::StitchToRight(leftImage, rightImage, &stitchedImage, errorMessage);
|
||||||
@ -55,17 +36,6 @@ void DualcamGrabber::run() {
|
|||||||
std::cerr << e.what() << '\n';
|
std::cerr << e.what() << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// auto stop4 = high_resolution_clock::now();
|
|
||||||
// auto duration1 = duration_cast<microseconds>(stop1 - start);
|
|
||||||
// auto duration2 = duration_cast<microseconds>(stop2 - stop1);
|
|
||||||
// auto duration3 = duration_cast<microseconds>(stop3 - stop2);
|
|
||||||
// auto duration4 = duration_cast<microseconds>(stop4 - stop3);
|
|
||||||
// std::cerr << "framecount: " << counter << " image constr: " << duration1.count() << "\t" << " retrieve1: " << duration2.count() << "\t" << " retrieve2: " << duration3.count() << "\t" << "conversion: " << duration4.count() << std::endl;
|
|
||||||
// ifi = duration_cast<microseconds>(stop4 - framestart).count();
|
|
||||||
// framestart = stop4;
|
|
||||||
// if (counter > 0) {
|
|
||||||
// std::cerr << "frame " << counter << " inter frame interval: " << ifi << "microseconds" << std::endl;
|
|
||||||
// }
|
|
||||||
counter += 1;
|
counter += 1;
|
||||||
}
|
}
|
||||||
cameras.StopGrabbing();
|
cameras.StopGrabbing();
|
||||||
|
@ -54,8 +54,8 @@ bool DualcamWrapper::frameRate(uint new_framerate, int camindex) {
|
|||||||
frameRate(new_framerate, 0);
|
frameRate(new_framerate, 0);
|
||||||
frameRate(new_framerate, 1);
|
frameRate(new_framerate, 1);
|
||||||
return true;
|
return true;
|
||||||
} else if (camindex >= 0 && camindex < 2) {
|
} else if (camindex == 0 && camindex ==1) {
|
||||||
GenApi::INodeMap& nodemap = getNodemap(camindex);
|
GenApi::INodeMap& nodemap = getNodemap(0);
|
||||||
GenApi::INode* n = nodemap.GetNode( "AcquisitionFrameRateEnable" );
|
GenApi::INode* n = nodemap.GetNode( "AcquisitionFrameRateEnable" );
|
||||||
Pylon::CBooleanParameter enableframerate(n);
|
Pylon::CBooleanParameter enableframerate(n);
|
||||||
enableframerate.SetValue(true);
|
enableframerate.SetValue(true);
|
||||||
@ -72,7 +72,7 @@ bool DualcamWrapper::frameRate(uint new_framerate, int camindex) {
|
|||||||
|
|
||||||
|
|
||||||
double DualcamWrapper::frameRate(int camindex) {
|
double DualcamWrapper::frameRate(int camindex) {
|
||||||
assert(camindex >= 0 && camindex < 2);
|
assert(camindex > 0 && camindex < 2);
|
||||||
double rate = -1.;
|
double rate = -1.;
|
||||||
if (valid) {
|
if (valid) {
|
||||||
GenApi::INodeMap& nodemap = getNodemap(camindex);
|
GenApi::INodeMap& nodemap = getNodemap(camindex);
|
||||||
@ -173,14 +173,14 @@ bool DualcamWrapper::grabFrame(MyImage &img, int camindex) {
|
|||||||
qDebug() << "grabFrame from camera " << camindex;
|
qDebug() << "grabFrame from camera " << camindex;
|
||||||
if (valid) {
|
if (valid) {
|
||||||
GenApi::INodeMap &nodemap = getNodemap(camindex);
|
GenApi::INodeMap &nodemap = getNodemap(camindex);
|
||||||
qDebug() << "Setting width" << layout.rois[camindex].width;
|
qDebug() << "Setting width" << layout.rois[0].width;
|
||||||
Pylon::CIntegerParameter(nodemap, "Width").SetValue(layout.rois[camindex].width);
|
Pylon::CIntegerParameter(nodemap, "Width").SetValue(layout.rois[0].width);
|
||||||
qDebug() << "Setting height" << layout.rois[0].height;
|
qDebug() << "Setting height" << layout.rois[0].height;
|
||||||
Pylon::CIntegerParameter(nodemap, "Height").SetValue(layout.rois[camindex].height);
|
Pylon::CIntegerParameter(nodemap, "Height").SetValue(layout.rois[0].height);
|
||||||
qDebug() << "Setting xoffset" << layout.rois[camindex].x;
|
qDebug() << "Setting xoffset" << layout.rois[0].x;
|
||||||
Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(layout.rois[camindex].x);
|
Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(layout.rois[0].x);
|
||||||
qDebug() << "Setting yoffset" << layout.rois[camindex].y;
|
qDebug() << "Setting yoffset" << layout.rois[0].y;
|
||||||
Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(layout.rois[camindex].y);
|
Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(layout.rois[0].y);
|
||||||
|
|
||||||
camera->StartGrabbing();
|
camera->StartGrabbing();
|
||||||
camera->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
|
camera->RetrieveResult( 5000, frame, Pylon::TimeoutHandling_ThrowException);
|
||||||
@ -191,30 +191,15 @@ bool DualcamWrapper::grabFrame(MyImage &img, int camindex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DualcamWrapper::setROI() {
|
|
||||||
std::cerr << "Setting ROI" << std::endl;
|
|
||||||
for (int camindex = 0; camindex < 2; camindex++){
|
|
||||||
std::cerr << "\t" << camindex << std::endl;
|
|
||||||
GenApi::INodeMap &nodemap = getNodemap(camindex);
|
|
||||||
qDebug() << "Setting width" << layout.rois[camindex].width;
|
|
||||||
Pylon::CIntegerParameter(nodemap, "Width").SetValue(layout.rois[camindex].width);
|
|
||||||
qDebug() << "Setting height" << layout.rois[0].height;
|
|
||||||
Pylon::CIntegerParameter(nodemap, "Height").SetValue(layout.rois[camindex].height);
|
|
||||||
qDebug() << "Setting xoffset" << layout.rois[camindex].x;
|
|
||||||
Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(layout.rois[camindex].x);
|
|
||||||
qDebug() << "Setting yoffset" << layout.rois[camindex].y;
|
|
||||||
Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(layout.rois[camindex].y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void DualcamWrapper::resetCamera(int camindex) {
|
void DualcamWrapper::resetCamera(int camindex) {
|
||||||
GenApi::INodeMap &nodemap = getNodemap( camindex );
|
GenApi::INodeMap &nodemap = getNodemap( camindex );
|
||||||
int64_t dfltWidth = 2048;
|
int64_t dfltWidth = 2048;
|
||||||
int64_t dfltHeight = 1536;
|
int64_t dfltHeight = 1536;
|
||||||
qDebug() << "resetting camera to default ROI (" << dfltWidth << ", " << dfltHeight << ")";
|
qDebug() << "resetting camera to default ROI (" << dfltWidth << ", " << dfltHeight << ")";
|
||||||
try {
|
try {
|
||||||
|
// std::cerr << "MaxWidth: " << Pylon::CIntegerParameter(nodemap, "WidthMax").GetValue() << std::endl;
|
||||||
Pylon::CIntegerParameter(nodemap, "Width").SetValue(dfltWidth, false);
|
Pylon::CIntegerParameter(nodemap, "Width").SetValue(dfltWidth, false);
|
||||||
|
// std::cerr << "MaxHeight: " << Pylon::CIntegerParameter(nodemap, "HeightMax").GetValue() << std::endl;
|
||||||
Pylon::CIntegerParameter(nodemap, "Height").SetValue(dfltHeight, false);
|
Pylon::CIntegerParameter(nodemap, "Height").SetValue(dfltHeight, false);
|
||||||
Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(0);
|
Pylon::CIntegerParameter(nodemap, "OffsetX").SetValue(0);
|
||||||
Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(0);
|
Pylon::CIntegerParameter(nodemap, "OffsetY").SetValue(0);
|
||||||
@ -244,9 +229,8 @@ bool DualcamWrapper::openCameras(std::string &message) {
|
|||||||
valid = false;
|
valid = false;
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
// resetCamera(0);
|
resetCamera(0);
|
||||||
// resetCamera(1);
|
resetCamera(1);
|
||||||
setROI();
|
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ public:
|
|||||||
DualcamWrapper(const CameraLayout &layout);
|
DualcamWrapper(const CameraLayout &layout);
|
||||||
~DualcamWrapper();
|
~DualcamWrapper();
|
||||||
|
|
||||||
|
|
||||||
ImageSettings getImageSettings(int camindex);
|
ImageSettings getImageSettings(int camindex);
|
||||||
bool isOpen();
|
bool isOpen();
|
||||||
void terminate();
|
void terminate();
|
||||||
@ -34,7 +35,6 @@ private:
|
|||||||
void resetCamera(int camindex);
|
void resetCamera(int camindex);
|
||||||
Pylon::CInstantCameraArray cameras;
|
Pylon::CInstantCameraArray cameras;
|
||||||
GenApi::INodeMap& getNodemap(int camindex);
|
GenApi::INodeMap& getNodemap(int camindex);
|
||||||
void setROI();
|
|
||||||
bool valid, withLayout;
|
bool valid, withLayout;
|
||||||
CameraLayout layout;
|
CameraLayout layout;
|
||||||
|
|
||||||
|
@ -776,8 +776,8 @@ void PylonRecorder::startSinglecamRecording() {
|
|||||||
delete writer;
|
delete writer;
|
||||||
writer = nullptr;
|
writer = nullptr;
|
||||||
}
|
}
|
||||||
writer = new Writer(buffer);
|
writer = new Writer(buffer, 0);
|
||||||
connect(writer, SIGNAL(writingDone()), this, SLOT(writerDone()));
|
connect(writer, SLOT(writingDone()), this, SLOT(writerDone()));
|
||||||
writer->setVideoSpecs(specs);
|
writer->setVideoSpecs(specs);
|
||||||
|
|
||||||
QSettings s;
|
QSettings s;
|
||||||
@ -807,7 +807,7 @@ void PylonRecorder::startDualcamRecording() {
|
|||||||
VideoSpecs specs = getVideoSpecs(settings);
|
VideoSpecs specs = getVideoSpecs(settings);
|
||||||
specs.filename = filename;
|
specs.filename = filename;
|
||||||
specs.format = VideoFormat::mp4;
|
specs.format = VideoFormat::mp4;
|
||||||
qDebug() << "got video specifications " << specs.fps;
|
qDebug() << "got video specifications";
|
||||||
if (buffer != nullptr) {
|
if (buffer != nullptr) {
|
||||||
buffer->clear();
|
buffer->clear();
|
||||||
delete buffer;
|
delete buffer;
|
||||||
@ -839,7 +839,7 @@ void PylonRecorder::startDualcamRecording() {
|
|||||||
delete writer;
|
delete writer;
|
||||||
writer = nullptr;
|
writer = nullptr;
|
||||||
}
|
}
|
||||||
writer = new Writer(buffer);
|
writer = new Writer(buffer, 0);
|
||||||
connect(writer, SIGNAL(writingDone()), this, SLOT(writerDone()));
|
connect(writer, SIGNAL(writingDone()), this, SLOT(writerDone()));
|
||||||
writer->setVideoSpecs(specs);
|
writer->setVideoSpecs(specs);
|
||||||
|
|
||||||
|
13
writer.cpp
13
writer.cpp
@ -37,7 +37,7 @@ void Writer::run() {
|
|||||||
// Releases all pylon resources.
|
// Releases all pylon resources.
|
||||||
// PylonTerminate();
|
// PylonTerminate();
|
||||||
// Return with error code 1.
|
// Return with error code 1.
|
||||||
emit writingDone();
|
emit writingDone(this->cam_number);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << "checks done!";
|
qDebug() << "checks done!";
|
||||||
@ -114,12 +114,7 @@ void Writer::run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count < chunksize) {
|
if (count < chunksize) {
|
||||||
try {
|
stamps_buffer[count] = nix::util::timeToStr(img->timestamp());
|
||||||
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();
|
ids_buffer[count] = img->index();
|
||||||
count ++;
|
count ++;
|
||||||
} else {
|
} else {
|
||||||
@ -143,11 +138,11 @@ 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();
|
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;
|
||||||
}
|
}
|
||||||
emit writingDone();
|
emit writingDone(cam_number);
|
||||||
}
|
}
|
||||||
|
7
writer.h
7
writer.h
@ -15,8 +15,8 @@ class Writer : public QThread
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Writer(ImageBuffer*buffer, QObject *parent = nullptr) :
|
explicit Writer(ImageBuffer*buffer, int number, QObject *parent = nullptr) :
|
||||||
QThread(parent), buffer(buffer) {}
|
QThread(parent), buffer(buffer), cam_number(number) {}
|
||||||
|
|
||||||
void setVideoSpecs(VideoSpecs specs);
|
void setVideoSpecs(VideoSpecs specs);
|
||||||
void setProjectMetadata(ProjectMetadata mdata);
|
void setProjectMetadata(ProjectMetadata mdata);
|
||||||
@ -25,9 +25,10 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void terminated();
|
void terminated();
|
||||||
void writingDone();
|
void writingDone(int cam);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int cam_number;
|
||||||
ImageBuffer *buffer;
|
ImageBuffer *buffer;
|
||||||
VideoSpecs videoSpecs;
|
VideoSpecs videoSpecs;
|
||||||
ProjectMetadata metadata;
|
ProjectMetadata metadata;
|
||||||
|
Loading…
Reference in New Issue
Block a user