CameraThread.cpp
Go to the documentation of this file.
00001 
00002 #include <blort/Tracker/CameraThread.h>
00003 #include <stdexcept>
00004 
00005 using namespace Tracking;
00006 
00007 CameraThread::CameraThread(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("[CameraThread::CameraThread] 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                 
00024                 if(m_image->width != width || m_image->height != height){
00025                         char errmsg[128];
00026                         sprintf(errmsg, "[CameraThread::CameraThread] Created capture with wrong resolution %dx%d instead of %dx%d (OpenCV)", m_image->width, m_image->height, width, height);
00027                         throw std::runtime_error(errmsg);                       
00028                 }
00029                 
00030         m_mutex.Unlock();
00031 }
00032 
00033 CameraThread::~CameraThread()
00034 {
00035         this->Stop();
00036 }
00037 
00038 BOOL CameraThread::OnTask()
00039 {
00040         m_image = cvQueryFrame(m_capture);
00041         m_new_image = true;
00042         return TRUE;
00043 }
00044 
00045 void CameraThread::GetImage(IplImage* image)
00046 {
00047         if(m_new_image){
00048 //              printf("%d %d, %d %d\n", m_image->width, m_image->height, image->width, image->height);
00049                 cvCopyImage(m_image, image);
00050                 m_new_image = false;
00051         }
00052 }
00053 


blort
Author(s): Michael Zillich, Thomas Mörwald, Johann Prankl, Andreas Richtsfeld, Bence Magyar (ROS version)
autogenerated on Thu Jan 2 2014 11:38:25