mirror of
https://github.com/vale981/Taevitas
synced 2025-03-05 09:31:42 -05:00
write t'll it is over
This commit is contained in:
parent
60dc96f50b
commit
961cbb7b48
4 changed files with 2 additions and 201 deletions
|
@ -68,7 +68,7 @@ void CameraManager::imageGrabbed( FlyCapture2::Image * image ) {
|
|||
image_buffer->removeFirst();
|
||||
|
||||
if(!is_capturing && image_buffer->empty())
|
||||
emit stopped;
|
||||
emit finishedCapturing;
|
||||
|
||||
mutex.unlock();
|
||||
return;
|
||||
|
|
|
@ -1,116 +0,0 @@
|
|||
#include "cameramanager.h"
|
||||
#include <QDebug>
|
||||
#include <QMutex>
|
||||
|
||||
using namespace FlyCapture2;
|
||||
|
||||
CameraManager::CameraManager( QObject * parent ) : QObject( parent ), num_cameras {0}, camera_index {-1}, is_capturing {false} {
|
||||
image_buffer = new QVector<FlyCapture2::Image *>();
|
||||
}
|
||||
|
||||
CameraManager::~CameraManager() {
|
||||
delete image_buffer;
|
||||
|
||||
stopCapture();
|
||||
camera.Disconnect();
|
||||
}
|
||||
|
||||
void CameraManager::connectCamera( int index ) {
|
||||
// Don't connect twice.
|
||||
if ( camera_index == index )
|
||||
return;
|
||||
|
||||
Error error; // general purpose error object
|
||||
if ( camera.IsConnected() ) {
|
||||
error = camera.Disconnect();
|
||||
if ( error != PGRERROR_OK ) {
|
||||
throw error;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Connecting to camera: " << index << '\n';
|
||||
|
||||
// get PGRGuid of the Camera
|
||||
BusManager bus_mgr;
|
||||
error = bus_mgr.GetCameraFromIndex( index, &camera_guid );
|
||||
if ( error != PGRERROR_OK ) {
|
||||
throw error;
|
||||
return;
|
||||
}
|
||||
|
||||
// connectCamera
|
||||
error = camera.Connect( &camera_guid );
|
||||
if ( error != PGRERROR_OK ) {
|
||||
throw error;
|
||||
return;
|
||||
}
|
||||
|
||||
cam_config = FlyCapture2::FC2Config();
|
||||
cam_config.grabMode = GrabMode::BUFFER_FRAMES;
|
||||
cam_config.numBuffers = 10; // We gonna move them into our own data structure.
|
||||
cam_config.highPerformanceRetrieveBuffer = true;
|
||||
camera.SetConfiguration( &cam_config );
|
||||
|
||||
camera_index = index;
|
||||
}
|
||||
|
||||
// The capture callback is a wrapper to emit the frameCaptured signal.
|
||||
void CameraManager::imageGrabbed( FlyCapture2::Image * image ) {
|
||||
//thread Safe
|
||||
static QMutex mutex;
|
||||
mutex.lock();
|
||||
|
||||
image_buffer->append( image );
|
||||
emit frameCaptured( image_buffer->front() );
|
||||
delete image_buffer->front();
|
||||
|
||||
image_buffer->removeFirst();
|
||||
|
||||
if(!is_capturing && image_buffer->empty())
|
||||
emit finishedCapturing;
|
||||
|
||||
mutex.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
bool CameraManager::stopCapture() {
|
||||
if ( !is_capturing )
|
||||
return false;
|
||||
|
||||
|
||||
grabber->stopCapturing();
|
||||
Error error = camera.StopCapture();
|
||||
if ( error != PGRERROR_OK ) {
|
||||
throw error;
|
||||
return false;
|
||||
}
|
||||
|
||||
is_capturing = false;
|
||||
|
||||
return image_buffer->empty();
|
||||
}
|
||||
|
||||
void CameraManager::startCapture() {
|
||||
// Don't capture twice!
|
||||
if ( is_capturing )
|
||||
return;
|
||||
|
||||
Error error;
|
||||
error = camera.StartCapture();
|
||||
|
||||
if ( error != PGRERROR_OK ) {
|
||||
throw error;
|
||||
return;
|
||||
}
|
||||
|
||||
// Just my own async image grabbing!
|
||||
// TODO: ERRORS!
|
||||
grabber = new ImageGrabber( this );
|
||||
grabber->setCamera( &camera );
|
||||
connect( grabber, &ImageGrabber::imageCaptured, this, &CameraManager::imageGrabbed, Qt::QueuedConnection );
|
||||
connect( grabber, &ImageGrabber::finished, grabber, &ImageGrabber::deleteLater );
|
||||
grabber->start();
|
||||
|
||||
is_capturing = true;
|
||||
}
|
|
@ -76,7 +76,7 @@ private slots:
|
|||
|
||||
signals:
|
||||
void frameCaptured(FlyCapture2::Image* image) const;
|
||||
void stopped() const;
|
||||
void finishedCapturing() const;
|
||||
};
|
||||
|
||||
#endif // CAMERAMANAGER_H
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
#ifndef CAMERAMANAGER_H
|
||||
#define CAMERAMANAGER_H
|
||||
|
||||
|
||||
/*
|
||||
This Class is an abstraction over the FlyCapture2 API for handeling the connection to the camera and
|
||||
hiding the internals from the GUI code, to make reusability easier, although FlyCapture code is needed outside.
|
||||
*/
|
||||
|
||||
// TODO: implement camera arrival removal
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QThread>
|
||||
#include "FlyCapture2.h"
|
||||
#include "imagegrabber.h"
|
||||
|
||||
class CameraManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CameraManager(QObject *parent = 0);
|
||||
~CameraManager();
|
||||
|
||||
// Starts capturing images. When an image has been captured, the signal frameCaptured is emited.
|
||||
// Throws FlyCapture2::Error
|
||||
void startCapture();
|
||||
bool stopCapture();
|
||||
|
||||
//TODO remove, if not needed
|
||||
const FlyCapture2::Camera* getCamera() const {
|
||||
return &camera;
|
||||
};
|
||||
|
||||
bool isConnected() {
|
||||
return camera.IsConnected();
|
||||
}
|
||||
|
||||
// Get the number of connected cameras.
|
||||
unsigned int numCameras() {
|
||||
FlyCapture2::BusManager bus_mgr;
|
||||
bus_mgr.GetNumOfCameras(&num_cameras);
|
||||
return num_cameras;
|
||||
};
|
||||
|
||||
// Connect camera from index. Once successfull it emits the cameraConnected signal.
|
||||
// Emits Error signal in case of an error.
|
||||
void connectCamera(int);
|
||||
|
||||
bool isCapturing() {
|
||||
return is_capturing;
|
||||
}
|
||||
|
||||
private:
|
||||
FlyCapture2::Camera camera;
|
||||
FlyCapture2::FC2Config cam_config;
|
||||
|
||||
unsigned int num_cameras;
|
||||
|
||||
// GUID of the camera, which is currently being used
|
||||
FlyCapture2::PGRGuid camera_guid;
|
||||
|
||||
// Index of the current camera
|
||||
int camera_index;
|
||||
|
||||
// State Variable
|
||||
bool is_capturing;
|
||||
|
||||
QVector<FlyCapture2::Image *> *image_buffer;
|
||||
|
||||
// Capture Thread
|
||||
ImageGrabber *grabber;
|
||||
|
||||
private slots:
|
||||
void imageGrabbed(FlyCapture2::Image *image);
|
||||
|
||||
signals:
|
||||
void frameCaptured(FlyCapture2::Image* image) const;
|
||||
void finishedCapturing() const;
|
||||
};
|
||||
|
||||
#endif // CAMERAMANAGER_H
|
||||
|
Loading…
Add table
Reference in a new issue