1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
44 #ifdef HAVE_VIDEOINPUT
45 #include "videoinput.h"
47 /********************* Capturing video from camera via VFW *********************/
49 class CvCaptureCAM_DShow : public CvCapture
53 virtual ~CvCaptureCAM_DShow() { close(); }
55 virtual bool open( int index );
57 virtual double getProperty(int);
58 virtual bool setProperty(int, double);
59 virtual bool grabFrame();
60 virtual IplImage* retrieveFrame(int);
61 virtual int getCaptureDomain() { return CV_CAP_DSHOW; } // Return the type of the capture object: CV_CAP_VFW, etc...
72 struct SuppressVideoInputMessages
74 SuppressVideoInputMessages() { videoInput::setVerbose(false); }
77 static SuppressVideoInputMessages do_it;
78 videoInput CvCaptureCAM_DShow::VI;
80 CvCaptureCAM_DShow::CvCaptureCAM_DShow()
86 void CvCaptureCAM_DShow::close()
92 cvReleaseImage(&frame);
96 // Initialize camera input
97 bool CvCaptureCAM_DShow::open( int _index )
100 VI.setupDevice(_index);
101 if( !VI.isDeviceSetup(_index) )
107 bool CvCaptureCAM_DShow::grabFrame()
113 IplImage* CvCaptureCAM_DShow::retrieveFrame(int)
115 if( !frame || VI.getWidth(index) != frame->width || VI.getHeight(index) != frame->height )
118 cvReleaseImage( &frame );
119 int w = VI.getWidth(index), h = VI.getHeight(index);
120 frame = cvCreateImage( cvSize(w,h), 8, 3 );
123 VI.getPixels( index, (uchar*)frame->imageData, false, true );
127 double CvCaptureCAM_DShow::getProperty( int property_id )
129 switch( property_id )
131 case CV_CAP_PROP_FRAME_WIDTH:
132 return VI.getWidth(index);
133 case CV_CAP_PROP_FRAME_HEIGHT:
134 return VI.getHeight(index);
135 case CV_CAP_PROP_FOURCC:
141 bool CvCaptureCAM_DShow::setProperty( int property_id, double value )
143 int width = 0, height = 0;
145 switch( property_id )
147 case CV_CAP_PROP_FRAME_WIDTH:
148 width = cvRound(value);
151 case CV_CAP_PROP_FRAME_HEIGHT:
152 height = cvRound(value);
158 if( width != VI.getWidth(index) || height != VI.getHeight(index) )
160 VI.stopDevice(index);
161 VI.setupDevice(index, width, height);
163 return VI.isDeviceSetup(index);
167 CvCapture* cvCreateCameraCapture_DShow( int index )
169 CvCaptureCAM_DShow* capture = new CvCaptureCAM_DShow;
171 if( capture->open( index ))
179 #pragma comment(lib, "videoInput.lib")