2/29/2012

To convert from MyVisionUSB to OpenCV and Display (source code)



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 comments:

  1. μ–‘κ΄‘μ›…21/3/12 15:36

    μ•ˆλ…•ν•˜μ„Έμš”. 이 λ°©λ²•μœΌλ‘œ 2번째 체널도 읽을 수 있겠죠? OpenCVμ—μ„œ cvCreateCameraCapture() ν•¨μˆ˜λ‘œλŠ” ν•œ μ²΄λ„λ§Œ 읽을 수 μžˆλŠ”κ²ƒκ°™μŠ΅λ‹ˆλ‹€.

    ReplyDelete
  2. OpenCV의 cvCreateCameraCapture(index) ν•¨μˆ˜μ—μ„œ indexκ°€ 카메라 μˆœλ²ˆμ„ λ§ν•˜μ§€λ§Œ μ‹€μ œλ‘œ λ™μž‘μ€ μ•ˆλ˜μ—ˆλ˜ 걸둜 κΈ°μ–΅ν•©λ‹ˆλ‹€. μœ„ μ†ŒμŠ€μ—μ„œ λ©”λͺ¨λ¦¬ 볡사가 반볡문으둜 μ²˜λ¦¬ν•˜κ³  μžˆμ–΄ 속도가 λŠλ €μš”, 이 뢀뢄을 λ°”κΏ”μ•Ό ν•˜λŠ”λ° μ‹ κ²½ μ“Έ μ‹œκ°„μ΄ μ—†λ„€μš”.. γ…Žγ…Ž λ°©λ¬Έ ν•΄ μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€.

    ReplyDelete