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); } 480>
μλ νμΈμ. μ΄ λ°©λ²μΌλ‘ 2λ²μ§Έ 체λλ μ½μ μ μκ² μ£ ? OpenCVμμ cvCreateCameraCapture() ν¨μλ‘λ ν 체λλ§ μ½μ μ μλκ²κ°μ΅λλ€.
ReplyDeleteOpenCVμ cvCreateCameraCapture(index) ν¨μμμ indexκ° μΉ΄λ©λΌ μλ²μ λ§νμ§λ§ μ€μ λ‘ λμμ μλμλ κ±Έλ‘ κΈ°μ΅ν©λλ€. μ μμ€μμ λ©λͺ¨λ¦¬ 볡μ¬κ° λ°λ³΅λ¬ΈμΌλ‘ μ²λ¦¬νκ³ μμ΄ μλκ° λλ €μ, μ΄ λΆλΆμ λ°κΏμΌ νλλ° μ κ²½ μΈ μκ°μ΄ μλ€μ.. γ γ λ°©λ¬Έ ν΄ μ£Όμ μ κ°μ¬ν©λλ€.
ReplyDelete