+ All Categories
Home > Documents > PART II – Two case studies Dario Cazzato, INO – CNR [email protected] Università del Salento...

PART II – Two case studies Dario Cazzato, INO – CNR [email protected] Università del Salento...

Date post: 17-Dec-2015
Category:
Upload: helen-norton
View: 214 times
Download: 0 times
Share this document with a friend
Popular Tags:
58
OpenCV PART II – Two case studies Dario Cazzato, INO – CNR [email protected] Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle Immagini) A.A. 2012/2013
Transcript
Page 1: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

OpenCVPART II – Two case studies

Dario Cazzato, INO – [email protected]

Università del SalentoFacoltà di Ingegneria

Image Processing(Elaborazione delle Immagini)

A.A. 2012/2013

Page 2: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

This lesson introduce the use of the OpenCV library on real cases.

Two study cases:◦ Stereo Correspondence Problem;◦ Segmentation of Video Sequences.

Introduction

Page 3: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Why OpenCV?◦ Free, open source, for real-time application, cross-

platform, constantly updated, strong partners and research.

C/C++:◦ “cv::Mat vs CvMat”.

Basic components:◦ Matrixes, vectors, rectangles, sizes, images,

datatype… Some example.

What We’ve seen

Page 4: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Stereo Correspondance Problem

Page 5: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision? Men:

◦ Binocular vision.◦ Average distance between

eyes: 6cm.◦ An object/point seen with

eyes is viewed as one, altough in the retina We have two images.

The combined image is more than the sum of its parts. It’s not trivial!

Page 6: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision? Other configurations:

◦ Animals: Predator: binocular sight. Prey: lateral eyes (to enlarge the field of sight).

◦ Intersecting line of sight (typical in stereo vision!).

Let’s see some key concept from a practical point of view, but all the problem is absolutely larger!◦ You will see more detail about epipolar

geometry and matrixes computation at lesson.

Page 7: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Pinhole camera model The simplest model of the camera. Only a single ray enters from any particular point, the

pinhole aperture. This point is projected onto the image plane. The focal lenght is the distance from the pinhole

aperture to the image plane.

Page 8: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Pinhole camera model A real point Q is

projected onto the image plane by the ray passing through the center of projection.

This intersection gives q.

Calibration Matrix (3X4)

From “Learning OpenCV”, G.Bradski, A.Kaehler, O’Reilly.

Page 9: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Pinhole camera model

Homogeneous coordinate system.

If you have N dimension, use N+1 coordinates.

HomographyPerspective Geometry

Page 10: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision?

1 Camera is not enough!

Page 11: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision?With two (or more) cameras we can compute depth by triangulation,if we are able to find homologous points in the two images.

Epipolar Geometry

Page 12: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision? Four steps:

1. Undistortion;2. Rectification;3. Disparity Map;4. Triangulation.

Page 13: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision?1. Undistortion: removal of tangential and

radial lens distortion.

This problem concerns the single camera!

Distortion vector (1X5)

Page 14: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision?1. Undistortion: removal of tangential and

radial lens distortion.

Page 15: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision?2. Rectify: output row-aligned images (coplanar,

with the same y-coordinate).

With rectified images, we can search for a point in one image in the same line (y-coordinate) of the second one!

Page 16: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision? Of course, a stereo calibration is needed

(extrinsic and intrinsic parameters):◦ Intrinsic: focal lenght, distortion.◦ Extrinsic: Matrixes R, T that aligns the two cameras

(Essential Matrix E, you will see more at lesson).

We can divide the procedure in :◦ Stereo Calibration: computation of the geometric

relations between the two cameras in space;◦ Stereo Rectification: “correction” of individual

images as made with row-aligned image plane and parallel optical axes.

Page 17: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision?

Look at the example of OpenCV, and the source stereo_calib.cpp.

Rectification turns the cameras in standard form!

Page 18: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision?

Example 1

Page 19: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision?

From “Learning OpenCV”, G.Bradski, A.Kaehler, O’Reilly.

Page 20: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision?3. Disparity map: difference in x-coordinates of

the same point viewed in the 2 cameras.

A map is created computing the disparity for all the points. It’s encoded as a grayscale image, where farer point are darker.

Page 21: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

What is Stereo Vision?4. Triangulation: difference in x-coordinates of

the same point viewed in the 2 cameras.

Idea: (d:T = f:Z)

Page 22: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Stereo Correspondence Problem How to find homologous points?

◦ Correlation-based - checking if one location in one image looks/seems like another in another image;

◦ Feature-based - finding features in the image and seeing if the layout of a subset of features is similar in the two images.

Page 23: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Occlusions

So, why so challenging?

Page 24: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Photometric transformations

So, why so challenging?

Page 25: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Uniform regions

So, why so challenging?

Page 26: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Noise Specular surfaces Perspective views Repetition “No results possible” detection:

◦ Sometime we just would like to say: “No correspondent point in the other image for this point”

So, why so challenging?

Page 27: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Stereo Correspondence ProblemLocal Algorithm

Winner take all strategy

Page 28: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Sum of Absolute Difference:

Sum of Squared Differences:

WTA Strategy

Page 29: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Zero-mean Normalized Cross Correlation:

Not just the window, but a fast normalization;

ZNCC has range [-1,1]; We compute the ZNCC for each pixel center; We take the max value.

WTA Strategy

Page 30: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

ZNCC

Page 31: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

ZNCC What we can do to enhounce the model?

◦ Ratio between first and second max; Idea behind: if the maximum and a local maximum

have similar value, the probability of error increase, and we could reject these values (putting a treshold).

◦ Spread; Idea behind: a flat area means repetitive texture. Just

discard maximum in flat peaks.◦ Multiple windows;◦ Kernel shape based on segmentation.

Computation time increases!

Page 32: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

ZNCC – Our model Two enhouncements:

1. Check the epipolar line ± size: We can deal with noise in the epipolar geometry; For a fast computation, keep size small! (1,2,3).

2. Inverse function: We take the maximum, and we make ZNCC again

starting from the right image; If the new winner isn’t the starting point (or is more

than a treshold far, an error occurred, so discard the point).

Demo 1

Page 33: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Segmentation of Video Sequences

Page 34: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Background subtraction One of the Video Sequences Segmentation

algorithms. Good with fixed camera and static

background. High level goal:

◦ People detection.◦ Surveillance:

Reactive; Proactive.

Page 35: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

From the Web

Page 36: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Codebook Model BS: subtract the current frame from the

background model. Two phases:

◦ Background training;◦ Foreground detection.

Improvements to the base version.

Page 37: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Segmentation - background model A codebook is built for every pixel; A codebook is composed by codewords, boxes;

that grow to cover the common values seen over the time;

Samples of each pixel are clustered in set of codewords;

Incoming pixel:◦ It has a brightness in the brightness range AND Color

Distortion less than a treshold = BACKGROUND;◦ Othervise FOREGROUND.

Page 38: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Segmentation – codebook model

Page 39: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Segmentation - mnrl MNRL (Maximum Negative Run Lenght): let

us to make the background learning with objects movement.

It refines codebook separating codebooks that can have foreground from the real background.

MNRL = 50%.

Page 40: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Segmentation – detecting foreground

The foreground is simply detected computing the distance of the sample from the nearest cluster mean.

Page 41: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Segmentation – codebook algorithm

Page 42: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Segmentation – codebook improvements Left object in the scene:

Page 43: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Segmentation – codebook improvements Holes problem:

Page 44: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Segmentation – codebook improvements Layering Modeling/Detection - 3 classes of

codebook and 3 parameters that let to switch in the categories:◦ Permanent;◦ Non-permanent;◦ Training.

Adaptative Codebook Updating:◦ Retraining is not the solution!! ◦ Global status updating at each frame;◦ Periodical cleanining of the old codebook.

Page 45: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Filtering the binary frame Median filter:

Page 46: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Filtering the binary frame Median filter:

Page 47: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Filtering the binary frame Opening and Closing:

Morphological Operators

Page 48: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Filtering the binary frame Opening and Closing:

Page 49: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Filtering the binary frame

Page 50: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Filtering the binary frame

Page 51: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Filtering the binary frame Opening:

Closing:

Median Filter:

Page 52: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Object detection Why object detection?

Not all the white pixels are of real interest (noise, holes not yet updated…).

Object detection and labeling algorithm required.

Page 53: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Object detection algorithm A: when an external contour point is encountered for the

first time, a complete trace of the contour is made. This procedure stops when A is found again. All that points will have the same label A;

B: when A' is encountered (it is an external contour point already labeled), a scan of the entire line is made, marking with the same label all the points encountered;

Page 54: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Object detection algorithm C: when an internal contour point B is encountered for the

first time, it takes the same label. Then a trace of this contour is made, giving again the same label to all the met point;

D: when an already labeled point is found, like B', a scan of the entire line is made, marking the detected point with the same label.

Page 55: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Filters – filter by area and ratio We slide all the blobs continuing to process

only blobs with an area and ratio included in a range: ◦ [min Area, max Area], in pixel;◦ [min Ratio, max Ratio].

Decision of range:◦ Average height (from 1,60m to 2m);◦ Average width of the box (from 10 cm to 60 cm);◦ Distance from the camera (from 1m to 5m);

A first necessary loss of genarality.

Demo 2

Page 56: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Technical report (Camera Calibration):◦ A Flexible New Technique for Camera

Calibration, Zhengyou Zhang, 1998 Papers (Stereo Vision):

◦ Chia-Hung Chen, Han-Pang Huang, and Sheng-Yen Lo, Stereo-Based 3D Localization for Grasping KnownObjects with a Robotic Arm System Department of Mechanical Engineering National Taiwan University 10647, Taipei, Taiwan

References

Page 57: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Papers (Codebook):◦ Kim, Chalidabhongse, Harwood, Davis, Real-Time

foreground-background segmentation using Codebook model, Computer Vision Lab, Department of Computer Science, University of Maryland, College Park, MD 20742, USA, Faculty of Information Technology, King Mongkut’s Institute of Technology, Ladkrabang, Bangkok 10520, Thailand, 2005.

◦ P. Fihl, R. Corlin, S. Park, T.B. Moeslund, M.M Trivedi, Tracking of Individuals in Very Long Video Sequence, Laboratory of Computer Vision and Media Technology, Aalborg University, Denmark, Computer Vision and Robotics Research Laboratory The University of California, San Diego, USA, 2006

References

Page 58: PART II – Two case studies Dario Cazzato, INO – CNR dario.cazzato@ino.it Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle.

Stereo Images and disparities (ground truth): ◦ http://vision.middlebury.edu/stereo

Camera Calibration and 3D Reconstruction with OpenCV:◦ http://docs.opencv.org/modules/calib3d/doc/camera_calibrati

on_and_3d_reconstruction.html Motion Analysis with OpenCV:

◦ http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html (MOG)

Books:◦ Codebook: “Learning OpenCV” (O’Reilly), Chapter 9.◦ Stereo Vision: “Learning OpenCV” (O’Reilly), Chapter 12.

Me:◦ [email protected]

References


Recommended