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)
58 /********************* Capturing video from camera via MIL *********************/
62 MIL_ID MilApplication;
64 } g_Mil = {0,0}; //global structure for handling MIL application
66 typedef struct CvCaptureCAM_MIL
68 CvCaptureVTable* vtable;
70 MilSystem, /* System identifier. */
71 MilDisplay, /* Display identifier. */
72 MilDigitizer, /* Digitizer identifier. */
73 MilImage; /* Image buffer identifier. */
78 // Initialize camera input
79 static int icvOpenCAM_MIL( CvCaptureCAM_MIL* capture, int wIndex )
81 if( g_Mil.MilApplication == M_NULL )
83 assert(g_Mil.MilUser == 0);
84 MappAlloc(M_DEFAULT, &(g_Mil.MilApplication) );
89 assert(g_Mil.MilUser>0);
93 int dev_table[16] = { M_DEV0, M_DEV1, M_DEV2, M_DEV3,
94 M_DEV4, M_DEV5, M_DEV6, M_DEV7,
95 M_DEV8, M_DEV9, M_DEV10, M_DEV11,
96 M_DEV12, M_DEV13, M_DEV14, M_DEV15 };
98 //set default window size
103 for( ; wIndex < 16; wIndex++ )
105 MsysAlloc( M_SYSTEM_SETUP, //we use default system,
106 //if this does not work
107 //try to define exact board
108 //e.g.M_SYSTEM_METEOR,M_SYSTEM_METEOR_II...
111 &(capture->MilSystem) );
113 if( capture->MilSystem != M_NULL )
116 if( capture->MilSystem != M_NULL )
118 MdigAlloc(capture->MilSystem,M_DEFAULT,
119 M_CAMERA_SETUP, //default. May be M_NTSC or other
120 M_DEFAULT,&(capture->MilDigitizer));
122 capture->rgb_frame = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3 );
123 MdigControl(capture->MilDigitizer, M_GRAB_SCALE, 1.0 / 2);
125 /*below line enables getting image vertical orientation
126 consistent with VFW but it introduces some image corruption
127 on MeteorII, so we left the image as is*/
128 //MdigControl(capture->MilDigitizer, M_GRAB_DIRECTION_Y, M_REVERSE );
130 capture->MilImage = MbufAllocColor(capture->MilSystem, 3, w, h,
136 return capture->MilSystem != M_NULL;
139 static void icvCloseCAM_MIL( CvCaptureCAM_MIL* capture )
141 if( capture->MilSystem != M_NULL )
143 MdigFree( capture->MilDigitizer );
144 MbufFree( capture->MilImage );
145 MsysFree( capture->MilSystem );
146 cvReleaseImage(&capture->rgb_frame );
147 capture->rgb_frame = 0;
151 MappFree(g_Mil.MilApplication);
153 capture->MilSystem = M_NULL;
154 capture->MilDigitizer = M_NULL;
159 static int icvGrabFrameCAM_MIL( CvCaptureCAM_MIL* capture )
161 if( capture->MilSystem )
163 MdigGrab(capture->MilDigitizer, capture->MilImage);
170 static IplImage* icvRetrieveFrameCAM_MIL( CvCaptureCAM_MIL* capture )
172 MbufGetColor(capture->MilImage, M_BGR24+M_PACKED, M_ALL_BAND, (void*)(capture->rgb_frame->imageData));
173 //make image vertical orientation consistent with VFW
174 //You can find some better way to do this
175 capture->rgb_frame->origin = IPL_ORIGIN_BL;
176 cvFlip(capture->rgb_frame,capture->rgb_frame,0);
177 return capture->rgb_frame;
180 static double icvGetPropertyCAM_MIL( CvCaptureCAM_MIL* capture, int property_id )
182 switch( property_id )
184 case CV_CAP_PROP_FRAME_WIDTH:
185 if( capture->rgb_frame) return capture->rgb_frame->width;
186 case CV_CAP_PROP_FRAME_HEIGHT:
187 if( capture->rgb_frame) return capture->rgb_frame->height;
192 static CvCaptureVTable captureCAM_MIL_vtable =
195 (CvCaptureCloseFunc)icvCloseCAM_MIL,
196 (CvCaptureGrabFrameFunc)icvGrabFrameCAM_MIL,
197 (CvCaptureRetrieveFrameFunc)icvRetrieveFrameCAM_MIL,
198 (CvCaptureGetPropertyFunc)icvGetPropertyCAM_MIL,
199 (CvCaptureSetPropertyFunc)0,
200 (CvCaptureGetDescriptionFunc)0
203 CvCapture* cvCaptureFromCAM_MIL( int index )
205 CvCaptureCAM_MIL* capture = (CvCaptureCAM_MIL*)cvAlloc( sizeof(*capture));
206 memset( capture, 0, sizeof(*capture));
207 capture->vtable = &captureCAM_MIL_vtable;
209 if( icvOpenCAM_MIL( capture, index ))
210 return (CvCapture*)capture;
212 cvReleaseCapture( (CvCapture**)&capture );