Digital Image and Video Processing
OpenCV (Open Source Computer Vision)
... Library of classes and methods for real time computer vision algorithms
... Cross Platform FOSS written in C/C++
… More than 3500 Optimized Algorithms
... Primary Interface in C++
... Full Interfaces in Python, Java, MATLAB/Octave in form of APIs
... More than 14 Million Downloads
... More than 47,000 developers community
Features and Application Area
• 2D and 3D feature toolkits
• Egomotion estimation
• Facial recognition system
• Gesture recognition
• Human–computer interaction (HCI)
• Mobile robotics
• Motion understanding
• Object identification
• Segmentation and Recognition
• Stereopsis Stereo vision: depth perception from 2 cameras
• Structure from motion (SFM)
• Motion tracking
• Augmented reality and many others
Support with Programming Languages
• Written and primary interface in C++, but it still retains a less
comprehensive though extensive older C interface.
• Bindings in Python, Java and MATLAB/OCTAVE.
• The API for these interfaces can be found in the online
documentation.
• Wrappers in other languages such as C#, Perl, Ch, and Ruby
have been developed to encourage adoption by a wider
audience.
Statistical Machine Learning Library in OpenCV
• Boosting (meta-algorithm)
• Decision tree learning
• Gradient boosting trees
• Expectation-maximization algorithm
• k-nearest neighbor algorithm
• Naive Bayes classifier
• Artificial neural networks
• Random forest
• Support vector machine (SVM)
– and many others
OpenCV (Open Source Computer Vision)
Platforms Supported
• Windows
Stable Release : 3.3.0
• Android
• Maemo OpenCV is used as the primary vision
• FreeBSD package in ROS (Robot Operating
• OpenBSD System).
• iOS
• BlackBerry Improved CUDA Support for Mobile
Platforms
• Linux
• OS X
Integration with Scilab
Install
--> atomsInstall("scicv")
--> atomsInstall("IPCV")
OR
--> atomsInstall("PATH OF ZIP")
UnInstall
--> atomsRemove("scicv")
--> atomsInstall("IPCV")
WebCam Interfacing with Python
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Image and Video Processing Functions
im=imread(filename);
imwrite(im, filename);
n = aviopen('video.avi');
//get the first 10 frames from the video file
for f=1:10
im = avireadframe(n);
imshow(im);
sleep(500); Appropriate CODEC is
end required for Video
avilistopened() Processing
Implementation XVID,
aviclose(n);
DVIX
Edge Detection
im = imread('lenna2.png');
im = rgb2gray(im);
E = edge(im, 'sobel');
imshow(E);
E = edge(im, 'canny', [0.06, 0.2]);
imshow(E);
E = edge(im, 'sobel', -1);
imshow(mat2gray(E));
Histogram
im = imread('lena.png');
im = rgb2gray(im);
[count, cells]=imhist(im);
[count, cells]=imhist(im, 10);
scf(0); imhist(im, 10, '');
scf(1); imhist(im, 10, 0.5);
scf(2); imhist(im, 10, 'green');
Histogram of Intensity Distributions
-->x=imread('lena.jpg');
-->[p, i]=imhist(x);
-->plot(i,p)
p=pixel count
i= intensity
Image Subtraction
--> a=imread('lenna.png');
--> b=imread('lenna2.png');
--> c=imsubtract(a,b);
--> imshow(c)
Low and Strong Pass Image Filtering
x=imread(‘tree.jpg’); F= 0.04*ones(5,5);
F= y=imfilter(x,F);
imshow(y)
[0 0 0
0.33 0.33 0.33
0 0 0];
y=imfilter(x,F);
imshow(y)
Strong High-Pass Image Filtering
Reading WebCam Images
Read frames from a camera is very similar with from a video file.
The only difference is using camopen nor aviopen. Before using
camera in SIVP, make sure your camera can work well.
n=camopen();
im=avireadframe(n);
imshow(im);
avilistopened();
aviclose();
Creating Video from Images
im = imread('lenna.png');
n = avifile('lenna.avi', [300;300], 30);
for ii=1:200
ims = im(ii:512-ii, ii:512-ii, :);
addframe(n, ims);
end
aviclose(n);
GAURAV KUMAR
Director
Magma Research and Consultancy Services
Ambala Cantt., Haryana, India
Mobile Numbers : +91-9416366178, +91-9034001978
E-mail : [email protected]