Micro-Vision V411 acquisition card obtains image OpenCV in X64 environment

Source: Internet
Author: User
Tags bool

A few days ago bought a micro-vision V411 acquisition card, initially want to use OPENCV to directly collect video stream, using the teacher's multi-camera acquisition program. Unfortunately, no image is collected, simply use the SDK provided by micro-vision to develop.

SDK Scenario One: Mv_capturesingle

	Dcardnum = Mv_getdevicenumber ()
	HWND Hwnd=getsafehwnd ();

	DWORD i;
        for (i=0;i<dcardnum;i++)
	{
		Hdvchdl[i]=mv_opendevice (i, TRUE);
		Mv_setdeviceparameter (Hdvchdl[i], disp_whnd, (DWORD) HWND);	Sets the image display window handle
		mv_setdeviceparameter (hdvchdl[i],garb_bitdescribe,data_co_rgb24);  Set to 24-bit acquisition

		Mv_setdeviceparameter (Hdvchdl[i], disp_left, i%2*460);
		Mv_setdeviceparameter (Hdvchdl[i], disp_top, (I/2) *345);

		Mv_setdeviceparameter (Hdvchdl[i], garb_in_width, 768);
		Mv_setdeviceparameter (Hdvchdl[i], garb_width, 768);
		Mv_setdeviceparameter (Hdvchdl[i], disp_width, 460);

		Mv_setdeviceparameter (Hdvchdl[i], garb_in_height, 288);
		Mv_setdeviceparameter (Hdvchdl[i], garb_height, 288);
		Mv_setdeviceparameter (Hdvchdl[i], disp_height, 345);

		Mv_operatedevice (Hdvchdl[i], mvrun);
	}
This line is important to set the 24-bit acquisition of the line, it specifies the data collected card transmission, here I set the
    Data_co_rgb24
Followed by our protagonist: OpenCV

		For (DWORD i=0;i<num;i++)	//num
		{
			mv_setdeviceparameter (hdvchdl[i], Set_garbimageinfo, (DWORD) & Info[i]);	Get information about the current image

			PVOID PBuf = malloc (Info[i]. Length);
			Capture an image
			ptr[i] = Mv_capturesingle (Hdvchdl[i], FALSE, Pbuf,info[i]. Length, &info[i]);
			sprintf (char *) &filename, "card%d_%d", i+1, FileNum);
			if (i = = 0)
			{
				Cv::mat frame (info[i]. Heigth,info[i]. WIDTH,CV_8UC3);
				Frame.data = static_cast<uchar*> (Ptr[i]);
				Cv::resize (Frame,frame,cv::size (320,240));
				Cv::imshow ("Mat0", frame);
				if (cv::waitkey () = =) break;
				Cv::imwrite ("1.jpg", frame);
			}
<span style= "font-family:arial, Helvetica, Sans-serif;" >						</span><span style= "font-family:arial, Helvetica, Sans-serif;" >free (PBUF);</span>
<span style= "White-space:pre" >		</span>   }
			
The important thing is this line:
Cv::mat frame (Info[i]. Heigth,info[i]. WIDTH,CV_8UC3);

This method is easy to implement, but the acquisition rate is too slow, which affects post-processing.


SDK Scenario Two: Mv_setcallback

The important thing is two lines, the other is consistent with the method, remember to comment out the image display code (GARB_).

		Mv_setdeviceparameter (Hdvchdl[i], grab_bitdescribe, data_co_rgb24);
		Mv_setcallback (Hdvchdl[i], func[i], this, before_process)

BOOL WINAPI CALLBACKFUNCT1 (PVOID pData, Pmv_imageinfo pimageinfo, PVOID puserdata, ULONG Index);
BOOL WINAPI CALLBACKFUNCT1 (PVOID pData, Pmv_imageinfo pimageinfo, PVOID puserdata, ULONG Index)
{    
	if (((CMUTIFAC erecdlg*) (puserdata)->bdvccpt)
	{
	   if (((cmutifacerecdlg*) puserdata)->bdvc1cpt)
	   {
		   memcpy (( cmutifacerecdlg*) puserdata)->pdata1,pdata,768*576*4);
		((cmutifacerecdlg*) puserdata)->bdvc1cpt=false;
	   }
	}

	return TRUE;
OpenCV Capture and display

        Iplimage M_frame;
	Cvvimage M_cvvimage; 
	Mv_imageinfo info;

	BDVCCPT  = TRUE;
	BDVC1CPT = TRUE;

	Mv_setdeviceparameter (Hdvchdl[0],set_garbimageinfo, (DWORD) &info);	
	Cv::mat FRAME (info. Heigth,info. WIDTH,CV_8UC3);
	Frame.data = static_cast<uchar*> (pData1);
	
	M_frame = Frame;
	M_cvvimage.copyof (&m_frame,1);				Copy the frame image    
        M_cvvimage.drawtohdc (HDC, &rect);			Display to the device in a rectangular box

If you want to do the video stream display, this line of code must not forget, the reason to look at the callback function.
	BDVCCPT  = TRUE;
	BDVC1CPT = TRUE;

The acquisition rate of the two methods is close to the sampling frame rate of the camera, the code is written in a chaotic way, for reference only. Most of the code refers to the SDK and demo provided by the micro-view.

This article is for reference only, if reproduced please indicate the source.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.