This is sample source to convert MyVision USB to OpenCV.
You need MyVision USB library to handle image buffer.
This link is included "MVULib.lib, MVULib.dll, MyVision.h".
Lib Download
And you can download driver file on the http://withrobot.com/157.
The below source is sample code to convert MyVision USB to OpenCV.
This code don't use memcpy. so it is little bit slow. The code needs upgrade to speed up.
#include < stdio.h > #include < cv.h > #include < cxcore.h > #include < highgui.h > #include < cvaux.h > #include "MyVision.h" using namespace std; void main() { ////////////////////////////////////////////////// //MyVisionUSB Setting HBUF m_hBuf; HDIG m_hDig; char* ver = sysGetLibVer(); if(strcmp(ver, MV_LIB_VER) != 0) printf("incorrect library version\n"); m_hBuf = bufAlloc(640,480, MV_RGB32 | MV_DOUBLE); if(!m_hBuf) printf("Cann't Alloc Buffer\n"); m_hDig = digAlloc(MV_DEV0); if(!m_hDig) printf("Cann't Alloc Digitizer"); digGrabContinuous(m_hDig, m_hBuf); RGB32_T** pixel = (RGB32_T**)bufGetPtr2D(m_hBuf); //////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// //OpenCV Setting cvNamedWindow("MyVisionUSBtoOpenCV",CV_WINDOW_AUTOSIZE); IplImage * img = cvCreateImage(cvSize(640,480), 8, 3); int color, R, G, B, c; while(1) { digGrabWait(m_hDig, MV_FIELD_EVEN); for(int i=0; i<480 color="color" for="for" i="i" int="int" j="j" r="RGB32_TO_R(color);" xff0000="xff0000">>16); G = RGB32_TO_G(color); // (((color)&0x00ff00)>>8); B = RGB32_TO_B(color); // (((color)&0x0000ff)); img->imageData[i*img->widthStep+j*3+0] = B; img->imageData[i*img->widthStep+j*3+1] = G; img->imageData[i*img->widthStep+j*3+2] = R; } } cvShowImage("MyVisionUSBtoOpenCV",img); if( cvWaitKey(10) > 0 ) break; } ////////////////////////////////////////////////////////////////////////// //release memory cvReleaseImage(&img); cvDestroyAllWindows(); // digHalt(m_hDig); digFree(m_hDig); bufFree(m_hBuf); }
안녕하세요. 이 방법으로 2번째 체널도 읽을 수 있겠죠? OpenCV에서 cvCreateCameraCapture() 함수로는 한 체널만 읽을 수 있는것같습니다.
ReplyDeleteOpenCV의 cvCreateCameraCapture(index) 함수에서 index가 카메라 순번을 말하지만 실제로 동작은 안되었던 걸로 기억합니다. 위 소스에서 메모리 복사가 반복문으로 처리하고 있어 속도가 느려요, 이 부분을 바꿔야 하는데 신경 쓸 시간이 없네요.. ㅎㅎ 방문 해 주셔서 감사합니다.
ReplyDelete