/**/ /* This is a standalone program. Pass an image name as a first parameter of the program. Switch between standard and probabilistic Hough transform by changing "#if 1" to "#if 0" and back */ #include < cv.h > #include < highgui.h > #include < math.h > #include < stdio.h > #include < mil.h > // cxcore.lib cv.lib highgui.lib mil.lib milcor.lib milgen.lib milmet2.lib milcor2.lib milmet2d.lib milmet2cl.lib milpul.lib milorion.lib mil1394.lib milvga.lib #define CHECK_EXIT(x) {if(!(x)){printf("Error %s\n",#x);exit(0);}} class CMIL_CV { MIL_ID MilApplication, /**//* Application identifier. */ MilSystem, /**//* System identifier. */ //MilDisplay, /* Display identifier. */ MilDigitizer, /**//* Digitizer identifier. */ MilImageDisp; /**//* Image buffer identifier. */ static void MouseCallback (int event, int x, int y, int flags, void* param) { if(event==CV_EVENT_LBUTTONDOWN)//CV_EVENT_MOUSEMOVE) { IplImage *img=*(IplImage**)param;//为什么直接传param就不行 CHECK_EXIT(CV_IS_IMAGE(img)); CvFont ft=cvFont(2,1); char s[100]; sprintf(s,"%3d,%3d %d",x,y,CV_IMAGE_ELEM(img,BYTE,y,x));; cvPutText(img,s,cvPoint(100,100),&ft,CV_RGB(0,0,0)); printf("%s\n",s); } }public: enum { Mil_CH0=M_CH0, Mil_CH1=M_CH1, }; BOOL MilGetImage(int Channel,IplImage * &dst) { try { MbufClear(MilImageDisp, 0); MdigChannel(MilDigitizer, Channel); MdigGrab(MilDigitizer, MilImageDisp); int w=MbufInquire(MilImageDisp,M_SIZE_X,M_NULL);; int h=MbufInquire(MilImageDisp,M_SIZE_Y,M_NULL);; int band=MbufInquire(MilImageDisp,M_SIZE_BAND,M_NULL);; int pitch=MbufInquire(MilImageDisp,M_PITCH_BYTE,M_NULL);; // IplImage *dst=cvCreateImage(cvSize(w,h),8,band); if(!dst) dst=cvCreateImage(cvSize(w,h),8,band); // CHECK_EXIT(dst->width==w && dst->height==h && dst->nChannels=band); char* p=dst->imageData; MbufGet(MilImageDisp,p); dst->origin = IPL_ORIGIN_TL; //cvFlip(dst,dst,0); } catch() { return FALSE; } return TRUE; }; BOOL MilOpen(char *DCF_NAME) { try { MappAlloc(M_DEFAULT, &MilApplication); MsysAlloc(M_SYSTEM_METEOR_II, M_DEF_SYSTEM_NUM, M_SETUP, &MilSystem); //MdispAlloc(MilSystem, M_DEFAULT, M_DEF_DISPLAY_FORMAT, M_DEFAULT, &MilDisplay); MdigAlloc(MilSystem, M_DEFAULT, DCF_NAME, M_DEFAULT, &MilDigitizer); printf(" Allocate a display buffer, clear it and display it. \n"); MbufAllocColor(MilSystem, MdigInquire(MilDigitizer, M_SIZE_BAND, M_NULL), (long) (MdigInquire(MilDigitizer, M_SIZE_X, M_NULL)), (long) (MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL)), 8L+M_UNSIGNED, M_IMAGE+M_GRAB+M_DISP, &MilImageDisp); MdigControl(MilDigitizer, M_GRAB_MODE, M_SYNCHRONOUS); //must!! MdigControl(MilDigitizer, M_CAMERA_LOCK, M_ENABLE);// MbufClear(MilImageDisp, 0); } catch() { return FALSE; } return TRUE; } BOOL MilClose() { try{ MbufFree(MilImageDisp); MdigFree(MilDigitizer); MsysFree(MilSystem); MappFree(MilApplication); }catch () { return FALSE; } return TRUE; } void Test() { CHECK_EXIT(MilOpen("H:/wqj/project/CMILL_CV/DCF6.dcf")); IplImage *img0=0; //必须初始化为0 IplImage *img1=0; int Image_id=0; cvNamedWindow( "CH0", 1 ); cvNamedWindow( "CH1", 1 ); cvSetMouseCallback( "CH0", MouseCallback,&img0); cvSetMouseCallback( "CH1", MouseCallback,&img1); printf("Press g to save image in current directory.\n"); printf("Press Esc to Exit.\n"); do { //奇怪,抓到的图都是CH0的//--要设置同步 MilGetImage(M_CH0,img0); CHECK_EXIT(img0); //printf("ImageSize %d*%d*%d\n",img0->width,img0->height,img0->nChannels); MilGetImage(M_CH1,img1); CHECK_EXIT(img1); int c=cvWaitKey(100); if(c=='g') { char img_name[100]; sprintf(img_name,"left_%.2d.bmp",Image_id); cvSaveImage(img_name,img0); sprintf(img_name,"right_%.2d.bmp",Image_id); cvSaveImage(img_name,img1); printf("save image %d ok\n",Image_id); Image_id++; } else if(c==27) break; cvShowImage( "CH0", img0 ); cvShowImage( "CH1", img1 ); } while(1); printf("Exit..\n"); CHECK_EXIT(MilClose()); cvReleaseImage(&img0); cvReleaseImage(&img1); }} ; int main( int argc, char ** argv) { CMIL_CV milcv; milcv.Test(); return 0;}