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.
43 #include <DeepSeaIF.h>
46 #pragma comment(lib,"DeepSeaIF.lib")
50 /****************** Capturing video from TYZX stereo camera *******************/
51 /** Initially developed by Roman Stanchak rstanchak@yahoo.com */
53 class CvCaptureCAM_TYZX : public CvCapture
56 CvCaptureCAM_TYZX() { index = -1; image = 0; }
57 virtual ~CvCaptureCAM_TYZX() { close(); }
59 virtual bool open( int _index );
61 bool isOpened() { return index >= 0; }
63 virtual double getProperty(int);
64 virtual bool setProperty(int, double) { return false; }
65 virtual bool grabFrame();
66 virtual IplImage* retrieveFrame(int);
67 virtual int getCaptureDomain() { return CV_CAP_TYZX; } // Return the type of the capture object: CV_CAP_VFW, etc...
70 virtual bool allocateImage();
77 DeepSeaIF * g_tyzx_camera = 0;
78 int g_tyzx_refcount = 0;
80 bool CvCaptureCAM_TYZX::open( int _index )
85 g_tyzx_camera = new DeepSeaIF;
86 if(!g_tyzx_camera) return false;
88 if(!g_tyzx_camera->initializeSettings(NULL)){
93 // set initial sensor mode
94 // TODO is g_tyzx_camera redundant?
95 g_tyzx_camera->setSensorMode(g_tyzx_camera->getSensorMode());
98 g_tyzx_camera->setZUnits((int) 1000);
100 g_tyzx_camera->enableLeftColor(true);
101 g_tyzx_camera->setColorMode(DeepSeaIF::BGRcolor);
102 g_tyzx_camera->setDoIntensityCrop(true);
103 g_tyzx_camera->enable8bitImages(true);
104 if(!g_tyzx_camera->startCapture()){
113 void CvCaptureCAM_TYZX::close()
117 cvReleaseImage( &image );
119 if(g_tyzx_refcount==0){
120 delete g_tyzx_camera;
125 bool CvCaptureCAM_TYZX::grabFrame()
127 return isOpened() && g_tyzx_camera && g_tyzx_camera->grab();
130 bool CvCaptureCAM_TYZX::allocateImage()
135 // assume we want to resize
136 cvReleaseImage(&image);
138 // figure out size depending on index provided
141 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
146 size = cvSize(g_tyzx_camera->zWidth(), g_tyzx_camera->zHeight());
147 depth = IPL_DEPTH_16S;
152 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
157 image = cvCreateImage(size, depth, nch);
161 /// Copy 'grabbed' image into capture buffer and return it.
162 IplImage * CvCaptureCAM_TYZX::retrieveFrame(int)
164 if(!isOpened() || !g_tyzx_camera) return 0;
166 if(!image && !alocateImage())
169 // copy camera image into buffer.
170 // tempting to reference TYZX memory directly to avoid copying.
174 memcpy(image->imageData, g_tyzx_camera->getRImage(), image->imageSize);
177 memcpy(image->imageData, g_tyzx_camera->getZImage(), image->imageSize);
181 memcpy(image->imageData, g_tyzx_camera->getLImage(), image->imageSize);
188 double CvCaptureCAM_TYZX::getProperty(int property_id)
191 switch(capture->index)
194 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
197 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
200 size = cvSize(g_tyzx_camera->zWidth(), g_tyzx_camera->zHeight());
206 switch( property_id )
208 case CV_CAP_PROP_FRAME_WIDTH:
210 case CV_CAP_PROP_FRAME_HEIGHT:
217 bool CvCaptureCAM_TYZX::setProperty( int, double )
222 CvCapture * cvCreateCameraCapture_TYZX (int index)
224 CvCaptureCAM_TYZX * capture = new CvCaptureCAM_TYZX;
225 if( capture->open(index) )