示例#1
0
bool Controller::connectToCamera(QString videoPath, int imageBufferSize, bool dropFrame, int capThreadPrio, int procThreadPrio)
{
	// Local variables
	bool isOpened=false;
	// Store imageBufferSize in private member
	this->imageBufferSize=imageBufferSize;
	// Create image buffer with user-defined settings
	imageBuffer = new ImageBuffer(imageBufferSize,dropFrame);
	// Create capture thread
	captureThread = new CaptureThread(imageBuffer);
	// Attempt to connect to camera
	if((isOpened=captureThread->connectToCamera(videoPath)))
	{
		// Create processing thread
		processingThread = new ProcessingThread(imageBuffer,captureThread->getInputSourceWidth(),captureThread->getInputSourceHeight());
		// Start capturing frames from camera
		captureThread->start((QThread::Priority)capThreadPrio);
		// Start processing captured frames
		processingThread->start((QThread::Priority)procThreadPrio);
	}
	else
	{
		// Delete capture thread
		deleteCaptureThread();
		// Delete image buffer
		deleteImageBuffer();
	}
	// Return camera open result
	return isOpened;
} // connectToCamera()
示例#2
0
/*
 * Called by the Main Window upon loading a video file.
 * Instantiates the threads and starts them.
 *
 * Note: Don't worry about having threads waste processing power by
 * running perpetually, even when there's nothing to do.
 * Use of semaphores will cause threads to wait for resources.
 */
bool Controller::loadVideo(QString filePath, int capThreadPrio,
                           int procThreadPrio, int dispThreadPrio) {
    bool isOpened = false; //local variable
    ImageHandler *imageHandler = new ImageHandler();
    ImageData *imageData = new ImageData();

    captureThread = new CaptureThread(imageHandler);
    processThread = new ProcessingThread(imageHandler, imageData);
    displayThread = new DisplayThread(imageData);

    if ((isOpened = captureThread->loadVideo(filePath))) {
        qDebug() << "Loaded video successfully.";
        qDebug() << "Starting threads...";

        captureThread->start((QThread::Priority)capThreadPrio);
        processThread->start((QThread::Priority)procThreadPrio);

        displayThread->start((QThread::Priority)dispThreadPrio);
    } else {
        qDebug() << "Video failed to open.";
        deleteCaptureThread();
        deleteProcessingThread();
        deleteDisplayThread();
    }
    qDebug() << "Completed loadVideo call from Controller.";
    return isOpened;
}
示例#3
0
void Controller::disconnectCamera()
{
	// Stop processing thread
	if(processingThread->isRunning())
		stopProcessingThread();
	// Stop capture thread
	if(captureThread->isRunning())
		stopCaptureThread();
	// Clear image buffer
	clearImageBuffer();
	// Disconnect camera
	captureThread->disconnectCamera();
	// Delete threads
	deleteCaptureThread();
	deleteProcessingThread();
	// Delete image buffer
	deleteImageBuffer();
} // disconnectCamera()
示例#4
0
/*
 * Causes the various threads to stop gracefully.
 * Allow each thread to handle its own resources, and simply delegate calls to them.
 */
void Controller::dropVideo() {
    if (captureThread->isRunning())
        stopCaptureThread();
    captureThread->dropVideo();
    deleteCaptureThread();

    if (displayThread->isRunning())
        stopDisplayThread();
    displayThread->dropFrame();
    deleteDisplayThread();

    if (processThread->isRunning())
        stopProcessingThread();
    processThread->dropFrame();
    //Remember, only the captureThread keeps track of the video.
    deleteProcessingThread();

    qDebug() << "Finished everything!";
}