2. Outline
●
Overview and practical issues.
●
A selection of OpenCV functionality:
–
–
Object classification and tracking
–
●
Image enhancement
Face detection and recognition
Conclusion and further resources.
4. Overview: License
●
BSD Licensed (free and open source)
●
May be used in commercial software.
●
No requirement to publish the source!
●
Must acknowledge OpenCV was used in the
documentation by including its copyright notice.
Note: There is a C#/.NET wrapper for OpenCV
called “Emgu CV” that may be commercially
licensed.
5. Overview: Patents
●
Note: A couple of algorithms (SIFT and SURF)
that are implemented are patented.
–
You can't accidentally use them because they are in
a separate module called “nonfree”.
6. Overview: Users
●
Stitching street-view images together,
●
Detecting intrusions in surveillance video in Israel
●
Detection of swimming pool drowning accidents in
Europe
9. Overview: Installation
●
Ubuntu VM:
–
●
sudo apt-get install libopencv-dev
Windows:
–
Download latest version from http://opencv.org/
For Python:
●
●
●
Also install Python from http://www.python.org/
Install numpy module
Copy the “cv2” module from OpenCV to
C:Python27Libsite-packages
15. Python: Display an image file
import cv2
image = cv2.imread("lena.bmp");
if image.empty():
print "Could not load image"
exit(1)
cv2.namedWindow("Image")
cv2.imshow("Image", image)
cv2.waitKey()
Similar structure
and naming as C++
version means
Python is good for
prototyping.
16. Video from IP camera w/ RTSP!
#include <opencv/cxcore.h>
#include <opencv/highgui.h>
int main(int argc, char* argv[])
{
cv::Ptr<CvCapture> capture = cvCaptureFromFile(
"rtsp://admin:admin@10.10.32.33/video");
cv::namedWindow("Frame");
for (;;)
{
cv::Mat frame = cvQueryFrame(capture);
cv::imshow("Frame", frame);
if (cv::waitKey(1) >= 0)
break;
}
return 0;
}
Network comm.,
RTSP protocol, etc.
is all handled for you
so all you have to do
is process each
frame as an image
(a cv::Mat object).
17. A Selection of Functionality
●
Image enhancement
–
●
Noise reduction, local contrast enhancement
Object classification and tracking
–
–
●
Track the paths that objects take in a scene
Differentiating between cars and trucks
Face detection and recognition
–
Identify faces seen in images or video.
18. Image Enhancement
Many many algorithms. Here are a few:
●
●
●
Deconvolution – used to reduce focus blur or
motion blur where the motion is known.
Unsharp masking – increases sharpness and
local contrast (like WDR)
Histogram equalization – stretches contrast
and somewhat corrects for over- or underexposure.
21. Image Enhancement: Demo!
●
Deconvolution – Can also be used for poor
camera focus, but the parameters of the blur
must be estimated in advance.
Generated using OpenCV example:
/opencv/samples/python2/deconvolution.py
24. Object detection and tracking
●
Foreground/background segmentation –
identify objects moving in a scene.
–
●
Histogram backprojection – identify objects by
their colour (even if they're not moving).
–
●
cv::BackgroundSubtractorMOG2
cv::calcBackProject()
Camshift tracking – track objects by their colour.
–
cv::CamShift
26. Face detection and recognition
●
Detection:
–
–
●
Haar cascade – detect faces by identifying
adjacent light and dark regions.
cv::CascadeClassifier
Recognition:
–
Eigenfaces classifier – for facial recognition
–
cv::FaceRecognizer
27. Face detection: C++
cv::CascadeClassifier profileFaceCascade;
profileFaceCascade.load("haarcascade_profileface.xml");
std::vector<cv::Rect> faceRects;
profileFaceCascade.detectMultiScale(image, faceRects);
cv::Mat foundFacesImage = image.clone();
for (std::vector<cv::Rect>::const_iterator rect =
faceRects.begin(); rect != faceRects.end(); ++ rect)
{
cv::rectangle(foundFacesImage, *rect,
cv::Scalar(0, 0, 255), 3);
}
cv::namedWindow("Faces");
cv::imshow("Faces", foundFacesImage);
cv::waitKey();
28. Face detection: C++
cv::CascadeClassifier profileFaceCascade;
profileFaceCascade.load("haarcascade_profileface.xml");
std::vector<cv::Rect> faceRects;
profileFaceCascade.detectMultiScale(image, faceRects); with
OpenCV comes
other classifier XML
cv::Mat foundFacesImage = image.clone();
files for detecting other
for (std::vector<cv::Rect>::const_iterator rect (e.g eyes,
things =
faceRects.begin(); rect != faceRects.end(); ++ rect)
glasses, profile faces)
{
}
cv::rectangle(foundFacesImage, *rect,
cv::Scalar(0, 0, 255), 3);
cv::namedWindow("Faces");
cv::imshow("Faces", foundFacesImage);
cv::waitKey();
31. Conclusion
●
●
●
●
OpenCV is for image/video processing and
computer vision.
Free and open source (BSD licensed)
Cross-platform and actively developed (also
downloaded over 3 million times)!
This presentation covered just a few of the over
2,000 algorithms available in OpenCV.