Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • sugu/vimba
1 result
Select Git revision
Show changes
Commits on Source (5)
...@@ -7,11 +7,15 @@ SOURCES += \ ...@@ -7,11 +7,15 @@ SOURCES += \
../src/cmd/main.cpp \ ../src/cmd/main.cpp \
../src/cmd/console.cpp \ ../src/cmd/console.cpp \
../src/cmd/core.cpp \ ../src/cmd/core.cpp \
../src/cmd/frameObserver.cpp \
../src/cmd/frameProcessor.cpp \
../src/utils.cpp ../src/utils.cpp
HEADERS += \ HEADERS += \
../src/cmd/console.h \ ../src/cmd/console.h \
../src/cmd/core.h \ ../src/cmd/core.h \
../src/cmd/frameObserver.h \
../src/cmd/frameProcessor.h \
../src/utils.h ../src/utils.h
DEFINES *= QT_USE_QSTRINGBUILDER #converts + to % when building strings DEFINES *= QT_USE_QSTRINGBUILDER #converts + to % when building strings
...@@ -27,12 +31,13 @@ LIBS += -L$${VIMBA_LIB_DIR} -lVmbC -lVmbCPP -Wl,-rpath,\'\$$ORIGIN\' ...@@ -27,12 +31,13 @@ LIBS += -L$${VIMBA_LIB_DIR} -lVmbC -lVmbCPP -Wl,-rpath,\'\$$ORIGIN\'
#-Wl,-rpath,. #-Wl,-rpath,.
QMAKE_POST_LINK += cp $${VIMBA_LIB_DIR}/lib*.so ../bin # copy vmb-libs to bin QMAKE_POST_LINK += cp $${VIMBA_LIB_DIR}/lib*.so ../bin # copy vmb-libs to bin
QMAKE_CXXFLAGS += -Wno-deprecated-enum-enum-conversion # ignore opencv warnings.
#PRE_LINK: cp vimba libs once #PRE_LINK: cp vimba libs once
# cp ../b/vimbax/api/lib/GenICam/*.so $${VIMBA_LIB_DIR} # cp ../b/vimbax/api/lib/GenICam/*.so $${VIMBA_LIB_DIR}
# cp ../b/vimbax/api/lib/libVmb{C,CPP,ImageTransform}.so $${VIMBA_LIB_DIR} # cp ../b/vimbax/api/lib/libVmb{C,CPP,ImageTransform}.so $${VIMBA_LIB_DIR}
TARGET = recorder-cmd TARGET = cmd
DESTDIR = ../bin DESTDIR = ../bin
QMAKE_CLEAN += .cache/clangd/index/* .qmake.stash QMAKE_CLEAN += .cache/clangd/index/* .qmake.stash
......
...@@ -41,52 +41,52 @@ ...@@ -41,52 +41,52 @@
"variants": "variants":
[ [
{ {
"name": "gui: build & run", "name": "cmd: build & run",
"shell_cmd": "qmake6 recorder-gui.pro && make -j`nproc` && cd ../bin && recorder-gui", "shell_cmd": "qmake6 recorder-cmd.pro && make -j`nproc` && cd ../bin && recorder-cmd \\$run_args",
}, },
{ {
"name": "gui: run", "name": "cmd: run",
"shell_cmd": "cd ../bin && recorder-gui", "shell_cmd": "cd ../bin && recorder-cmd \\$run_args",
}, },
{ {
"name": "gui: build", "name": "cmd: build",
"shell_cmd": "qmake6 recorder-gui.pro && make -j`nproc` ", "shell_cmd": "qmake6 recorder-cmd.pro && make -j`nproc` ",
}, },
{ {
"name": "gui: rebuild", "name": "cmd: rebuild",
"shell_cmd": "make -j`nproc` clean && qmake6 recorder-gui.pro && make -j`nproc` -B", "shell_cmd": "make -j`nproc` clean && qmake6 recorder-cmd.pro && make -j`nproc` -B",
}, },
{ {
"name": "gui: rebuild && run", "name": "cmd: rebuild && run",
"shell_cmd": "make -j`nproc` clean && qmake6 recorder-gui.pro && make -j`nproc` -B && LD_LIBRARY_PATH=../bin && recorder-gui", "shell_cmd": "make -j`nproc` clean && qmake6 recorder-cmd.pro && make -j`nproc` -B && LD_LIBRARY_PATH=../bin && recorder-cmd \\$run_args",
}, },
{ {
"name": "gui: designer", "name": "gui: build & run",
"shell_cmd": "designer ../src/gui/mainwindow.ui", "shell_cmd": "qmake6 recorder-gui.pro && make -j`nproc` && cd ../bin && recorder-gui",
}, },
{ {
"name": "-------------------------------", "name": "-------------------------------",
"shell_cmd": "", "shell_cmd": "",
}, },
{ {
"name": "cmd: build & run", "name": "gui: run",
"shell_cmd": "qmake6 recorder-cmd.pro && make -j`nproc` && cd ../bin && recorder-cmd \\$run_args", "shell_cmd": "cd ../bin && recorder-gui",
}, },
{ {
"name": "cmd: run", "name": "gui: build",
"shell_cmd": "cd ../bin && recorder-cmd \\$run_args", "shell_cmd": "qmake6 recorder-gui.pro && make -j`nproc` ",
}, },
{ {
"name": "cmd: build", "name": "gui: rebuild",
"shell_cmd": "qmake6 recorder-cmd.pro && make -j`nproc` ", "shell_cmd": "make -j`nproc` clean && qmake6 recorder-gui.pro && make -j`nproc` -B",
}, },
{ {
"name": "cmd: rebuild", "name": "gui: rebuild && run",
"shell_cmd": "make -j`nproc` clean && qmake6 recorder-cmd.pro && make -j`nproc` -B", "shell_cmd": "make -j`nproc` clean && qmake6 recorder-gui.pro && make -j`nproc` -B && LD_LIBRARY_PATH=../bin && recorder-gui",
}, },
{ {
"name": "cmd: rebuild && run", "name": "gui: designer",
"shell_cmd": "make -j`nproc` clean && qmake6 recorder-cmd.pro && make -j`nproc` -B && LD_LIBRARY_PATH=../bin && recorder-cmd \\$run_args", "shell_cmd": "designer ../src/gui/mainwindow.ui",
}, },
{ {
"name": "-------------------------------", "name": "-------------------------------",
...@@ -96,6 +96,8 @@ ...@@ -96,6 +96,8 @@
"name": "bear -- create new compile_commands.json", "name": "bear -- create new compile_commands.json",
"shell_cmd": "bear -- make -j`nproc` && mv compile_commands.json ..", "shell_cmd": "bear -- make -j`nproc` && mv compile_commands.json ..",
}, },
// { // {
// "name": "qmake6", // "name": "qmake6",
// "shell_cmd": "qmake6", // "shell_cmd": "qmake6",
......
...@@ -23,30 +23,47 @@ void Console::listenKeys() ...@@ -23,30 +23,47 @@ void Console::listenKeys()
} }
} }
void Console::error(const int& errCode )
{
if( errCode )
{
QString errStr=errorCodeToMessage( errCode );
qDebug().noquote() << errStr;
}
}
void Console::error(const QString& str, const int& errCode=0 )
{
if( str != "" )
qDebug().noquote() << "⚠️ " << str;
error(errCode);
}
void Console::print(const QString& str ) void Console::print(const QString& str )
{ {
qDebug() << str; qDebug().noquote() << str;
} }
void Console::printList(QStringList& list ) void Console::printList(const QStringList& list )
{ {
for ( auto& str : list ) for ( auto str : list )
{ {
str.replace(DELIM," "); str.replace(DELIM," ");
qDebug() << str << " "; qDebug().noquote() << str << " ";
} }
} }
Controller::Controller() // ###############################
// Controller
Controller::Controller() : console(new Console())
{ {
Console* console = new Console;
console->moveToThread(&thread); console->moveToThread(&thread);
connect(&thread, &QThread::finished, console, &QObject::deleteLater); connect(&thread, &QThread::finished, console, &QObject::deleteLater);
connect(this, &Controller::operate, console, &Console::listenKeys); connect(this, &Controller::operate, console, &Console::listenKeys);
connect(console, &Console::keyPressed, this, &Controller::keyPress); connect(console, &Console::keyPressed, this, &Controller::keyPress);
connect(this, &Controller::print, console, &Console::print, Qt::DirectConnection); //just delegate to console
connect(this, &Controller::printList, console, &Console::printList, Qt::DirectConnection); //just delegate to console
thread.start(); thread.start();
} }
...@@ -54,33 +71,43 @@ Controller::~Controller() ...@@ -54,33 +71,43 @@ Controller::~Controller()
{ {
thread.quit(); thread.quit();
thread.wait(); //wait for thread to finish thread.wait(); //wait for thread to finish
// qDebug() << __FUNCTION__ << "():" << __LINE__ << ": "; // qDebug().noquote() << __FUNCTION__ << "():" << __LINE__ << ": ";
} }
void Controller::keyPress(const QChar& key) void Controller::keyPress(const QChar& key)
{ {
qDebug() << __FUNCTION__ << ": " << key; qDebug().noquote() << __FUNCTION__ << ": " << key;
if ( key.isDigit() ) if ( key.isDigit() )
{ {
emit selectCam(key.digitValue()); emit selectCam(key.digitValue()-1);
} }
else else
{ {
switch (key.unicode()) switch (key.unicode())
{ {
// XXX add new func
case 'h': case 'h':
emit printHelp(); emit printHelp();
break; break;
case 'o': case 'o':
emit openCam(); emit openCam();
break; break;
case 'l': case 'l':
emit listCams(); emit listCams();
break; break;
case 'r':
emit record();
break;
case 'v': case 'v':
emit printVersion(); emit printVersion();
break; break;
case 'q': case 'q':
qApp->quit(); qApp->quit();
break; break;
......
...@@ -12,8 +12,10 @@ class Console : public QObject ...@@ -12,8 +12,10 @@ class Console : public QObject
public slots: public slots:
void listenKeys(); void listenKeys();
void error(const QString&,const int&);
void error(const int&);
void print(const QString&); void print(const QString&);
void printList(QStringList&); void printList(const QStringList&);
// ... // ...
signals: signals:
...@@ -29,24 +31,30 @@ class Controller : public QObject ...@@ -29,24 +31,30 @@ class Controller : public QObject
public: public:
Controller(); Controller();
~Controller(); ~Controller();
Console* console;
public slots: public slots:
void keyPress(const QChar &); void keyPress(const QChar &);
signals: signals:
// to UI
void operate(); void operate();
void error(const QString&,const int& errCode=0);
void error(const int& errCode=0);
void print(const QString&); void print(const QString&);
void printList(QStringList&); void printList(const QStringList&);
void listCams();
// to core
void printHelp();
void printVersion(); void printVersion();
void listCams();
void openCam(); void openCam();
void printHelp();
void selectCam(int); void selectCam(int);
void record();
// void openCam(); // XXX add new func
// void calibrateCam(); // void calibrateCam();
// void startRecording();
// void stopRecording(); // void stopRecording();
// void loadSettings(); // void loadSettings();
// void storeSettings(); // void storeSettings();
......
#include "core.h" #include "core.h"
#include "../utils.h" #include "VmbC/VmbCommonTypes.h"
#include "VmbCPP/SharedPointerDefines.h"
#include "frameobserver.h"
#include "../utils.h"
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <VmbCPP/VmbCPP.h> #include <VmbCPP/VmbCPP.h>
#include <VmbCPP/Camera.h>
#include <QDebug> #include <QDebug>
#include <QThread>
using namespace VmbCPP; using namespace VmbCPP;
...@@ -15,35 +20,34 @@ Core::Core() : ...@@ -15,35 +20,34 @@ Core::Core() :
sys( VmbSystem::GetInstance() ), // Create and get Vimba singleton sys( VmbSystem::GetInstance() ), // Create and get Vimba singleton
cameras( CameraPtrVector() ), // Holds camera handles cameras( CameraPtrVector() ), // Holds camera handles
camIdx(-1), camIdx(-1),
curCam(NULL) curCam(nullptr)
{ {
if ( VmbErrorSuccess != sys.Startup() ) if ( f(sys.Startup()) )
{ {
qDebug() << "Couldn't initialize API"; qDebug() << "Couldn't initialize API";
exit(1); //add err code exit(VmbErrorApiNotStarted);
} }
qDebug() << "init API :)"; //emitting signals in ctor doesnt Work, cuz their not connected yet
apiStarted = true; apiStarted = true;
qDebug() << "init API :)";
initCams(); initCams();
} }
void Core::initCams() void Core::initCams()
{ {
if ( VmbErrorSuccess == sys.GetCameras( cameras ) ) if ( f(sys.GetCameras( cameras )))
{ {
qDebug() << "found " << cameras.size() << " cameras"; qDebug() << "Couldn't get cameras";
}
else
{
qDebug().noquote() << QString("found %1 cameras").arg(cameras.size());
if (cameras.size()) if (cameras.size())
{ {
camIdx = 0; //dflt to 1rst camIdx = 0; //dflt to 1rst
curCam = cameras.at(camIdx); curCam = cameras.at(camIdx);
} }
}
else
{
qDebug() << "Couldn't get cameras";
} }
} }
...@@ -57,20 +61,11 @@ Core::~Core() ...@@ -57,20 +61,11 @@ Core::~Core()
sys.Shutdown(); //unload TL's sys.Shutdown(); //unload TL's
} }
CameraPtr Core::cam() CameraPtr Core::cam()
{ {
return cameras.at(camIdx); return cameras.at(camIdx);
} }
void Core::setCam(ulong idx)
{
if( idx >= cameras.size() )
idx = cameras.size() - 1;
camIdx = idx;
}
void Core::listCams() void Core::listCams()
{ {
...@@ -85,49 +80,184 @@ void Core::listCams() ...@@ -85,49 +80,184 @@ void Core::listCams()
std::string str; std::string str;
QString curCamInfo; QString curCamInfo;
curCamInfo += QString::number(idx+1) + ". ";
if (idx == camIdx ) if (idx == camIdx )
curCamInfo += "[*]" + DELIM; curCamInfo += "[*]" + DELIM;
else else
curCamInfo += "[ ]" + DELIM; curCamInfo += "[ ]" + DELIM;
VmbErrorType err = camera->GetID( str ); if( f((camera->GetID( str )))) continue;
if( VmbErrorSuccess != err )
str = errorCodeToMessage(err).toStdString();
curCamInfo += QString::fromStdString(str) + DELIM; curCamInfo += QString::fromStdString(str) + DELIM;
err = camera->GetName( str ); if( f((camera->GetName( str )))) continue;
if( VmbErrorSuccess != err )
str = errorCodeToMessage(err).toStdString();
curCamInfo += QString::fromStdString(str) + DELIM; curCamInfo += QString::fromStdString(str) + DELIM;
err = camera->GetModel( str ); if( f((camera->GetModel( str )))) continue;
if( VmbErrorSuccess != err )
str = errorCodeToMessage(err).toStdString();
curCamInfo += QString::fromStdString(str) + DELIM; curCamInfo += QString::fromStdString(str) + DELIM;
err = camera->GetSerialNumber( str ); if( f((camera->GetSerialNumber( str )))) continue;
if( VmbErrorSuccess != err )
str = errorCodeToMessage(err).toStdString();
curCamInfo += QString::fromStdString(str) + DELIM; curCamInfo += QString::fromStdString(str) + DELIM;
err = camera->GetInterfaceID( str ); if( f((camera->GetInterfaceID( str )))) continue;
if( VmbErrorSuccess != err )
str = errorCodeToMessage(err).toStdString();
curCamInfo += QString::fromStdString(str) + DELIM; curCamInfo += QString::fromStdString(str) + DELIM;
curCamInfo += "closed"; //initially cams are closed, right? XXX how to find out?
curCamInfo += "closed";
// need to update open / closed states.
//initially cams are closed, right? XXX how to find out?
//XXX track states
//VmbSystem::RegisterCameraListObserver
allCamInfo << curCamInfo; allCamInfo << curCamInfo;
idx++; idx++;
} }
emit print(QString("found " + QString::number(cameras.size()) + " cameras"));
// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << allCamInfo; emit printList(allCamInfo);
emit camsListed(allCamInfo);
} }
void Core::printVersion() void Core::printVersion()
{ {
auto version = getVersionString(); auto version = getVersions();
emit versionPrinted(version); emit printList(version);
}
void Core::printHelp()
{
//sa Controller::keyPress
QStringList str;
str << "HELP!"
<< "-------------------------------"
<< "h: print this help"
<< "1-9: select camera"
<< "o: open selected camera"
// XXX add new func
<< "r: start recording"
<< "l: list available cameras"
<< "v: print versions"
<< "q: quit"
<< "-------------------------------";
emit printList(str);
}
bool Core::f(const VmbErrorType& ret, const QString& msg)
{
//vimba function wrapper to test return type and potentially emit error message or successmsg
// returns true on error
if( VmbErrorSuccess == ret )
{
if (! msg.isEmpty())
emit print(msg);
return false;
}
else
{
if (! msg.isEmpty())
emit print("Fail! " + msg);
emit error(ret);
return true;
}
} }
bool Core::openCam()
{
if(!curCam)
{
emit error(errCamIdx);
return false;
}
return f(curCam->Open( VmbAccessModeFull ),"open cam #"+QString::number(camIdx+1));
}
void Core::selectCam(const int& camIdx)
{
try
{
curCam = cameras.at(camIdx);
}
catch (const std::out_of_range& oor)
{
emit error(errCamIdx);
return;
}
emit print("camSelected("+QString::number(camIdx)+")");
}
void Core::record()
{
//TODO use exceptions to not clutter error handling code here and catch em in main
// TODO
// if( !curCam->isOpen() )
// return; >> listener
VmbInt64_t nPLS; // Payload size value
FeaturePtr pFeature ; // Generic feature pointer
auto nFrames = 5;
FramePtrVector frames(nFrames); // Frame array
// Get the image size for the required buffer
if ( f(curCam->GetFeatureByName ("PayloadSize", pFeature ),"get PayloadSize") )
return; // emit error("Couldn't get payload size 1");
// if( pFeature == nullptr )
// return; // emit error("Couldn't get payload size 2");
if( f(pFeature->GetValue (nPLS)))
return;
qDebug() << "nPLS: " << nPLS;
// Allocate memory for frame buffer
// Register frame observer / callback for each frame
// Announce frame to the API
for( auto& frame : frames )
{
frame.reset(new Frame(nPLS));
f(frame->RegisterObserver( IFrameObserverPtr( new FrameObserver(curCam) )),"register frame observer");
f(curCam->AnnounceFrame(frame), "announce frame");
}
// Start the capture engine (API)
f(curCam->StartCapture(), "start capture");
for( auto frame : frames )
f(curCam->QueueFrame(frame),"QueueFrame"); // Put frame into the frame queue
// if( !frame ) error("frame is null");
// Start the acquisition engine ( curCam)
f(curCam->GetFeatureByName ("AcquisitionStart", pFeature ),"get AcquisitionStart");
// curCam->StartContinuousImageAcquisition(int bufferCount, const IFrameObserverPtr &pObserver)
f(pFeature->RunCommand(),"run AcquisitionStart");
// pFeature ->IsCommandDone(bool &isDone)
// pFeature ->
// Program runtime
QThread::sleep(2);
// Stop the acquisition engine ( curCam)
f(curCam->GetFeatureByName ("AcquisitionStop", pFeature ),"get AcquisitionStop");
f(pFeature->RunCommand(),"run AcquisitionStop");
// Stop the capture engine (API)
// Flush the frame queue
// Revoke all frames from the API
f(curCam->EndCapture(),"end capture");
f(curCam->FlushQueue(),"flush queue");
f(curCam->RevokeAllFrames(),"revoke all frames");
for( FramePtr frame : frames )
{
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << " frame:" << frame;
// Unregister the frame observer / callback
f(frame->UnregisterObserver(),"unregister observer");
}
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
}
#pragma once #pragma once
#include "VmbCPP/SharedPointerDefines.h"
#include "qglobal.h" #include "qglobal.h"
#include <QObject> #include <QObject>
#include <VmbCPP/SharedPointerDefines.h>
#include <VmbCPP/Interface.h> #include <VmbCPP/Interface.h>
namespace VmbCPP { namespace VmbCPP {
...@@ -19,19 +19,26 @@ class Core : public QObject ...@@ -19,19 +19,26 @@ class Core : public QObject
~Core(); ~Core();
public slots: public slots:
void listCams();
void printVersion(); void printVersion();
void printHelp();
void listCams();
bool openCam();
void selectCam(const int &);
CameraPtr cam(); // make getter seetter -> rm curCam and camIdx //or make Camera class wrapper
void record();
signals: signals:
void camsListed(QStringList &); void print(const QString &);
void versionPrinted(const QString &); void printList(QStringList);
// ... more signals here void error(const int&);
void error(const QString&,const int& errCode=0);
private: private:
bool f(const VmbErrorType&, const QString& = "");
void initCams(); void initCams();
static void getCamInfo( const CameraPtr & ); void getCamInfo( const CameraPtr & );
CameraPtr cam();
void setCam(ulong idx);
bool apiStarted; bool apiStarted;
VmbCPP::VmbSystem& sys; VmbCPP::VmbSystem& sys;
......
#include "frameobserver.h"
#include "frameprocessor.h"
#include "qnamespace.h"
#include <VmbCPP/SharedPointerDefines.h>
#include <VmbCPP/Camera.h>
#include <QDebug>
#include <QThread>
#include <QObject>
using namespace VmbCPP;
FrameObserver::FrameObserver( CameraPtr pCamera ) : IFrameObserver( pCamera )
{
// static int count=0;
// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << " #:" << count++
}
// Frame callback notifies about incoming frames
// process data afap
// some functions are prohibited within this callback!
// Do not apply image processing within this callback ( performance )
// -> create frame processor to handle frame processing asynchronously
// When the frame has been processed , requeue it
void FrameObserver::FrameReceived ( const FramePtr pframe )
{
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
FrameProcessor *processor = new FrameProcessor(pframe, this);
QThread *thread = new QThread;
processor->moveToThread(thread);
connect(thread, &QThread::started, processor, &FrameProcessor::processFrame);
connect(processor, &FrameProcessor::frameProcessed, processor, &FrameProcessor::deleteLater);
connect(processor, &FrameProcessor::frameProcessed, thread, &QThread::quit);
connect(processor, &FrameProcessor::frameProcessed, this, &FrameObserver::queueFrame); // Connect to a slot in FrameObserver
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
thread->start();
m_pCamera->QueueFrame( pframe );
}
void FrameObserver::queueFrame(FramePtr pFrame)
{
m_pCamera->QueueFrame(pFrame); // Queue the frame back to the camera
}
#pragma once
#include <QObject>
#include <VmbCPP/IFrameObserver.h>
// using VmbCPP::CameraPtr;
// using VmbCPP::FramePtr;
// using VmbCPP::IFrameObserver;
using namespace VmbCPP;
class FrameObserver : public QObject, public IFrameObserver
{
Q_OBJECT
public:
void FrameReceived( const FramePtr pFrame );
FrameObserver( CameraPtr pCamera );
private slots:
void queueFrame(FramePtr pFrame);
};
#include "frameprocessor.h"
#include "opencv2/imgcodecs.hpp"
#include <opencv2/opencv.hpp>
#include <VmbC/VmbCommonTypes.h>
#include <VmbCPP/Frame.h>
#include <QDebug>
#include <QThread>
#include <QObject>
#include <QImage>
FrameProcessor::FrameProcessor(FramePtr pframe, QObject *parent) : QObject(parent), m_pframe(pframe)
{}
//2d check image format!
//2d add camera name to filename
/// Process the received frame asynchronously
void FrameProcessor::processFrame()
{
// process frames receiveStatus
VmbFrameStatusType status;
m_pframe->GetReceiveStatus(status);
if (status != VmbFrameStatusComplete)
{
qDebug() << "Frame not complete, skip processing.";
return;
}
VmbUint32_t width = 0;
VmbUint32_t height = 0;
unsigned char* pdata;
VmbPixelFormatType pixelFormat;
VmbUint64_t timestamp;
m_pframe->GetWidth(width);
m_pframe->GetHeight(height);
m_pframe->GetBuffer(pdata);
m_pframe->GetPixelFormat(pixelFormat);
m_pframe->GetTimestamp(timestamp);
cv::Mat frameMat(height, width, CV_8UC3, pdata);
if (pixelFormat == VmbPixelFormatRgb8)
{
// If the frame pixel format is RGB8, directly copy the data
// memcpy(frameMat.data, pData, width * height * 3);
qDebug() << "Pixel format is RGB8";
}
else
{
// If the pixel format is not already in BGR format, you may need to convert it
// cv::Mat tempMat(height, width, CV_8UC1, pdata); //UC1??
// cv::cvtColor(tempMat, frameMat, cv::COLOR_BayerGB2BGR); // Adjust the conversion based on the actual Bayer pattern
qDebug() << "Pixel format is not RGB8, converting to BGR";
}
std::vector<int> params = {cv::IMWRITE_JPEG_QUALITY, 99, cv::IMWRITE_JPEG_OPTIMIZE, 1, cv::IMWRITE_JPEG_RST_INTERVAL,4};
QString filename = QString::number(timestamp) + "frame.jpg";
cv::imwrite(filename.toStdString(), frameMat, params);
qDebug() << "Frame saved as JPEG: " << filename;
emit frameProcessed(m_pframe);
}
#include <QObject>
#include <VmbCPP/SharedPointerDefines.h>
using VmbCPP::FramePtr;
class FrameProcessor : public QObject
{
Q_OBJECT
public:
explicit FrameProcessor(FramePtr, QObject *parent = nullptr);
public slots:
void processFrame();
signals:
void frameProcessed(FramePtr);
private:
FramePtr m_pframe;
};
#include "../utils.h" #include "../utils.h"
#include "console.h" #include "console.h"
#include "core.h" #include "core.h"
#include "qnamespace.h"
#include <iostream>
#include <QCoreApplication> #include <QCoreApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QDir>
#include <QTimer> #include <QTimer>
using namespace std; //string/cin/cerr/cout/endl int main(int argc, char *argv[])
bool maybeCreateDir(QDir out_dir)
{
if( !out_dir.exists() )
{
qDebug() << "out_dir (" << out_dir.absolutePath() << ") doesn't exist. Should I Create it? ['y'-yes, '?'-no]\n";
char c='y';
cin >> c;
if( c == 'y' )
{
cout << "u pressed yes" << endl;
if( out_dir.mkpath(out_dir.absolutePath())) {
cout << "created out_dir" << endl;
}
else
{
cerr << "failed to create out_dir '" << out_dir.absolutePath().toStdString() << "'" << endl;
return false;
}
}
else
{
cout << "u pressed no" << endl;
return false;
}
}
qDebug() << "out_dir: " << out_dir.dirName() << "\n";
return true;
}
int main(int argc, char *argv[])
{ {
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
QCoreApplication::setApplicationVersion(getVersionString()); QCoreApplication::setApplicationVersion(getVersion());
QCoreApplication::setApplicationName("recorder"); QCoreApplication::setApplicationName("recorder");
Controller controller; Controller controller;
Core core; Core core;
//ui (controller) -> vmb (core) //ui (controller) -> vmb (core)
QObject::connect(&controller, &Controller::listCams, &core, &Core::listCams); QObject::connect(&controller, &Controller::printHelp, &core, &Core::printHelp);
QObject::connect(&controller, &Controller::printVersion, &core, &Core::printVersion); QObject::connect(&controller, &Controller::printVersion, &core, &Core::printVersion);
//vmb (core) -> ui (controller) QObject::connect(&controller, &Controller::listCams, &core, &Core::listCams);
QObject::connect(&core, &Core::camsListed, &controller, &Controller::printList); QObject::connect(&controller, &Controller::openCam, &core, &Core::openCam);
QObject::connect(&core, &Core::versionPrinted, &controller, &Controller::print); QObject::connect(&controller, &Controller::selectCam, &core, &Core::selectCam);
QObject::connect(&controller, &Controller::record, &core, &Core::record);
// XXX add new func
//vmb (core) -> ui (controller.console)
QObject::connect(&core, SIGNAL(error(const QString&, const int&)), controller.console, SLOT(error(const QString&, const int&)),Qt::DirectConnection);
QObject::connect(&core, SIGNAL(error(const int&)), controller.console, SLOT(error(const int&)),Qt::DirectConnection);
QObject::connect(&core, SIGNAL(print(const QString&)), controller.console, SLOT(print(const QString&)),Qt::DirectConnection);
QObject::connect(&core, SIGNAL(printList(const QStringList&)), controller.console, SLOT(printList(const QStringList&)),Qt::DirectConnection);
// sa Controller() for delegating to Console
QTimer::singleShot(0, &controller, SIGNAL(operate())); QTimer::singleShot(0, &controller, SIGNAL(operate()));
QTimer::singleShot(10, &core, SLOT(printVersion())); // for testing QTimer::singleShot(10, &core, SLOT(printVersion())); // for testing
QTimer::singleShot(15, &core, SLOT(listCams())); // for testing QTimer::singleShot(30, &core, SLOT(listCams())); // for testing
QTimer::singleShot(100, &core, SLOT(openCam())); // for testing
return a.exec(); return a.exec();
} }
...@@ -98,3 +73,5 @@ bool maybeCreateDir(QDir out_dir) ...@@ -98,3 +73,5 @@ bool maybeCreateDir(QDir out_dir)
// { // {
// maybeCreateDir(parser.value("o")); // maybeCreateDir(parser.value("o"));
// } // }
...@@ -20,11 +20,11 @@ void FrameObserver::FrameReceived ( const FramePtr pFrame ) ...@@ -20,11 +20,11 @@ void FrameObserver::FrameReceived ( const FramePtr pFrame )
void Vimba::RunExample (void) void Vimba::RunExample (void)
{ {
VmbInt64_t nPLS; // Payload size value
FeaturePtr pFeature ; // Generic feature pointer
VmbSystem &sys = VmbSystem :: GetInstance (); // Create and get Vimba singleton VmbSystem &sys = VmbSystem :: GetInstance (); // Create and get Vimba singleton
CameraPtrVector cameras ; // Holds camera handles CameraPtrVector cameras ; // Holds camera handles
CameraPtr camera ; CameraPtr camera ;
VmbInt64_t nPLS; // Payload size value
FeaturePtr pFeature ; // Generic feature pointer
FramePtrVector frames (15); // Frame array FramePtrVector frames (15); // Frame array
// Start the API , get and open cameras // Start the API , get and open cameras
......
#include "utils.h"
#include "opencv2/core/version.hpp" #include "opencv2/core/version.hpp"
#include <random> #include <random>
...@@ -6,66 +7,104 @@ ...@@ -6,66 +7,104 @@
#include "VmbCPP/VmbCPP.h" #include "VmbCPP/VmbCPP.h"
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <QDir>
#include <iostream>
const int APP_VERSION_MAJOR = 0; const int APP_VERSION_MAJOR = 0;
const int APP_VERSION_MINOR = 0; const int APP_VERSION_MINOR = 0;
const int APP_VERSION_PATCH = 5; const int APP_VERSION_PATCH = 6;
using namespace VmbCPP; using namespace VmbCPP;
const QString getVersionString() const QString getVersion()
{ {
VmbVersionInfo_t version; return QString("# Recorder: %1.%2.%3").arg(APP_VERSION_MAJOR).arg(APP_VERSION_MINOR).arg(APP_VERSION_PATCH);
VmbSystem::GetInstance().QueryVersion(version); }
const QStringList getVersions()
{
VmbVersionInfo_t version;
VmbSystem::GetInstance().QueryVersion(version);
QString s = "\n### Versions\n"; QStringList s;
s += QStringLiteral("# Recorder: %1.%2.%3\n").arg(APP_VERSION_MAJOR).arg(APP_VERSION_MINOR).arg(APP_VERSION_PATCH); s << "### Versions";
s += QStringLiteral("# Vimba: %1.%2.%3\n").arg(version.major).arg(version.minor).arg(version.patch); s << QString("# Recorder: %1.%2.%3").arg(APP_VERSION_MAJOR).arg(APP_VERSION_MINOR).arg(APP_VERSION_PATCH);
s += QStringLiteral("# Qt: %1.%2.%3\n").arg(QT_VERSION_MAJOR).arg(QT_VERSION_MINOR).arg(QT_VERSION_PATCH); s << QString("# Vimba: %1.%2.%3").arg(version.major).arg(version.minor).arg(version.patch);
s += QStringLiteral("# openCV: %1.%2.%3\n").arg(CV_VERSION_MAJOR).arg(CV_VERSION_MINOR).arg(CV_VERSION_REVISION); s << QString("# Qt: %1.%2.%3").arg(QT_VERSION_MAJOR).arg(QT_VERSION_MINOR).arg(QT_VERSION_PATCH);
s << QString("# openCV: %1.%2.%3").arg(CV_VERSION_MAJOR).arg(CV_VERSION_MINOR).arg(CV_VERSION_REVISION);
return s; return s;
} }
const QString errorCodeToMessage( VmbError_t err ) const QString errorCodeToMessage( VmbError_t err )
{ {
QString msg = "error: "; QString msg = "⚠️ ";
switch( err ) switch( err )
{ {
default: msg += "Unknown"; break; default: msg += "Unknown"; break;
case VmbErrorJustInfo: msg = ""; break; //custom case VmbErrorJustInfo: msg = ""; break; //custom
case VmbErrorSuccess: msg = "Success"; break; case VmbErrorSuccess: msg = "success! 😎"; break; //
case VmbErrorInternalFault: msg += "Unexpected fault in VmbApi or driver."; break; case VmbErrorInternalFault: msg += "Unexpected fault in VmbApi or driver."; break;
case VmbErrorApiNotStarted: msg += "API not started."; break; case VmbErrorApiNotStarted: msg += "API not started."; break;
case VmbErrorNotFound: msg += "Not found."; break; case VmbErrorNotFound: msg += "Not found."; break;
case VmbErrorBadHandle: msg += "Invalid handle "; break; case VmbErrorBadHandle: msg += "Invalid handle "; break;
case VmbErrorDeviceNotOpen: msg += "Device not open."; break; case VmbErrorDeviceNotOpen: msg += "Device not open."; break;
case VmbErrorInvalidAccess: msg += "Invalid access."; break; case VmbErrorInvalidAccess: msg += "Invalid access."; break;
case VmbErrorBadParameter: msg += "Bad parameter."; break; case VmbErrorBadParameter: msg += "Bad parameter."; break;
case VmbErrorStructSize: msg += "Wrong DLL version."; break; case VmbErrorStructSize: msg += "Wrong DLL version."; break;
case VmbErrorMoreData: msg += "More data returned than memory provided."; break; case VmbErrorMoreData: msg += "More data returned than memory provided."; break;
case VmbErrorWrongType: msg += "Wrong type."; break; case VmbErrorWrongType: msg += "Wrong type."; break;
case VmbErrorInvalidValue: msg += "Invalid value."; break; case VmbErrorInvalidValue: msg += "Invalid value."; break;
case VmbErrorTimeout: msg += "Timeout."; break; case VmbErrorTimeout: msg += "Timeout."; break;
case VmbErrorOther: msg += "TL error."; break; case VmbErrorOther: msg += "TL error."; break;
case VmbErrorResources: msg += "Resource not available."; break; case VmbErrorResources: msg += "Resource not available."; break;
case VmbErrorInvalidCall: msg += "Invalid call."; break; case VmbErrorInvalidCall: msg += "Invalid call."; break;
case VmbErrorNoTL: msg += "TL not loaded."; break; case VmbErrorNoTL: msg += "TL not loaded."; break;
case VmbErrorNotImplemented: msg += "Not implemented."; break; case VmbErrorNotImplemented: msg += "Not implemented."; break;
case VmbErrorNotSupported: msg += "Not supported."; break; case VmbErrorNotSupported: msg += "Not supported."; break;
} // ------------------------------- own errCodes -------------------------------
return msg; case errCamIdx: msg += "Camera index out of range."; break;
}
return msg;
} }
QString randomString() QString randomString()
{ {
QStringList list{"a", "b", "c", "d", "e", "f", "g"}; QStringList list{"a", "b", "c", "d", "e", "f", "g"};
//, "h", "i", "j", "k", "l", "m"}; //, "h", "i", "j", "k", "l", "m"};
std::random_device rd; std::random_device rd;
std::mt19937 g(rd()); std::mt19937 g(rd());
std::shuffle(list.begin(), list.end(), g); std::shuffle(list.begin(), list.end(), g);
QString randomString = list.join(""); QString randomString = list.join("");
qDebug() << "Random string:" << randomString; qDebug() << "Random string:" << randomString;
return randomString; return randomString;
}
bool maybeCreateDir(QDir out_dir)
{
if( !out_dir.exists() )
{
qDebug() << "out_dir (" << out_dir.absolutePath() << ") doesn't exist. Should I Create it? ['y'-yes, '?'-no]";
char c='y';
std::cin >> c;
if( c == 'y' )
{
qDebug() << "u pressed yes";
if( out_dir.mkpath(out_dir.absolutePath())) {
qDebug() << "created out_dir";
}
else
{
std::cerr << "failed to create out_dir '" << out_dir.absolutePath().toStdString() << "'" << std::endl;
return false;
}
}
else
{
qDebug() << "u pressed no";
return false;
}
}
qDebug() << "out_dir: " << out_dir.dirName();
return true;
} }
...@@ -4,10 +4,20 @@ ...@@ -4,10 +4,20 @@
#include <QString> #include <QString>
#include "VmbC/VmbCommonTypes.h" //VmbError_t -> cant really fwd-decl typedef...?? #include "VmbC/VmbCommonTypes.h" //VmbError_t -> cant really fwd-decl typedef...??
const QString getVersionString(); class QDir;
const QStringList getVersions();
const QString getVersion();
const QString errorCodeToMessage( VmbError_t ); const QString errorCodeToMessage( VmbError_t );
QString randomString(); QString randomString();
bool maybeCreateDir(QDir);
const QChar DELIM='|'; const QChar DELIM='|';
typedef enum camtronErr
{
errCamIdx = 10, //!< camera index out of range
xx = 11, //!< Unexpected fault in VmbC or driver
} camtronErr;
#endif #endif