Skip to content
Snippets Groups Projects
Commit baf20fee authored by am0ebe's avatar am0ebe
Browse files

more stuff

parent 11d29392
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,8 @@ HEADERS += $$SRC_DIR/cmd/*.h \
DEFINES *= QT_USE_QSTRINGBUILDER #converts + to % when building strings #append macro
DEFINES += CONSOLE #add macro
#DEFINES += DEBUG
# opencv
CONFIG += link_pkgconfig
PKGCONFIG += opencv4
......
......@@ -17,7 +17,6 @@ using namespace std::chrono;
Cam::Cam(CameraPtr pCamera) : IPrinter(),
_cam(pCamera),
_name(""),
_id(""),
_state(closed),
_frames(FramePtrVector(threadsPerCam())),
......@@ -27,20 +26,21 @@ _timer(new QTimer(this))
{
_timer->setSingleShot(true);
connect(_timer, SIGNAL(timeout()), this, SLOT(stopRecording()));
name();
id();
}
// Copy constructor
Cam::Cam(const Cam& other) :
IPrinter(),
_cam(other._cam),
_name(other._name),
_id(other._id),
_state(other._state),
_frames(other._frames),
_payloadSize(other._payloadSize),
_pixelFormat(other._pixelFormat)
{}
{
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "copy constructor";
}
Cam::~Cam()
{
......@@ -51,17 +51,6 @@ Cam::~Cam()
// close() should be called automatically, when the last shared_ptr to the camera is destroyed
}
QString Cam::name()
{
if( _name.isEmpty() )
{
std::string str;
f(_cam->GetName( str ));
_name = QString::fromStdString(str);
}
return _name;
}
QString Cam::id()
{
if( _id.isEmpty() )
......@@ -80,15 +69,14 @@ State Cam::state() const
void Cam::open()
{
f(_cam->Open( VmbAccessModeFull ),"open cam #"+_name);
f(_cam->Open( VmbAccessModeFull ),"open cam #"+_id);
//state change will be handled by CamObserver::CameraStateChanged
}
void Cam::close()
{
f(_cam->Close(),"close cam #"+_name);
f(_cam->Close(),"close cam #"+_id);
//state change will be handled by CamObserver::CameraStateChanged
}
/* Does:
......@@ -110,9 +98,10 @@ void Cam::startRecording(seconds dur)
{
FeaturePtr pFeature;
g( _cam->GetFeatureByName ("PayloadSize", pFeature ),"get PayloadSize");
g( _cam->GetFeatureByName ("PayloadSize", pFeature ));
g( pFeature->GetValue (_payloadSize));
print("PayloadSize",_payloadSize);
//XXX adjust packetSize ??
g( _cam->GetFeatureByName("PixelFormat", pFeature));
g( pFeature->GetValue(_pixelFormat));
......@@ -149,10 +138,7 @@ void Cam::startRecording(seconds dur)
void Cam::startRecording(minutes dur)
{
// Convert to seconds
auto dur_s = duration_cast<seconds>(dur);
startRecording(dur_s);
startRecording(duration_cast<seconds>(dur)); // Convert to seconds
}
/* Does:
......@@ -235,13 +221,13 @@ QString Cam::stateToString(const State& state)
void Cam::toggleOpenClose()
{
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << stateToString(_state);
// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << stateToString(_state);
if( _state == opened )
_state = closed;
else if ( _state == closed )
_state = opened;
else
error("toggleOpenClose: cam state is not closed or opened");
error("toggleOpenClose: cam state is neither closed nor opened");
}
void Cam::onCameraDisconnected()
......
......@@ -41,7 +41,6 @@ public:
Cam(const Cam&);
~Cam();
QString name();
QString id();
State state() const;
static QString stateToString(const State&);
......@@ -50,7 +49,7 @@ public:
void open();
void close();
void startRecording(minutes dur);
void startRecording(seconds dur); //use as literals "1s, 1min"
void startRecording(seconds dur); //can use literals "1s, 1min"
QString info();
inline CameraPtr getCameraPtr() const { return _cam; }
......@@ -60,7 +59,6 @@ public slots:
private:
CameraPtr _cam;
QString _name;
QString _id;
State _state;
FramePtrVector _frames;
......
......@@ -11,12 +11,12 @@ void CamObserver::CameraListChanged(CameraPtr pCam, UpdateTriggerType reason)
{
if( UpdateTriggerPluggedIn == reason || UpdateTriggerPluggedOut == reason )
{
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
emit cameraListChanged();
}
else // UpdateTriggerOpenStateChanged
{
emit cameraStateChanged(pCam);
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
// qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
}
}
......@@ -13,7 +13,8 @@
Console::Console(): QObject() {}; // Private constructor to prevent instantiation
Console* Console::getInstance() {
Console* Console::getInstance()
{
static Console* instance = new Console; // Static local variable ensures single instance
return instance;
}
......@@ -30,7 +31,7 @@ void Console::listenKeys()
{
emit numberEntered(std::stoi(input)); // Number
}
else if (input.size() == 1)
else if (input.size() <= 1)
{
emit keyPressed(input[0]); // Single char (excluding single digits)
if( input[0] == 'q' )
......@@ -131,7 +132,7 @@ Controller::~Controller()
void Controller::onKeyPressed(const QChar& key)
{
auto console = Console::getInstance();
qDebug().noquote() << __FUNCTION__ << ": " << key;
// qDebug().noquote() << __FUNCTION__ << ": " << key;
switch (key.unicode())
{
......@@ -175,9 +176,9 @@ void Controller::onKeyPressed(const QChar& key)
}
}
void Controller::onLineEntered(const QString&)
void Controller::onLineEntered(const QString& line)
{
// qDebug().noquote() << "Line entered: " << line;
qDebug().noquote() << "Line entered: " << line;
}
void Controller::onNumberEntered(int number)
......
......@@ -27,8 +27,8 @@ int main(int argc, char *argv[])
QObject::connect(&controller, &Controller::setDuration, &core, &Core::setDuration);
// XXX add new func
// QTimer::singleShot(10, controller.console, SLOT(printVersion()), Qt::DirectConnection); // for testing
// QTimer::singleShot(200, &core, SLOT(openCam())); // for testing
QTimer::singleShot(0, Console::getInstance(), SLOT(printVersion()));
QTimer::singleShot(100, &core, SLOT(openCam())); // for testing
return a.exec();
}
......@@ -25,7 +25,7 @@ Core::Core() : IPrinter(),
_apiStarted( false ),
_sys( VmbSystem::GetInstance() ), // create and get Vimba singleton
_cameras( CamPtrVector() ),
_recDuration( 16s ) //default
_recDuration( 6s ) //default
{
QTimer::singleShot(0, this, SLOT(init())); //delayed init to allow connections to be established -> print/error signals!
}
......@@ -37,6 +37,8 @@ void Core::init()
_apiStarted = true;
print("threads",QThread::idealThreadCount());
auto camObserver = new CamObserver();
connect( camObserver, SIGNAL(cameraListChanged()), this, SLOT(listCams()) ); //listcams calls updateCams!
connect( camObserver, SIGNAL(cameraStateChanged(CameraPtr)), this, SLOT(toggleCamState(CameraPtr)) ); //
......@@ -84,7 +86,7 @@ void Core::updateCameras()
if (!found)
{
_cameras.push_back(std::make_shared<Cam>(vcam)); //create Cam() from CameraPtr vcam
print({"cam connected:",_cameras.back()->name()});
print(QString("cam connected: %1").arg(_cameras.back()->id()));
}
}
......@@ -92,7 +94,7 @@ void Core::updateCameras()
auto it = _cameras.begin();
while (it != _cameras.end())
{
qDebug() << "check " << (*it)->id();
// qDebug() << "check " << (*it)->id();
bool found = false;
for (const auto& vcam : vmbCameras)
......@@ -108,11 +110,11 @@ void Core::updateCameras()
if (!found)
{
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << " !!! ";
print({"cam disconnected",(*it)->name()});
print({"cam disconnected",(*it)->id()});
it = _cameras.erase(it);
}
}
} // now ~Camera() should be called on removed cams. >> camObserver
} // now ~Camera() should be called on removed cams. >> triggers camObserver
void Core::toggleCamState(CameraPtr vcam)
{
......@@ -127,7 +129,8 @@ void Core::listCams()
if( !_apiStarted )
return;
updateCameras();
updateCameras();]
print("cams",_cameras.size());
QStringList allCamInfo;
auto idx=0;
......@@ -188,22 +191,17 @@ CamPtr Core::cam(const unsigned long &idx)
void Core::startRecording()
{
if( cam() == nullptr )
return;
cam()->startRecording( _recDuration ); //XXX dur from user input
if( cam() )
cam()->startRecording( _recDuration );
}
void Core::stopRecording()
{
if( cam() == nullptr )
return;
if( cam() )
cam()->stopRecording();
}
void Core::setDuration(int dur)
{
qDebug() << __LINE__ << "-" << __PRETTY_FUNCTION__ << "";
_recDuration = seconds(dur);
}
......@@ -25,6 +25,8 @@ FrameProcessor::~FrameProcessor()
// post: frame needs to be requeued
void FrameProcessor::processFrame()
{
static int count = 0;
++count;
VmbUint32_t width = 0;
VmbUint32_t height = 0;
unsigned char* pdata = nullptr;
......@@ -37,21 +39,26 @@ void FrameProcessor::processFrame()
m_pframe->GetTimestamp(timestamp);
m_pframe->GetPixelFormat(pixelFormat);
QString pixelFormatStr = "RGB8";
if (pixelFormat != VmbPixelFormatRgb8)
{
qWarning() << "⚠️ Pixel format is not RGB8, 2D: implement convert func ... ";
pixelFormatStr = "???";
}
qDebug() << "Frame received: " << width << "x" << height << "px, format: " << pixelFormat << ", timestamp: " << timestamp;
cv::Mat frameMat(height, width, CV_8UC3, pdata);
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;
qDebug() << "rcvd Frame #" << count << ": " << width << "x" << height << "px, format: " << pixelFormatStr << ", timestamp: " << timestamp << ", file: " << filename;
#ifdef DEBUG
QThread::msleep(2000); //simulate processing time // testing
#endif
emit frameProcessed(m_pframe);
}
......@@ -21,13 +21,20 @@ using namespace VmbCPP;
int ncam()
{
#ifdef DEBUG
return 1; //XXX read in from config file
#else
return 1;
#endif
}
int threadsPerCam()
{
// return std::ceil(static_cast<double>(QThread::idealThreadCount()) / ncam() ); //round up!
return 2; // for testing
#ifdef DEBUG
return 2;
#else
return std::ceil(static_cast<double>(QThread::idealThreadCount()) / ncam() ); //round up!
#endif
}
const QString getVersion()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment