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 typedef struct CvCaptureCAM_TYZX
55 CvCaptureVTable* vtable;
61 static int icvOpenCAM_TYZX (CvCaptureCAM_TYZX * capture, int wIndex );
62 static int icvSetPropertyCAM_TYZX (CvCaptureCAM_TYZX* capture, int property_id, double value );
63 static void icvCloseCAM_TYZX (CvCaptureCAM_TYZX* capture );
64 static int icvGrabFrameCAM_TYZX (CvCaptureCAM_TYZX* capture );
65 static IplImage * icvRetrieveFrameCAM_TYZX (CvCaptureCAM_TYZX* capture );
66 static double icvGetPropertyCAM_TYZX (CvCaptureCAM_TYZX* capture, int property_id );
67 static int icvSetPropertyCAM_TYZX (CvCaptureCAM_TYZX* capture, int property_id, double value );
69 static CvCaptureVTable captureCAM_TYZX_vtable =
72 (CvCaptureCloseFunc)icvCloseCAM_TYZX,
73 (CvCaptureGrabFrameFunc)icvGrabFrameCAM_TYZX,
74 (CvCaptureRetrieveFrameFunc)icvRetrieveFrameCAM_TYZX,
75 (CvCaptureGetPropertyFunc)icvGetPropertyCAM_TYZX,
76 (CvCaptureSetPropertyFunc)icvSetPropertyCAM_TYZX,
77 (CvCaptureGetDescriptionFunc)0
82 DeepSeaIF * g_tyzx_camera = 0;
83 int g_tyzx_refcount = 0;
85 static int icvOpenCAM_TYZX(CvCaptureCAM_TYZX * capture, int index )
88 g_tyzx_camera = new DeepSeaIF;
89 if(!g_tyzx_camera) return 0;
91 if(!g_tyzx_camera->initializeSettings(NULL)){
96 // set initial sensor mode
97 // TODO is g_tyzx_camera redundant?
98 g_tyzx_camera->setSensorMode(g_tyzx_camera->getSensorMode());
101 g_tyzx_camera->setZUnits((int) 1000);
103 g_tyzx_camera->enableLeftColor(true);
104 g_tyzx_camera->setColorMode(DeepSeaIF::BGRcolor);
105 g_tyzx_camera->setDoIntensityCrop(true);
106 g_tyzx_camera->enable8bitImages(true);
107 if(!g_tyzx_camera->startCapture()){
112 capture->index=index;
116 static void icvCloseCAM_TYZX( CvCaptureCAM_TYZX* capture )
118 if( capture && capture->image )
120 cvReleaseImage( &capture->image );
123 if(g_tyzx_refcount==0){
124 delete g_tyzx_camera;
129 static int icvGrabFrameCAM_TYZX (CvCaptureCAM_TYZX * )
131 return g_tyzx_camera && g_tyzx_camera->grab();
134 static void icvAllocateImageCAM_TYZX (CvCaptureCAM_TYZX * capture)
139 // assume we want to resize
142 cvReleaseImage(&(capture->image));
145 // figure out size depending on index provided
146 switch(capture->index){
148 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
153 size = cvSize(g_tyzx_camera->zWidth(), g_tyzx_camera->zHeight());
154 depth = IPL_DEPTH_16S;
159 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
164 capture->image = cvCreateImage(size, depth, nch);
167 /// Copy 'grabbed' image into capture buffer and return it.
168 static IplImage * icvRetrieveFrameCAM_TYZX (CvCaptureCAM_TYZX * capture)
170 if(!capture || !g_tyzx_camera) return 0;
173 icvAllocateImageCAM_TYZX(capture);
174 if(!capture->image) return 0;
177 // copy camera image into buffer.
178 // tempting to reference TYZX memory directly to avoid copying.
179 switch (capture->index)
182 memcpy(capture->image->imageData, g_tyzx_camera->getRImage(), capture->image->imageSize);
185 memcpy(capture->image->imageData, g_tyzx_camera->getZImage(), capture->image->imageSize);
189 memcpy(capture->image->imageData, g_tyzx_camera->getLImage(), capture->image->imageSize);
193 return capture->image;
196 static double icvGetPropertyCAM_TYZX (CvCaptureCAM_TYZX * capture, int property_id)
199 switch(capture->index)
202 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
205 size = cvSize(g_tyzx_camera->intensityWidth(), g_tyzx_camera->intensityHeight());
208 size = cvSize(g_tyzx_camera->zWidth(), g_tyzx_camera->zHeight());
214 switch( property_id )
216 case CV_CAP_PROP_FRAME_WIDTH:
218 case CV_CAP_PROP_FRAME_HEIGHT:
225 static int icvSetPropertyCAM_TYZX (CvCaptureCAM_TYZX *, int, double )
231 CvCapture * cvCaptureFromCAM_TYZX (int index)
233 CvCaptureCAM_TYZX * capture = (CvCaptureCAM_TYZX*) cvAlloc( sizeof(*capture));
234 memset( capture, 0, sizeof(*capture));
235 capture->vtable = &captureCAM_TYZX_vtable;
237 if (icvOpenCAM_TYZX( capture, index ))
238 return (CvCapture*)capture;
240 cvReleaseCapture( (CvCapture**)&capture );