"Vision-Camera 1" OpenCV Call Industrial camera (USB interface and GigE interface)

Source: Internet
Author: User
"Computer vision" OPENCV calls industrial cameras (USB interface and GigE interface)
The first time to write a blog in csdn, there is no place please advise, Welcome to Exchange Comments Message
The development environment is WIN7+VS2010+OPENCV (mainly operating system Windows,linux not yet tried) 1 Code OPENCV Open USB and GigE cameras directly 1.1 Three different code forms with the same principleMethod One
---------------------------------"header file, namespace contains part"----------------------------//Description: Contains the header file and namespace used by the program//---------- ---------------------------------------------------------------------------------------//#include "opencv2/ Video/tracking.hpp "#include" StdAfx.h "#include" opencv2/imgproc/imgproc.hpp "#include" opencv2/highgui/highgui.hpp
"#include <iostream> #include <ctype.h> using namespace CV;

using namespace Std; -----------------------------------"global variable Declaration"-----------------------------------------//Description: Declaring global variables//-----------
------Mat Image;
Rect selection; -----------------------------------the main () function--------------------------------------------//Description: The entry function for the console application,
Our program starts here//-------------------------------------------------------------------------------------------------
	int main () {videocapture cap;
	Rect Trackwindow; Cap.open (0);//0 Default-camera, if using a notebook camera, 1--is USB limited, no USB on the network, if using a notebook;-1 Select multiple Camera interface if (!cap.isopened ()) {cout << "cannot initialize camera \ n"
	; } Namedwindow ( "Camshift Demo", 0);
	Mat frame;
	BOOL paused = false;
	Method 1//for (;;)
	{//if (!paused)//{//Cap >> frame;
	if (Frame.empty ())//break;			
	}//Imshow ("Camshift Demo", frame);
			}////Method 2 while (1) {if (!paused) {cap >> frame;
		if (Frame.empty ()) break;	 } imshow ("Camshift Demo", frame);  Displays the current frame Waitkey (30);
Delay 30ms} return 0;
 }



Method Two
Camera2.cpp: Defines the entry point of the console application.
//
#include "stdafx.h"
#include <opencv2\opencv.hpp>  
using namespace CV;  

-----------------------------------"Main () function"--------------------------------------------
//		Description: The entry function of the console application, our program starts here
//----------------------------------------------------------------------------- --------------------
int main ()  
{  
	//"1" reads video from the camera
	videocapture capture (1);
	0 Default-camera, if using a notebook camera, 1--is USB limited, no USB on the network, if using a notebook;-1 Select multiple camera interface
	//"2" loop to display each frame
	while (1)  
	{  
		Mat frame;  Defines a mat variable that stores the image for each frame
		capture>>frame;  Reads the current frame
	   if (Frame.empty ())
			continue;
		Imshow ("read video", frame);  Displays the current frame
		waitkey (+);  Delay 30ms
	}  
	return 0;     
}  

Method Three

Camera3.cpp: Defines the entry point of the console application.
//

#include "stdafx.h"
#include <opencv2\opencv.hpp>  
using namespace CV;  
using namespace std;
int main ()  
{  
	videocapture capture (0);
	0 Default-camera, if using a notebook camera, 1--is USB limited, no USB on the network, if using a notebook;-1 Select multiple camera interfaces while

	(1)
	{
		Mat frame;
		Capture >> frame;
		if (! Frame.empty ())
		{
						imshow ("final result", frame);
		}
		else
		cout << "can not";//The last frame of processing
		waitkey ();
	}
	return (0);
}

(PS videocapture Capture (1);//1--USB is limited, no USB on the network, if using a notebook;-1 select multiple camera interfaces; 0 Default-camera, if using a laptop camera)

Actually 0,1 ... Device ID number see WIN7 under Device Manager-image devices, corresponding search quotes , starting from 0.



Introduction to 1.2 videocapture Reference document

2 Common camera Industry notes 2.1 According to the camera interface is divided into USB interface and GigE interface. (The PS1 laptop thinks that there is no interface, the call to see the ID number, usually 0,) 2.2 Depending on the need to install the relevant drive is divided into belt drive and free drive. (PS two development (OPENCV call) installation of the relevant driver reference SDK, in fact, under the Win7 Device Manager can display the general can be called directly)
Now post the main industrial cameras used by bloggers:



To pay off a deficiency or error.
(PS videocapture Capture (1);//1--USB is limited, no USB on the network, if using a notebook;-1 select multiple camera interfaces; 0 Default-camera, if using a laptop camera)

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.