Use OpenCV + vs2013 to turn on the computer camera

Source: Internet
Author: User
Tags win32

A few days ago with Java JMF to open the camera, now I use OPENCV to open the camera. Here is the specifics of the operation

1. Download and install OpenCV

Download the OpenCV version of Windows opencv.org on the official website. (i downloaded the opencv-3.1.0.exe), download after the installation of automatic decompression, choose the installation location on the line.

2. Configure Environment variables

Computer > Right-click Properties > Advanced system Settings > Environment variables > System Variables

Path under Path to add OpenCV such as: ... opencv\build\x64\vc12\bin;

OPENCV 3.1.0 version only x64, here VC12 = vs2013, according to their own installed VS version to choose

3. Project includes directory configuration

Open vs 2013, File > New > Project > Visual C + + >WIN32 Console Application

Click the new project you just created right > Add > New Item


In View > Other Windows > Open Property Manager

Click Project->debug| Win32->microsoft.cpp.win32.user (Right-click Property, or Double-tap) to open the Properties page.

When the Properties page is opened, it is configured. The first is in

A General properties > VC + + Directories > include directories

Add OpenCV in the installation directory ... \opencv\bulid\include

Two General properties > VC + + directory > library directory

Add .... opencv\build\x64\vc10\lib

Three Common Properties > Linker > Input > Additional dependencies

Opencv_world310d.lib

If it appears at compile time; Module machine type ' X86 ' conflicts with Target machine type ' x64 '

Workaround:

Click on Project Right > Properties > select Platform as x64> Configuration Manager > Active solution Platform Select X64 (no new) > then in Connector > Advanced > Target computer (MachineX64)

Sometimes you need to restart your computer to take effect when configured

Here's the code to open the camera:

Overall idea:

1) Add the Include file OpenCV

2) Create an object to get the video stream

3) Create a window to display the captured video stream

4) If you close, release the object that gets the video stream

#include <opencv2\core\core.hpp>

#include <opencv2\highgui\highgui.hpp>

#include <opencv2\opencv.hpp>

Using namespace cv;//namespace

int main ()

{

Videocapture Capture (0);//Create Videocapture Object

if (!capture.isopened ())//To determine whether to turn on the camera, open isopened return ture

return 1;

BOOL Stop (FALSE);//define a variable to stop the loop

Mat frame;//is used to store read sequences of video, hosting images for each frame, and the mat class is a data structure used to hold images and other matrices

Namedwindow ("Camera");//Create a window that displays the window for each frame

while (!stop)

{

if (!capture.read (frame))//Interrupt if no read is reached

{

Break

}

Imshow ("Camera", frame);//normal display, fill the captured video into the window

char C = cvwaitkey (33);

if (c = =) break; Use empty spacebar to stop ASCII to 32

}

Capture.release ();//Release

}



For JMF   and OPENCV to open the camera, both of these methods I tried, for both of them I said some of my ideas, in the absence of this project, I think very simple, but the fact seems not so, because there is no clue, everything is looking for information on the Internet, Find a lot of information, and found that many can not be used, that time only felt difficult. But fortunately, I still found a solution. Both of the environment installation configuration is more troublesome. That's what I think. OpenCV feels better for JMF, and the code is cleaner and clearer.

Related Article

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.