[dualcomwrapper] enable software triggering

This commit is contained in:
Jan Grewe 2025-03-12 11:01:50 +01:00
parent 12c2f6292f
commit 4f2d45df6b
4 changed files with 77 additions and 43 deletions

View File

@ -13,46 +13,55 @@ void DualcamGrabber::run() {
stop_request = false; stop_request = false;
size_t counter = 0; size_t counter = 0;
if (wrapper->isOpen()) { if (!wrapper->isOpen()) {
Pylon::CInstantCameraArray &cameras = wrapper->getCameraArray(); return;
wrapper->frameRate(static_cast<uint>(framerate), -1); }
wrapper->exposureTime(exposure);
wrapper->gain(gain);
cameras.StartGrabbing(); Pylon::CInstantCameraArray &cameras = wrapper->getCameraArray();
Pylon::CGrabResultPtr frame0, frame1; wrapper->frameRate(static_cast<uint>(framerate), -1);
Pylon::CPylonImage leftImage; wrapper->exposureTime(exposure);
Pylon::CPylonImage rightImage; wrapper->gain(gain);
Pylon::CPylonImage stitchedImage;
std::string errorMessage = "";
while (cameras.IsGrabbing() && !stop_request) { cameras.StartGrabbing();
auto before = high_resolution_clock::now(); Pylon::CGrabResultPtr frame0, frame1;
try { Pylon::CPylonImage leftImage;
cameras[0].RetrieveResult( 5000, frame0, Pylon::TimeoutHandling_ThrowException ); Pylon::CPylonImage rightImage;
cameras[1].RetrieveResult( 5000, frame1, Pylon::TimeoutHandling_ThrowException ); Pylon::CPylonImage stitchedImage;
leftImage.AttachGrabResultBuffer( frame0 ); std::string errorMessage = "";
rightImage.AttachGrabResultBuffer( frame1 );
} catch(const std::exception& e) { while (cameras.IsGrabbing() && !stop_request) {
qDebug() << "Grabbing frame failed! " << e.what(); auto before = high_resolution_clock::now();
} auto after1 = high_resolution_clock::now();
auto after = high_resolution_clock::now(); try {
if (leftImage.IsValid() && rightImage.IsValid()) { cameras[0].RetrieveResult( 5000, frame0, Pylon::TimeoutHandling_ThrowException );
try { after1 = high_resolution_clock::now();
StitchImage::StitchToRight(leftImage, rightImage, &stitchedImage, errorMessage); cameras[1].RetrieveResult( 5000, frame1, Pylon::TimeoutHandling_ThrowException );
MyImage *img = new MyImage(stitchedImage.GetWidth(), stitchedImage.GetHeight()); leftImage.AttachGrabResultBuffer( frame0 );
img->setFrame(stitchedImage); rightImage.AttachGrabResultBuffer( frame1 );
buffer->push(img); } catch(const std::exception& e) {
} catch(const std::exception& e) { qDebug() << "Grabbing frame failed! " << e.what();
std::cerr << e.what() << '\n'; }
} auto after = high_resolution_clock::now();
} if (leftImage.IsValid() && rightImage.IsValid()) {
auto stitch = high_resolution_clock::now(); try {
auto grab_duration = duration_cast<microseconds>(after - before); StitchImage::StitchToRight(leftImage, rightImage, &stitchedImage, errorMessage);
auto stitch_duration = duration_cast<microseconds>(stitch - after); MyImage *img = new MyImage(stitchedImage.GetWidth(), stitchedImage.GetHeight());
std::cerr << "framecount: " << counter << " grab_duration (us): " << grab_duration.count() << "\t" << " stitching (us): " << stitch_duration.count() << std::endl; img->setFrame(stitchedImage);
counter += 1; buffer->push(img);
} catch(const std::exception& e) {
std::cerr << e.what() << '\n';
}
} }
cameras.StopGrabbing(); auto stitch = high_resolution_clock::now();
} auto grab_duration = duration_cast<microseconds>(after - before);
auto grab1_duration = duration_cast<microseconds>(after1 - before);
auto stitch_duration = duration_cast<microseconds>(stitch - after);
std::cerr << "framecount: " << counter << " grab_duration (us): " << grab_duration.count() << "\t" << " stitching (us): " << stitch_duration.count() << " grab1_duration (us): " << grab1_duration.count() << std::endl;
counter += 1;
auto done = high_resolution_clock::now();
auto total_duration = duration_cast<microseconds>(done - before);
double rate = (1./((double)total_duration.count()/1000000));
std::cerr << "total_duration (us): " << total_duration.count() << " rate: " << rate << std::endl;
}
cameras.StopGrabbing();
} }

View File

@ -284,7 +284,7 @@ void DualcamWrapper::closeCameras() {
} }
Pylon::CInstantCameraArray &DualcamWrapper::getCameraArray() { Pylon::CInstantCameraArray &DualcamWrapper::getCameraArray() {
return cameras; return cameras;
} }
// Pylon::CInstantCamera DualcamWrapper::getCamera(int camindex) { // Pylon::CInstantCamera DualcamWrapper::getCamera(int camindex) {
@ -293,6 +293,28 @@ Pylon::CInstantCameraArray &DualcamWrapper::getCameraArray() {
GenApi::INodeMap& DualcamWrapper::getNodemap(int camindex){ GenApi::INodeMap& DualcamWrapper::getNodemap(int camindex){
GenApi::INodeMap &nodemap = cameras[camindex].GetNodeMap(); GenApi::INodeMap &nodemap = cameras[camindex].GetNodeMap();
return nodemap; return nodemap;
}
void DualcamWrapper::enableSoftwareTrigger(int camindex){
GenApi::INodeMap &nodemap = getNodemap( camindex );
// Enable triggered image acquisition for the Frame Start trigger
Pylon::CEnumParameter(nodemap, "TriggerMode").SetValue("On");
// Set the trigger source to Line 1
Pylon::CEnumParameter(nodemap, "TriggerSource").SetValue("Line1");
// Set the trigger activation mode to level high
Pylon::CEnumParameter(nodemap, "TriggerActivation").SetValue("LevelHigh");
}
void DualcamWrapper::disableSoftwareTrigger(int camindex){
GenApi::INodeMap& nodemap = getNodemap(camindex);
// Disable triggered image acquisition for the Frame Start trigger
Pylon::CEnumParameter(nodemap, "TriggerMode").SetValue("Off");
}
bool DualcamWrapper::softwareTriggerEnabeled(int camindex){
GenApi::INodeMap& nodemap = getNodemap(camindex);
// Get the current state.
return Pylon::CEnumParameter(nodemap, "TriggerMode").GetValue() == "On";
} }

View File

@ -30,6 +30,9 @@ public:
bool exposureTime(double exposure_time, int camindex=-1); bool exposureTime(double exposure_time, int camindex=-1);
double gain(int camindex); double gain(int camindex);
bool gain(double gain_db, int camindex=-1); bool gain(double gain_db, int camindex=-1);
void enableSoftwareTrigger(int camindex);
void disableSoftwareTrigger(int camindex);
bool softwareTriggerEnabeled(int camindex);
Pylon::CInstantCameraArray &getCameraArray(); Pylon::CInstantCameraArray &getCameraArray();
private: private:

View File

@ -684,7 +684,7 @@ void PylonRecorder::connectCamera() {
dualcam = new DualcamWrapper(layout); dualcam = new DualcamWrapper(layout);
bool success = dualcam->openCameras(message); bool success = dualcam->openCameras(message);
if (success) { if (success) {
qDebug()::cerr << "dual camera connected\n"; qDebug() << "Dual cameras connected";
cameraConnectedLabel->setText("connected"); cameraConnectedLabel->setText("connected");
cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: green;}"); cameraConnectedLabel->setStyleSheet("QLabel { font-size: 10px;font-family: Arial;color: green;}");
cameraOpened = true; cameraOpened = true;