CaptureClass.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <stdio.h>
00027 #endif
00028
00029 #include "CaptureClass.h"
00030
00031 #ifdef _MSC_VER // this file is not available on Linux
00032
00033 #endif
00034
00035
00036
00038 Capturerer::Capturerer(int num)
00039 : capture(NULL),captureImage(0),_bIsWinOn(false)
00040 {
00041 capture = cvCaptureFromCAM( num );
00042
00043 if( !capture )
00044 throw "Cant create capture device";
00045
00046 hScale=0.5;
00047 vScale=0.5;
00048 lineWidth=1;
00049 useLabel=true;
00050
00051
00052 cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX, hScale,vScale,0,lineWidth);
00053
00054
00055 }
00057 Capturerer::Capturerer(const char* fileName)
00058 : capture(NULL), captureImage(0),_bIsWinOn(false)
00059 {
00060 capture = cvCaptureFromAVI( fileName );
00061
00062 if( !capture )
00063 throw "Cant create capture device";
00064
00065 }
00066
00067 int Capturerer::chooseCamNum(void)
00068 {
00069 #if 0
00070 int ncams = cvcamGetCamerasCount( );
00071
00072 int* out;
00073 if(ncams >1){
00074 int nselected = cvcamSelectCamera(&out);
00075 if(nselected>0)
00076 printf("the 1-st selected camera is camera number %d", out[0]);
00077 if(nselected == 2)
00078 printf("the 2-nd selected camera is camera number %d", out[1]);
00079 }else if (ncams < 1){
00080 printf("No camara in system! Terminating.\n");
00081 return -1;
00082 }else
00083 out = new int(0);
00084
00085 return *out;
00086 #else
00087
00088 return -1;
00089 #endif
00090 }
00091
00092 Capturerer::~Capturerer()
00093 {
00094 if(_bIsWinOn)
00095 cvDestroyWindow("Capture");
00096 if(capture)
00097 cvReleaseCapture(&capture);
00098 }
00099
00100
00101 void Capturerer::setCaptureWindows(bool On)
00102 {
00103 if(!_bIsWinOn && On)
00104 {
00105 cvNamedWindow( "Capture", 0 );
00106 _bIsWinOn = true;
00107 }
00108 if(_bIsWinOn && !On)
00109 {
00110 cvDestroyWindow("Capture");
00111 _bIsWinOn = false;
00112 }
00113 }
00114
00115
00116 char Capturerer::getOneCapture(const char *text)
00117 {
00118
00119
00120 IplImage* frame = NULL;
00121 frame = cvQueryFrame( capture );
00122
00123 if( !frame )
00124 throw "Cannot get frame";
00125
00126 if(! captureImage)
00127 size = cvGetSize(frame);
00128 captureImage = cvCreateImage( size, 8, 3 );
00129
00130
00131 cvCopy( frame, captureImage, 0 );
00132
00133
00134 cvFlip(captureImage, captureImage);
00135
00136
00137 if (text)
00138 cvPutText (captureImage,text, cvPoint(0,size.height - 5) , &font, cvScalar(0,255,0));
00139
00140
00141 if(_bIsWinOn)
00142 cvShowImage( "Capture", captureImage );
00143
00144 return cvWaitKey(1);
00145
00146 }
00147