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.
45 #pragma warning( disable: 4711 )
48 #if (defined WIN64 || defined _WIN64) && defined _MSC_VER && !defined __ICL
49 #pragma optimize("",off)
53 /************************* Reading AVIs & Camera data **************************/
55 CV_IMPL void cvReleaseCapture( CvCapture** pcapture )
57 if( pcapture && *pcapture )
64 CV_IMPL IplImage* cvQueryFrame( CvCapture* capture )
66 return capture ? capture->queryFrame() : 0;
70 CV_IMPL int cvGrabFrame( CvCapture* capture )
72 return capture ? capture->grabFrame() : 0;
75 CV_IMPL IplImage* cvRetrieveFrame( CvCapture* capture, int idx )
77 return capture ? capture->retrieveFrame(idx) : 0;
80 CV_IMPL double cvGetCaptureProperty( CvCapture* capture, int id )
82 return capture ? capture->getProperty(id) : 0;
85 CV_IMPL int cvSetCaptureProperty( CvCapture* capture, int id, double value )
87 return capture ? capture->setProperty(id, value) : 0;
90 CV_IMPL int cvGetCaptureDomain( CvCapture* capture)
92 return capture ? capture->getCaptureDomain() : 0;
97 * Camera dispatching method: index is the camera number.
98 * If given an index from 0 to 99, it tries to find the first
99 * API that can access a given camera index.
100 * Add multiples of 100 to select an API.
102 CV_IMPL CvCapture * cvCreateCameraCapture (int index)
106 #ifdef HAVE_VIDEOINPUT
109 CV_CAP_IEEE1394, // identical to CV_CAP_DC1394
111 CV_CAP_VFW, // identical to CV_CAP_V4L
118 // interpret preferred interface (0 = autodetect)
119 int pref = (index / 100) * 100;
127 // try every possibly installed camera API
128 for (int i = 0; domains[i] >= 0; i++)
130 #if defined(HAVE_VIDEOINPUT) || defined(HAVE_TYZX) || defined(HAVE_VFW) || \
131 defined(HAVE_CAMV4L) || defined (HAVE_CAMV4L2) || defined(HAVE_GSTREAMER) || \
132 defined(HAVE_DC1394_2) || defined(HAVE_DC1394) || defined(HAVE_CMU1394) || \
133 defined(HAVE_GSTREAMER) || defined(HAVE_MIL) || defined(HAVE_QUICKTIME) || \
135 // local variable to memorize the captured device
141 #ifdef HAVE_VIDEOINPUT
143 capture = cvCreateCameraCapture_DShow (index);
151 capture = cvCreateCameraCapture_TYZX (index);
159 capture = cvCreateCameraCapture_VFW (index);
163 #if defined (HAVE_CAMV4L) || defined (HAVE_CAMV4L2)
164 capture = cvCreateCameraCapture_V4L (index);
168 #ifdef HAVE_GSTREAMER
169 capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L2, 0);
172 capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L, 0);
178 case CV_CAP_FIREWIRE:
180 capture = cvCreateCameraCapture_DC1394_2 (index);
185 capture = cvCreateCameraCapture_DC1394 (index);
190 capture = cvCreateCameraCapture_CMU (index);
194 #ifdef HAVE_GSTREAMER
195 capture = cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_1394, 0);
203 capture = cvCreateCameraCapture_MIL (index);
209 #ifdef HAVE_QUICKTIME
211 capture = cvCreateCameraCapture_QT (index);
219 capture = cvCreateCameraCapture_Unicap (index);
228 // failed open a camera
233 * Videoreader dispatching method: it tries to find the first
234 * API that can access a given filename.
236 CV_IMPL CvCapture * cvCreateFileCapture (const char * filename)
238 CvCapture * result = 0;
242 result = cvCreateFileCapture_Win32 (filename);
247 result = cvCreateFileCapture_FFMPEG (filename);
252 result = cvCreateFileCapture_XINE (filename);
255 #ifdef HAVE_GSTREAMER
257 result = cvCreateCapture_GStreamer (CV_CAP_GSTREAMER_FILE, filename);
260 #ifdef HAVE_QUICKTIME
262 result = cvCreateFileCapture_QT (filename);
266 result = cvCreateFileCapture_Images (filename);
272 * Videowriter dispatching method: it tries to find the first
273 * API that can write a given stream.
275 CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc,
276 double fps, CvSize frameSize, int is_color )
278 //CV_FUNCNAME( "cvCreateVideoWriter" );
280 CvVideoWriter *result = 0;
283 result = cvCreateVideoWriter_Images(filename);
287 result = cvCreateVideoWriter_Win32(filename, fourcc, fps, frameSize, is_color);
292 result = cvCreateVideoWriter_XINE(filename, fourcc, fps, frameSize, is_color);
297 result = cvCreateVideoWriter_FFMPEG(filename, fourcc, fps, frameSize, is_color);
300 #ifdef HAVE_QUICKTIME
302 result = cvCreateVideoWriter_QT(filename, fourcc, fps, frameSize, is_color);
306 result = cvCreateVideoWriter_Images(filename);
311 CV_IMPL int cvWriteFrame( CvVideoWriter* writer, const IplImage* image )
313 return writer ? writer->writeFrame(image) : 0;
316 CV_IMPL void cvReleaseVideoWriter( CvVideoWriter** pwriter )
318 if( pwriter && *pwriter )
328 VideoCapture::VideoCapture()
331 VideoCapture::VideoCapture(const string& filename)
336 VideoCapture::VideoCapture(int device)
341 VideoCapture::~VideoCapture()
346 bool VideoCapture::open(const string& filename)
348 cap = cvCreateFileCapture(filename.c_str());
352 bool VideoCapture::open(int device)
354 cap = cvCreateCameraCapture(device);
358 bool VideoCapture::isOpened() const { return !cap.empty(); }
360 void VideoCapture::release()
365 bool VideoCapture::grab()
367 return cvGrabFrame(cap) != 0;
370 bool VideoCapture::retrieve(Mat& image, int channel)
372 IplImage* _img = cvRetrieveFrame(cap, channel);
378 if(_img->origin == IPL_ORIGIN_TL)
383 flip(temp, image, 0);
388 VideoCapture& VideoCapture::operator >> (Mat& image)
397 bool VideoCapture::set(int propId, double value)
399 return cvSetCaptureProperty(cap, propId, value) != 0;
402 double VideoCapture::get(int propId)
404 return cvGetCaptureProperty(cap, propId);
407 VideoWriter::VideoWriter()
410 VideoWriter::VideoWriter(const string& filename, int fourcc, double fps, Size frameSize, bool isColor)
412 open(filename, fourcc, fps, frameSize, isColor);
415 VideoWriter::~VideoWriter()
420 bool VideoWriter::open(const string& filename, int fourcc, double fps, Size frameSize, bool isColor)
422 writer = cvCreateVideoWriter(filename.c_str(), fourcc, fps, frameSize, isColor);
426 bool VideoWriter::isOpened() const
428 return !writer.empty();
431 VideoWriter& VideoWriter::operator << (const Mat& image)
433 IplImage _img = image;
434 cvWriteFrame(writer, &_img);