Vous êtes sur la page 1sur 6

“Understanding on Open CV ”

Submitted By,
R.Rajeswari-2015504571
B.Merlin Mercy-2015504563
A.Azarudeen-2015504017

Submitted to,
Mrs.G.Sumithra,
Asst.Professor,
Department of Electronics Engineering

Submission Date:24/12/2018
Introduction:
OpenCV is a cross-platform library using which we can develop real-
time computer vision applications. It mainly focuses on image processing, video
capture and analysis including features like face detection and object detection.
Computer Vision can be defined as a discipline that explains how to reconstruct,
interrupt, and understand a 3D scene from its 2D images, in terms of the
properties of the structure present in the scene. It deals with modeling and
replicating human vision using computer software and hardware.
Computer Vision overlaps significantly with the following fields −
 Image Processing − It focuses on image manipulation.
 Pattern Recognition − It explains various techniques to classify patterns.
 Photogrammetry − It is concerned with obtaining accurate measurements
from images.

Install OpenCV C++ with Visual Studio on Windows PC:

Step 1: Install Visual Studio 2017


Download the Visual Studio Community from the Microsoft official
website.Then install it by customizing it and clicking next.

Step 2: Install OpenCV


Download latest OpenCV package for Windows from opencv official page.
Extract and install it.

Step 3: Include OpenCV to system path


 Go to Advanced System Settings > Environment Variables >System
Variables > Path.
 Click on ‘Edit’. Now, click ‘New’ to add new environment variable.
 Copy and paste the path of bin folder inside OpenCV package. The path
will look similar to C:\opencv\build\x64\vc14\bin.
 Press OK and exit the environment variable dialog by clicking OK again.

Step 4: Create a new empty console application


 Open up Visual Studio. Create a new project as a Win32 Console
application using Visual C++. Make the Empty project and Finish.
 Add a new .cpp file inside the Source Files. This will open up the newly
created cpp file in the editor.
 Type the code inside the editor and save the source file.
 If image is included in the code , Save the image inside your project
location.

Step 5: Include OpenCV in Visual Studio


Till now, the opencv c++ functions & variables are not identifiable by visual
studio. This is due to the fact that we haven’t linked opencv with visual studio.
If you use x64 version ,toggle the Debug environment to x64.

 In the Project Menu ,select Properties.


 Inside Properties of the project, choose C/C++ -> General. Copy the path
to include folder of opencv and paste it inside Additional Include
Directories. The path will look similar to C:\opencv\build\include. Then,
click Apply.
 Go to linker > General. Copy the path to folder containing opencv lib files
and paste it inside Additional Library Directories. The path will look
similar to C:\opencv\build\x64\vc14\lib. Then, click Apply.
 Go to Input. Edit Additional Dependencies and paste the .lib file’s name.
Choose the .lib file according to your configuration. For debug mode, the
file ends with ‘d’, e. g., opencv_world341d.lib.. Then, click Apply.
 Exit the Properties by clicking OK.
edit the properties, using Configuration and Platform same as in which the
source file is saved.

Step 6: Test the code


 Build the code by clicking Build Solution or just pressing Ctrl+Shift+B on
keyboard. This should end up with output “Build Succeeded”.
 Run the Local Windows Debugger. This should display the image on a new
screen. Making any keypress will make the make window close.
This signifies that you made success to install OpenCV C++ with Visual
Studio on your Windows PC.
A small Program is written to convert the RGB image to Binary image in C++
Visual Studio.
Converting RGB image to binary image in Open CV:
The image of a crocodile is taken from the video taken by drone in Australia.
Source Code:
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"
#include "pch.h"
#include "opencv2/opencv.hpp"

using namespace cv;


using namespace std;

int main()
{

Mat image;
image = imread("croc1.png", CV_LOAD_IMAGE_COLOR);

if (!image.data)
{
cout << "Could not open or find the image" << std::endl;
return -1;
}

// Create a new matrix to hold the gray image


Mat gray;

// convert RGB image to gray


cvtColor(image, gray, CV_BGR2GRAY);

namedWindow("Display window", CV_WINDOW_AUTOSIZE);


imshow("Display window", image);

//namedWindow("grey window", CV_WINDOW_AUTOSIZE);


//imshow("grey window", gray);

Mat dst;

// Set threshold and maxValue


double thresh = 128;
double maxValue = 255;

// Binary Threshold
threshold(gray, dst, thresh, maxValue, THRESH_BINARY);
//threshold(gray , dst, thresh, maxValue, THRESH_BINARY_INV);
namedWindow("Result window", CV_WINDOW_AUTOSIZE);
imshow("Result window", dst);

waitKey(0);
return 0;
}

Code Explanation:
 The input image is red using imread function and stored in a Matrix called
image.
 Then the image is converted to Gray scale using cvtColor function and it is
stored in gray Matrix.
 Then the Gray image is converted to Binary image by setting appropriate
threshold based on image.
 Display the Input and Output images.

RGB Image: Binary Image:

0
Conclusion:
In this short time period,We learnt about characteristics ,behaviour and
features of the crocodile,Human-crocodile conflict,a lot of algorithms used in
image processing for edge detection ,edge linking,corner detector etc,a lot of new
concepts like feature extraction,classifier,pattern recognition,support vector
machines,fuzzy logic,neural networks etc.We got introduced to the new
environment –Open CV and learnt and installed Open CV and done some small
programs in that and got familiar with that platform.

Vous aimerez peut-être aussi