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();
69 virtual bool allocateImage();
76 DeepSeaIF * g_tyzx_camera = 0;
77 int g_tyzx_refcount = 0;
79 bool CvCaptureCAM_TYZX::open( int _index )
84 g_tyzx_camera = new DeepSeaIF;
85 if(!g_tyzx_camera) return false;
87 if(!g_tyzx_camera->initializeSettings(NULL)){
92 // set initial sensor mode
93 // TODO is g_tyzx_camera redundant?
94 g_tyzx_camera->setSensorMode(g_tyzx_camera->getSensorMode());
97 g_tyzx_camera->setZUnits((int) 1000);
99 g_tyzx_camera->enableLeftColor(true);
100 g_tyzx_camera->setColorMode(DeepSeaIF::BGRcolor);
101 g_tyzx_camera->setDoIntensityCrop(true);
102 g_tyzx_camera->enable8bitImages(true);
103 if(!g_tyzx_camera->startCapture()){
112 void CvCaptureCAM_TYZX::close()
116 cvReleaseImage( &image );
118 if(g_tyzx_refcount==0){
119 delete g_tyzx_camera;
124 bool CvCaptureCAM_TYZX::grabFrame()
126 return isOpened() && g_tyzx_camera && g_tyzx_camera->grab();
129 bool CvCaptureCAM_TYZX::allocateImage()
134 // assume we want to resize
135 cvReleaseImage(&image);
137 // figure out size depending on index provided
140 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
145 size = cvSize(g_tyzx_camera->zWidth(), g_tyzx_camera->zHeight());
146 depth = IPL_DEPTH_16S;
151 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
156 image = cvCreateImage(size, depth, nch);
160 /// Copy 'grabbed' image into capture buffer and return it.
161 IplImage * CvCaptureCAM_TYZX::retrieveFrame()
163 if(!isOpened() || !g_tyzx_camera) return 0;
165 if(!image && !alocateImage())
168 // copy camera image into buffer.
169 // tempting to reference TYZX memory directly to avoid copying.
173 memcpy(image->imageData, g_tyzx_camera->getRImage(), image->imageSize);
176 memcpy(image->imageData, g_tyzx_camera->getZImage(), image->imageSize);
180 memcpy(image->imageData, g_tyzx_camera->getLImage(), image->imageSize);
187 double CvCaptureCAM_TYZX::getProperty(int property_id)
190 switch(capture->index)
193 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
196 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
199 size = cvSize(g_tyzx_camera->zWidth(), g_tyzx_camera->zHeight());
205 switch( property_id )
207 case CV_CAP_PROP_FRAME_WIDTH:
209 case CV_CAP_PROP_FRAME_HEIGHT:
216 bool CvCaptureCAM_TYZX::setProperty( int, double )
221 CvCapture * cvCreateCameraCapture_TYZX (int index)
223 CvCaptureCAM_TYZX * capture = new CvCaptureCAM_TYZX;
224 if( capture->open(index) )