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

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);
  printf("Cann't Alloc Buffer\n");
 m_hDig = digAlloc(MV_DEV0);
  printf("Cann't Alloc Digitizer");
 digGrabContinuous(m_hDig, m_hBuf);
 RGB32_T** pixel = (RGB32_T**)bufGetPtr2D(m_hBuf);

 //OpenCV Setting
 IplImage * img = cvCreateImage(cvSize(640,480), 8, 3);

 int color, R, G, B, c; 
  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;

  if( cvWaitKey(10) > 0 )

 //release memory



  1. 양광웅21/3/12 15:36

    안녕하세요. 이 방법으로 2번째 체널도 읽을 수 있겠죠? OpenCV에서 cvCreateCameraCapture() 함수로는 한 체널만 읽을 수 있는것같습니다.

  2. OpenCV의 cvCreateCameraCapture(index) 함수에서 index가 카메라 순번을 말하지만 실제로 동작은 안되었던 걸로 기억합니다. 위 소스에서 메모리 복사가 반복문으로 처리하고 있어 속도가 느려요, 이 부분을 바꿔야 하는데 신경 쓸 시간이 없네요.. ㅎㅎ 방문 해 주셔서 감사합니다.


Post a Comment

Popular posts from this blog

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

OpenCV Stitching example (Stitcher class, Panorama)

AMP dose run on my pc?, AMP(Accelerated Massive Parallelism)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Optical Flow sample source code using OpenCV

Real-time N camera stitching Class.

OpenCV meanShiftFiltering example source code ( cpu: pyrMeanShiftFiltering, gpu:meanShiftFiltering, gpu:meanShiftSegmentation )

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Image warping (using opencv findHomography, warpPerspective)

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)