From 155ac6b471e086eec1155e54b691973133940006 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Wed, 13 Mar 2024 08:58:45 +0100 Subject: [PATCH] add user given camera name to configuration --- CMakeLists.txt | 10 +++++----- camerapreview.cpp | 5 +++-- pylonrecorder.cpp | 40 +++++++++++++++++++++++++++++++++------- pylonrecorder.h | 9 ++++++--- pylonwrapper.cpp | 6 ++++++ pylonwrapper.h | 1 + 6 files changed, 54 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8bcff6..2ab337f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,10 +43,10 @@ include_directories (AFTER ${NIX_INCLUDE_DIR}) # ####################################### # OPENCV -message ("=> finding opencv ...") -find_package(OpenCV REQUIRED opencv_highgui opencv_core) -include_directories(AFTER ${OpenCV_INCLUDE_DIRS} ) -set(LINK_LIBS ${LINK_LIBS} ${OpenCV_LIBRARIES}) +# message ("=> finding opencv ...") +# find_package(OpenCV REQUIRED opencv_highgui opencv_core) +# include_directories(AFTER ${OpenCV_INCLUDE_DIRS} ) +# set(LINK_LIBS ${LINK_LIBS} ${OpenCV_LIBRARIES}) ####################################### # Pylon @@ -58,5 +58,5 @@ file (GLOB RECORDER_SOURCES *.cpp) file (GLOB RECORDER_INCLUDES *.hpp) add_executable ( recorder ${RECORDER_SOURCES} ${RECORDER_INCLUDES} ${RECORDER_RES_SOURCES} ) target_include_directories ( recorder PUBLIC "${PROJECT_BINARY_DIR}" ) -target_link_libraries ( recorder Qt5::PrintSupport Qt5::Core Qt5::Widgets Qt5::Gui ${NIX_LIBRARIES} pylon::pylon ${OpenCV_LIBRARIES}) +target_link_libraries ( recorder Qt5::PrintSupport Qt5::Core Qt5::Widgets Qt5::Gui ${NIX_LIBRARIES} pylon::pylon) # ${PYLON_LIBRARIES} ${OpenCV_LIBRARIES}) \ No newline at end of file diff --git a/camerapreview.cpp b/camerapreview.cpp index b0bda78..d52acb2 100644 --- a/camerapreview.cpp +++ b/camerapreview.cpp @@ -60,8 +60,7 @@ CameraPreview::CameraPreview(QWidget *parent):cameraname(""), camera(nullptr), Q void CameraPreview::setCamera(QString &device){ qDebug() << "update camera! ";// << device.toStdString(); cameraname = device; - label->setText(device); - if (camera != NULL) { + if (camera != nullptr) { qDebug() << "camera is not nullptr! "; delete camera; camera = nullptr; @@ -76,7 +75,9 @@ void CameraPreview::setCamera(QString &device){ QString msg = "

Could not open camera device!

" + QString::fromStdString(message) + "

"; msgBox.setText(msg); msgBox.exec(); + return; } + label->setText(device + " - " + camera->userName()); takeStill(); } diff --git a/pylonrecorder.cpp b/pylonrecorder.cpp index c70b46c..6924be5 100644 --- a/pylonrecorder.cpp +++ b/pylonrecorder.cpp @@ -443,6 +443,9 @@ void PylonRecorder::createActions() { grab_continuous_action->setShortcut(tr("Ctrl+Enter")); grab_stop_action = camera_menu->addAction(stop_icon, tr("&stop grabbing"), this, &PylonRecorder::stopRecording); grab_stop_action->setShortcut(tr("Ctrl+Shift+Enter")); + set_cam_identifier_action = camera_menu->addAction(tr("set identifier"), this, &PylonRecorder::setCameraIDs); + set_cam_identifier_action->setStatusTip(tr("Set human readable camera identifier or easier recognition.")); + set_cam_identifier_action->setToolTip(tr("Set human readable camera identifier or easier recognition.")); selectStorageAction = new QAction(tr("storage location"), this); selectStorageAction->setStatusTip(tr("Select a storage location for the recorded videos")); @@ -540,9 +543,32 @@ void PylonRecorder::updateActions() { grab_still_action->setEnabled(cameraOpened); grab_continuous_action->setEnabled(cameraOpened && !grabbing); grab_stop_action->setEnabled(grabbing); + set_cam_identifier_action->setEnabled(false); } +void PylonRecorder::setCameraIDs() { + if (deviceList.size() == 0) { + QMessageBox msgBox; + QString msg = "

No camera device found!


Connect camera and try again!

"; + msgBox.setText(msg); + msgBox.exec(); + qWarning() << msg.toStdString().c_str(); + return; + } + cameraIdDialog = new CameraID(deviceList, this); + connect(cameraConfigDialog, SIGNAL(accepted()), SLOT(cameraIDAccepted())); + std::cerr <<"ping\n"; + cameraIdDialog->exec(); +} + +void PylonRecorder::cameraIDAccepted() { + QString newid = cameraIdDialog->newID(); + int deviceindex = cameraIdDialog->cameraIndex(); + std::cerr << "New camera id " << newid.toStdString() << " index: " << deviceindex << std::endl; + delete(cameraIdDialog); +} + void PylonRecorder::scaleImage(double factor) { QPixmap map = imageLabel->pixmap(Qt::ReturnByValue); Q_ASSERT(!map.isNull()); @@ -582,19 +608,19 @@ void PylonRecorder::adjustScrollBar(QScrollBar *scrollBar, double factor) { void PylonRecorder::cameraConfiguration(){ - d = new CamConfigurator(deviceList, this); - connect(d, SIGNAL(accepted()), SLOT(cameraConfigurationAccepted())); - connect(d, SIGNAL(rejected()), SLOT(cameraConfigurationAborted())); + cameraConfigDialog = new CamConfigurator(deviceList, this); + connect(cameraConfigDialog, SIGNAL(accepted()), SLOT(cameraConfigurationAccepted())); + connect(cameraConfigDialog, SIGNAL(rejected()), SLOT(cameraConfigurationAborted())); // QObject::connect(&d, SIGNAL(column_visibility_changed(QString, QString,bool)), this, SLOT(visible_columns_update(QString, QString,bool))); - d->exec(); + cameraConfigDialog->exec(); } void PylonRecorder::cameraConfigurationAccepted() { - qDebug() << "Cameras setting " << ((d->result()) ? "Accepted" : "Discarded"); - this->layout = d->layout(); + qDebug() << "Cameras setting " << ((cameraConfigDialog->result()) ? "Accepted" : "Discarded"); + this->layout = cameraConfigDialog->layout(); camsconfigured = true; - delete d; + delete cameraConfigDialog; } diff --git a/pylonrecorder.h b/pylonrecorder.h index 4f81c87..e352161 100644 --- a/pylonrecorder.h +++ b/pylonrecorder.h @@ -13,9 +13,9 @@ #include "grabber.h" #include "dualcamgrabber.h" #include "writer.h" -#include "opencvwriter.h" #include "projectsettings.h" #include "camconfig.h" +#include "camids.h" #include "util.h" #include @@ -71,6 +71,8 @@ private slots: void selectStorageLocation(); void cameraConfigurationAccepted(); void cameraConfigurationAborted(); + void setCameraIDs(); + void cameraIDAccepted(); private: void createActions(); @@ -87,7 +89,6 @@ private: VideoSpecs getVideoSpecs(const ImageSettings &settings); void startSinglecamRecording(); void startDualcamRecording(); - bool saveFile(const QString &fileName); void setImage(const QImage &newImage); void scaleImage(double factor); @@ -122,8 +123,9 @@ private: QString storageLocation = ""; ProjectMetadata mdata; Pylon::DeviceInfoList_t deviceList; - CamConfigurator *d; Pylon::PylonAutoInitTerm autoInitTerm; + CamConfigurator *cameraConfigDialog; + CameraID *cameraIdDialog; #if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printer) @@ -142,6 +144,7 @@ private: QAction *grab_stop_action; QAction *connect_camera_action; QAction *disconnect_camera_action; + QAction *set_cam_identifier_action; }; #endif diff --git a/pylonwrapper.cpp b/pylonwrapper.cpp index 0d108e7..b7f92a8 100644 --- a/pylonwrapper.cpp +++ b/pylonwrapper.cpp @@ -232,3 +232,9 @@ void PylonWrapper::closeCamera() { Pylon::CInstantCamera *PylonWrapper::getCamera() { return camera; } + +QString PylonWrapper::userName() { + GenApi::INodeMap& nodemap = camera->GetNodeMap(); + QString username = Pylon::CStringParameter(nodemap, "DeviceUserID").GetValue().c_str(); + return username; +} \ No newline at end of file diff --git a/pylonwrapper.h b/pylonwrapper.h index 243b37b..f1c74fe 100644 --- a/pylonwrapper.h +++ b/pylonwrapper.h @@ -27,6 +27,7 @@ public: bool exposureTime(double exposure_time); double gain(); bool gain(double gain_db); + QString userName(); Pylon::CInstantCamera *getCamera(); void resetCamera();