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.
46 #pragma warning( disable: 4711 )
47 #pragma comment(lib,"mil.lib")
48 #pragma comment(lib,"milmet2.lib")
51 #if defined WIN64 && defined EM64T && defined _MSC_VER && !defined __ICL
52 #pragma optimize("",off)
55 /********************* Capturing video from camera via MIL *********************/
59 MIL_ID MilApplication;
61 } g_Mil = {0,0}; //global structure for handling MIL application
63 class CvCaptureCAM_MIL : public CvCapture
66 CvCaptureCAM_MIL() { init(); }
67 virtual ~CvCaptureCAM_MIL() { close(); }
69 virtual bool open( int index );
72 virtual double getProperty(int);
73 virtual bool setProperty(int, double) { return false; }
74 virtual bool grabFrame();
75 virtual IplImage* retrieveFrame();
81 MilSystem, /* System identifier. */
82 MilDisplay, /* Display identifier. */
83 MilDigitizer, /* Digitizer identifier. */
84 MilImage; /* Image buffer identifier. */
89 void CvCaptureCAM_MIL::init()
91 MilSystem = MilDisplay = MilDigitizer = MilImage = M_NULL;
95 // Initialize camera input
96 bool CvCaptureCAM_MIL::open( int wIndex )
100 if( g_Mil.MilApplication == M_NULL )
102 assert(g_Mil.MilUser == 0);
103 MappAlloc(M_DEFAULT, &(g_Mil.MilApplication) );
108 assert(g_Mil.MilUser>0);
112 int dev_table[16] = { M_DEV0, M_DEV1, M_DEV2, M_DEV3,
113 M_DEV4, M_DEV5, M_DEV6, M_DEV7,
114 M_DEV8, M_DEV9, M_DEV10, M_DEV11,
115 M_DEV12, M_DEV13, M_DEV14, M_DEV15 };
117 //set default window size
121 for( ; wIndex < 16; wIndex++ )
123 MsysAlloc( M_SYSTEM_SETUP, //we use default system,
124 //if this does not work
125 //try to define exact board
126 //e.g.M_SYSTEM_METEOR,M_SYSTEM_METEOR_II...
131 if( MilSystem != M_NULL )
134 if( MilSystem != M_NULL )
136 MdigAlloc(MilSystem,M_DEFAULT,
137 M_CAMERA_SETUP, //default. May be M_NTSC or other
138 M_DEFAULT,&MilDigitizer);
140 rgb_frame = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3 );
141 MdigControl(MilDigitizer, M_GRAB_SCALE, 1.0 / 2);
143 /*below line enables getting image vertical orientation
144 consistent with VFW but it introduces some image corruption
145 on MeteorII, so we left the image as is*/
146 //MdigControl(MilDigitizer, M_GRAB_DIRECTION_Y, M_REVERSE );
148 MilImage = MbufAllocColor(MilSystem, 3, w, h,
149 8+M_UNSIGNED, M_IMAGE + M_GRAB, M_NULL);
152 return MilSystem != M_NULL;
155 void CvCaptureCAM_MIL::close( CvCaptureCAM_MIL* capture )
157 if( MilSystem != M_NULL )
159 MdigFree( MilDigitizer );
160 MbufFree( MilImage );
161 MsysFree( MilSystem );
162 cvReleaseImage(&rgb_frame );
166 MappFree(g_Mil.MilApplication);
169 MilDigitizer = M_NULL;
174 bool CvCaptureCAM_MIL::grabFrame()
178 MdigGrab(MilDigitizer, MilImage);
185 IplImage* CvCaptureCAM_MIL::retrieveFrame()
187 MbufGetColor(MilImage, M_BGR24+M_PACKED, M_ALL_BAND, (void*)(rgb_frame->imageData));
191 double CvCaptureCAM_MIL::getProperty( int property_id )
193 switch( property_id )
195 case CV_CAP_PROP_FRAME_WIDTH:
196 return rgb_frame ? rgb_frame->width : 0;
197 case CV_CAP_PROP_FRAME_HEIGHT:
198 return rgb_frame ? rgb_frame->height : 0;
203 bool CvCaptureCAM_MIL::setProperty( int, double )
209 CvCapture* cvCreateCameraCapture_MIL( int index )
211 CvCaptureCAM_MIL* capture = new CvCaptureCAM_MIL;
213 if( capture->open( index ))