(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
Opencv
1. CAMERA VISION
IN PYTHON USINGOPENCV
INTRODUCTION
TO
PresentedBy
Ethi$h Kumar Keerthi
17K65A0501
2. List of
Contents
INTRODUCTION
HISTORY
INSTALLATION
READ/OPEN IMAGE
ACCESS WEB CAM
TECHNIQUES
APPLICATIONS
ALTERNATIVES
3. INTRODUCTION
OpenCV (Open source computer vision) is a library of programming functions mainly aimed at real-
time computer vision. “Computer Vision is a field of deep learning that enables machines to see,
identify and process images like humans”.
Computer vision is one of the hottest fields in the industry right now. You can expect plenty of job
openings to come up in the next 2-4 years. The question then is – are you ready to take advantage of
these opportunities?
4. CONT...
Take a moment to ponder this – which applications or products come to your mind when you think of
computer vision? The list is HUGE. We use some of them everyday! Features like unlocking our
phones using face recognition, our smartphone cameras, self-driving cars – computer vision is
everywhere
5. History
Officially launched in 1999 the OpenCV project was initially an Intel Research initiative to advance
CPU-intensive applications, part of a series of projects including real-time ray tracing and 3D display
walls.The main contributors to the project included a number of optimization experts in Intel Russia,
as well as Intel's Performance Library Team. In the early days of OpenCV, the goals of the project
were described as:
Advance vision research by providing not only open but also optimized code for basic vision
infrastructure. No more reinventing the wheel.
Disseminate vision knowledge by providing a common infrastructure that developers could build on,
so that code would be more readily readable and transferable.
Advance vision-based commercial applications by making portable, performance-optimized code
available for free – with a license that did not require code to be open or free itself.
The first alpha version of OpenCV was released to the public at the IEEE Conference on Computer
Vision and Pattern Recognition in 2000, and five betas were released between 2001 and 2005. The
first 1.0 version was released in 2006. A version 1.1 "pre-release" was released in October 2008.
6. CONT...
The second major release of the OpenCV was in October 2009. OpenCV 2 includes major changes to
the C++ interface, aiming at easier, more type-safe patterns, new functions, and better
implementations for existing ones in terms of performance (especially on multi-core systems).
Official releases now occur every six months and development is now done by an independent
Russian team supported by commercial corporations.In August 2012, support for OpenCV was taken
over by a non-profit foundation OpenCV.org, which maintains a developer.On May 2016, Intel signed
an agreement to acquire Itseez, a leading developer of OpenCV
OpenCV runs on the following desktop operating systems:
Windows, Linux, macOS, FreeBSD, NetBSD, OpenBSD.
OpenCV runs on the following mobile operating systems: Android, iOS, Maemo,BlackBerry 10. The
user can get official releases from SourceForge or take the latest sources from GitHub.
7. Before going to our topic first we have to pay our sincere attention to PYTHON 2
So It's time to change our code to PYTHON 3
8. INSTALLATION
windows
• Python 3+ https://www.python.org/downloads/
• After installing the python and set path and install pip
• After installing pip, Open CMD as Adminstrator
•we need to install Frequently used Libraries before we install opencv : Numpy, Matplotlib, Scipy
• All we need to just type these commands
>>>pip install numpy
>>>pip install matplotlib
>>>pip install scipy
9. INSTALLATION
• Or try Anaconda (Python 3+ popular libraries) https://www.continuum.io/downloads
• Download latest OpenCV release from sourceforge site and click to extract it
(http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.6/OpenCV-2.4.6.0.exe/download)
• Goto opencv/build/python/3.5 folder(your respective version folder).
• Copy cv2.pyd to C:/Python35/lib/site-packeges.
• Open Python IDLE and type following codes in Python terminal.
>>>import cv2
•If cv2 imported successfully than your installation is completed
10. INSTALLATION
MAC
• Python 3.5 or 3.6 or Anaconda https://www.python.org/downloads/
https://www.continuum.io/downloads
• Frequently used Libraries : Numpy, Matplotlib, Scipy in Terminals : pip3 install –U numpy scipy
matplotlib (for Python 3.X)
• Download openCV http://opencv.org/downloads.html
• Install Xcode https://developer.apple.com/xcode/
• Install Cmake https://cmake.org/download/
• Build openCV for Python http://luigolas.com/blog/2014/09/15/install-opencv3-with- python-3-mac-
osx/
11. Read/Show Image
• In these we just interact with the opencv by giving
image as input
Code-
import cv2
img = cv2.imread('C:/Users/91741/Desktop/projects
python/seminar ppt/ammababoi.jpg')
cv2.imshow('sample image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output
12. Code
import cv2
import numpy as np
cap = cv2.VideoCapture('chaplin.mp4')
if (cap.isOpened()== False):
print("Error opening video stream or file")
while(cap.isOpened()):
ret, frame = cap.read()
if ret == True:
cv2.imshow('Frame',frame)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.destroyAllWindows()
Read/Show Video
• In these we just interact with the opencv by giving Video as
input
• In these we need to use NUMPY package
13. ACCESS WEB CAM
• In opencv main component is camera so now we look at the simple code for open webcam using
python code
>>> import cv2
cap = cv2.VideoCapture(0)
if not cap.isOpened():
raise IOError("Cannot open webcam")
while True:
ret, frame = cap.read()
frame = cv2.resize(frame, None, fx=1.5, fy=1.5, interpolation=cv2.INTER_AREA)
cv2.imshow('Input', frame)
c = cv2.waitKey(1)
if c == 27:
break
cap.release()
cv2.destroyAllWindows()
14. TECHNIQUES AND METHODS
• In opencv we have so many techniques some of them are
Changing Color Spaces
Resizing Images
Image Rotation
Image Translation
Simple Image Thresholding
Adaptive Thresholding
Image Segmentation (Watershed Algorithm)
Bitwise Operations
Edge Detection
Image Filtering
Image Contours
Here we discuss about some frequently used methods
15. CANNY EDGE DETECTION
The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a
wide range of edges in images. It was developed by John F. Canny in 1986. Canny also produced a
computational theory of edge detection explaining why the technique works.
Canny edge detection is a technique to extract useful structural information from different vision
objects and dramatically reduce the amount of data to be processed. It has been widely applied in
various computer vision systems. Canny has found that the requirements for the application of edge
detection on diverse vision systems are relatively similar. Thus, an edge detection solution to address
these requirements can be implemented in a wide range of situations. The general criteria for edge
detection include:
Detection of edge with low error rate, which means that the detection should accurately catch as many
edges shown in the image as possible
16. CONT...
The edge point detected from the operator should accurately localize on the center of the edge.
A given edge in the image should only be marked once, and where possible, image noise should
not create false edges.
To satisfy these requirements Canny used the calculus of variations – a technique which finds the
function which optimizes a given functional. The optimal function in Canny's detector is described
by the sum of four exponential terms, but it can be approximated by the first derivative of a
Gaussian.
Among the edge detection methods developed so far, Canny edge detection algorithm is one of the
most strictly defined methods that provides good and reliable detection. Owing to its optimality to
meet with the three criteria for edge detection and the simplicity of process for implementation, it
became one of the most popular algorithms for edge detection.
17. Code For Canny Edge Detection for Image
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('Brahmi.jpg',0)
edges = cv2.Canny(img,100,200)
plt.subplot(121),plt.imshow(img,cmap = 'gray')
plt.title('Original Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(edges,cmap = 'gray')
plt.title('Canny Edge Image'), plt.xticks([]), plt.yticks([])
plt.show()
Output
18. Code For Canny Edge Detection for Live Video
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_red = np.array([30,150,50])
upper_red = np.array([255,255,180])
mask = cv2.inRange(hsv, lower_red, upper_red)
res = cv2.bitwise_and(frame,frame, mask= mask)
laplacian = cv2.Laplacian(frame,cv2.CV_64F)
sobelx = cv2.Sobel(frame,cv2.CV_64F,1,0,ksize=5)
sobely = cv2.Sobel(frame,cv2.CV_64F,0,1,ksize=5)
cv2.imshow('Original',frame)
cv2.imshow('Mask',mask)
cv2.imshow('laplacian',laplacian)
cv2.imshow('sobelx',sobelx)
cv2.imshow('sobely',sobely)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
cap.release()
19. Image Filtering
In order to filter you have a few options.
Generally, you are probably going to convert
your colors to HSV, which is "Hue
Saturation Value." This can help you actually
pinpoint a more specific color, based on hue
and saturation ranges, with a variance of
value, for example. If you wanted, you could
actually produce filters based on BGR
values, but this would be a bit more difficult.
If you're having a hard time visualizing HSV,
don't feel silly, check out the Wikipedia page
on HSV, there is a very useful graphic there
for you to visualize it. Hue for color,
saturation for the strength of the color, and
value for light is how I would best describe
it personally. Now let's hop in.
Code For Image Filtering
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_red = np.array([30,150,50])
upper_red = np.array([255,255,180])
mask = cv2.inRange(hsv, lower_red, upper_red)
res = cv2.bitwise_and(frame,frame, mask= mask)
cv2.imshow('frame',frame)
cv2.imshow('mask',mask)
cv2.imshow('res',res)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
cap.release()
21. APPLICATIONS
OpenCV is being used for a very wide range of applications which include:
• Road Lane Detection Image Processing
• Street view image stitching
• Automated inspection and surveillance
• Robot and driver-less car navigation and control
• Medical image analysis
• Video/image search and retrieval
• Movies - 3D structure from motion
• Interactive art installations
22. ALTERNATIVES
Like Opencv we have different alternative tools/Libraries some of them are
• SimpleCV
• Accord.NET Framework
• ImageUltimate
• BoofCV
• libdwt
• FastCV Computer Vision
• LeptonicaSharp
23. END WORDS
OpenCV is truly an all emcompassing library for computer vision tasks. I just tried out all the
above codes on my machine – the best way to learn computer vision is by applying it on your
own. I encourage you to build your own applications and experiment with OpenCV as much as
you can if you intrested.
OpenCV is continually adding new modules for latest algorithms from Machine learning, do
check out their Github repository and get familiar with implementation.