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