CaptureClass.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2007     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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 //# include <cvcam.h>
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     // Init font
00052     cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX/*|CV_FONT_ITALIC*/, 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( );//returns the number of available cameras in the system
00071     //printf("Number of Cams: %d\n",ncams);
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     //FIXME: cvcamGetCamerasCount is not available on Linux
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     //static int i = 0;
00119     // Get frame
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      // copy memory frame to image
00131         cvCopy( frame, captureImage, 0 );
00132 
00133     // Flip
00134         cvFlip(captureImage, captureImage);
00135 
00136     // label
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 

Generated on Wed Nov 23 19:00:00 2011 for FreeCAD by  doxygen 1.6.1