Capture the Ipcamera image of the sea Conway and turn it into an image that OPENCV can handle (i)

Source: Internet
Author: User
Tags error code
Hai Kang wei visual ipcamera image capture


Capture the Ipcamera image and turn it into a OPENCV can be processed iplimage image (i)

Capture the Ipcamera image and turn it into a OPENCV can be processed iplimage image (ii)


Use of the Hai Kang Wei video camera model: ds-2cd4026fwd-(A) (P)


Hai Kang Wei visual ipcamera image capture method has two kinds:

(1) Use the net_dvr_capturejpegpicture_new inside the SDK to carry on the video capture picture

(2) capture real time stream, decode real time stream into YV12, then convert to RGB


In this blog post, I'll introduce the first method first.

The first method, the key is to invoke net_dvr_capturejpegpicture_new this function. The parameters for this function can be found in the SDK and I'll take a screenshot here to illustrate.


This function ret is used to return the size of the image of a parameter, but the function of this parameter is probably not by reference or pointer to pass the parameter, resulting in the return value is always 0 of my initialization, so for the next operation brings a bit of inconvenience- Have to use a large memory to save the image must be able to store the next.

Net_dvr_capturejpegpicture_new This function is to capture and save a single frame of data into a JPEG, stored in a specified memory space. Which is the JPEG in memory. In order to obtain the iplimage image that OPENCV can handle, it must be decoded in memory.

OpenCV the function of decoding in memory is only one: Imdecode, the following figure is a description of Imdecode


The function requires that the BUF must be an array or a vector of type byte. Therefore, you need to convert the JPEG compressed image of the char * type to a storage format.


#include <cstdio> #include <iostream> #include <ctime> #include <Windows.h> #include
HCNetSDK.h "#include" "highgui.h" #include "cv.h" using namespace CV;


using namespace Std;
typedef HWND (WINAPI *procgetconsolewindow) ();

Procgetconsolewindow Getconsolewindow;
	int main (int argc, char * argv[]) {//---------------------------------------//Initialize Net_dvr_init ();
	Setting connection time and reconnection time Net_dvr_setconnecttime (2000, 1);
	
	Net_dvr_setreconnect (10000, true);
	---------------------------------------//Get the console window handle//hmodule hKernel32 = GetModuleHandle ((LPCWSTR) "kernel32");

	
	Getconsolewindow = (Procgetconsolewindow) GetProcAddress (hKernel32, "Getconsolewindow");
	---------------------------------------//Registration device LONG Luserid;
	Net_dvr_deviceinfo_v30 Strudeviceinfo;
	Luserid = Net_dvr_login_v30 ("10.102.7.88", 8000, "admin", "12345", &strudeviceinfo);
		if (Luserid < 0) {printf ("Login error,%d\n", Net_dvr_getlasterror ());
		Net_dvr_cleanup (); Return-1;
	}//---------------------------------------//cvnamedwindow ("Camera", cv_window_autosize);
	iplimage* frame;
	Define JPEG image quality Lpnet_dvr_jpegpara Jpegpara = new Net_dvr_jpegpara;
	jpegpara->wpicquality = 0;
	
	Jpegpara->wpicsize = 9;
	char * Jpeg = new char[200*1024];
	DWORD len = 200*1024;
			
	Lpdword Ret = 0; if (!net_dvr_setcapturepicturemode (Bmp_mode)) {cout<< "Set Capture picture MODE error!"
		<<endl;
	cout<< "The error code is" <<net_dvr_getlasterror () <<endl;
	}//bool capture = Net_dvr_capturejpegpicture (Luserid,1,jpegpara, "1111");
	Vector<char>data (200*1024);
	while (1) {bool capture = net_dvr_capturejpegpicture_new (Luserid,1,jpegpara,jpeg,len,ret);
		if (!capture) {printf ("error:net_dvr_capturejpegpicture_new =%d", Net_dvr_getlasterror ());	
	return-1;

	for (int i=0;i<200*1024;i++) data[i] = Jpeg[i];
	Mat img = Imdecode (Mat (data), 1);
	Imshow ("Camera", IMG);
	
	Waitkey (1); //file * fp = fopen ("3.jpg"),"WB");
	Fwrite (JPEG,1,123*1024,FP);
	
	Fclose (FP);
return 0;
 }

Run this code of course OPENCV configuration can not be less, HCNetSDK.h must also include into the project.

Run this program, you can capture the image, but I calculated the next time, in the call Net_dvr_capturejpegpicture_new (Luserid,1,jpegpara,jpeg,len,ret), when this sentence, spents 300ms, This takes too long to be real-time. However, if there is no demand for real-time, this can be used, good understanding.

*********************************************************************************************
Reprint please indicate the source: http://blog.csdn.net/wanghuiqi2008/article/details/31404571
*********************************************************************************************



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.