CameraThread.cpp
Go to the documentation of this file.
00001 
00002 #include <blort/ThreadObject/CameraThread.h>
00003 #include <opencv2/legacy/compat.hpp>
00004 #include <stdexcept>
00005 
00006 
00007 CCameraThread::CCameraThread(int camID, int width, int height)
00008 {
00009         m_mutex.Lock();
00010                 m_new_image = false;
00011                 m_camID = camID;
00012                 m_width = width;
00013                 m_height = height;
00014                 
00015                 m_capture = cvCreateCameraCapture(m_camID);
00016                 
00017                 if(!m_capture)
00018                         throw std::runtime_error("[CCameraThread::CCameraThread] Can not create camera capture.\n");
00019                 
00020                 cvSetCaptureProperty(m_capture, CV_CAP_PROP_FRAME_WIDTH, m_width );
00021                 cvSetCaptureProperty(m_capture, CV_CAP_PROP_FRAME_HEIGHT, m_height );
00022                 m_image = cvQueryFrame(m_capture);
00023         m_mutex.Unlock();
00024 }
00025 
00026 CCameraThread::~CCameraThread()
00027 {
00028         this->Stop();
00029 }
00030 
00031 BOOL CCameraThread::OnTask()
00032 {
00033         m_image = cvQueryFrame(m_capture);
00034         m_new_image = true;
00035         return TRUE;
00036 }
00037 
00038 bool CCameraThread::GetImage(IplImage* image)
00039 {
00040         if(m_new_image){
00041                 cvCopyImage(m_image, image);
00042                 m_new_image = false;
00043                 return true;
00044         }
00045         return false;
00046 }
00047 


blort
Author(s): Thomas Mörwald , Michael Zillich , Andreas Richtsfeld , Johann Prankl , Markus Vincze , Bence Magyar
autogenerated on Wed Aug 26 2015 15:24:12