630 likes | 1.02k Views
Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle Immagini) A.A. 2012/2013. OpenCV. PART II – Two case studies. Dario Cazzato, INO – CNR dario.cazzato@ino.it. Introduction. This lesson introduce the use of the OpenCV library on real cases .
E N D
Università del Salento Facoltà di Ingegneria Image Processing (Elaborazione delle Immagini) A.A. 2012/2013 OpenCV PART II – Twocase studies Dario Cazzato, INO – CNR dario.cazzato@ino.it
Introduction • Thislesson introduce the useof the OpenCVlibrary on realcases. • Twostudycases: • Stereo CorrespondenceProblem; • Segmentationof Video Sequences.
WhatWe’ve seen • WhyOpenCV? • Free, open source, for real-time application, cross-platform, constantlyupdated, strong partners and research. • C/C++: • “cv::Mat vs CvMat”. • Basiccomponents: • Matrixes, vectors, rectangles, sizes, images, datatype… • Some example.
Whatis Stereo Vision? • Men: • Binocular vision. • Averagedistancebetweeneyes: 6cm. • An object/pointseenwitheyesisviewedasone, altough in the retina Wehavetwoimages. • The combined image is more than the sum of its parts. It’snottrivial!
Whatis Stereo Vision? • Otherconfigurations: • Animals: • Predator: binocularsight. • Prey: lateraleyes (toenlarge the fieldofsight). • Intersectinglineofsight (typical in stereo vision!). • Let’ssee some key conceptfrom a practicalpointofview, butall the problemisabsolutelylarger! • Youwillsee more detailaboutepipolargeometry and matrixescomputation at lesson.
Pinhole camera model • The simplestmodelof the camera. • Only a single rayentersfromanyparticularpoint, the pinhole aperture. • Thispointisprojectedonto the imageplane. • The focallenghtis the distancefrom the pinhole aperture to the imageplane.
Pinhole camera model • A realpointQisprojectedonto the imageplaneby the raypassingthrough the center ofprojection. • Thisintersectiongives q. Calibration Matrix (3X4) From “LearningOpenCV”, G.Bradski, A.Kaehler, O’Reilly.
Pinhole camera model • Homogeneous coordinate system. • IfyouhaveNdimension, use N+1 coordinates. Homography PerspectiveGeometry
Whatis Stereo Vision? 1 Camera isnotenough!
Whatis Stereo Vision? Withtwo (or more) cameraswe can computedepthbytriangulation, ifwe are abletofindhomologouspoints in the twoimages. EpipolarGeometry
Whatis Stereo Vision? • Foursteps: • Undistortion; • Rectification; • DisparityMap; • Triangulation.
Whatis Stereo Vision? • Undistortion: removaloftangential and radiallensdistortion. Thisproblemconcerns the single camera! Distortionvector (1X5)
Whatis Stereo Vision? • Undistortion: removaloftangential and radiallensdistortion.
Whatis Stereo Vision? • Rectify: output row-alignedimages (coplanar, with the same y-coordinate). Withrectifiedimages, we can searchfor a point in oneimage in the sameline (y-coordinate) of the secondone!
Whatis Stereo Vision? • Ofcourse, a stereo calibrationisneeded (extrinsic and intrinsicparameters): • Intrinsic: focallenght, distortion. • Extrinsic: MatrixesR, Tthataligns the twocameras (Essential Matrix E, youwillsee more at lesson). • We can divide the procedure in : • Stereo Calibration: computationof the geometric relations between the twocameras in space; • Stereo Rectification: “correction” ofindividualimagesasmadewithrow-alignedimageplane and parallelopticalaxes.
Whatis Stereo Vision? Look at the exampleofOpenCV, and the source stereo_calib.cpp. Rectificationturns the cameras in standard form!
Whatis Stereo Vision? Example1
Whatis Stereo Vision? From “LearningOpenCV”, G.Bradski, A.Kaehler, O’Reilly.
Whatis Stereo Vision? • Disparitymap: difference in x-coordinatesof the samepointviewed in the 2cameras. A mapiscreatedcomputing the disparityforall the points. It’sencodedas a grayscaleimage, wherefarerpoint are darker.
Whatis Stereo Vision? • Triangulation: difference in x-coordinatesof the samepointviewed in the 2cameras. Idea: (d:T = f:Z)
Stereo CorrespondenceProblem • Howtofindhomologouspoints? • 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.
So, why so challenging? • Occlusions
So, why so challenging? • Photometric transformations
So, why so challenging? • Uniformregions
So, why so challenging? • Noise • Specular surfaces • Perspectiveviews • Repetition • “No resultspossible” detection: • Sometimewe just wouldliketosay: “No correspondentpoint in the otherimageforthispoint” • …
Stereo CorrespondenceProblem LocalAlgorithm Winner take allstrategy
WTA Strategy • Sum ofAbsoluteDifference: • Sum ofSquaredDifferences:
WTA Strategy • Zero-meanNormalized Cross Correlation: • Not just the window, but a fast normalization; • ZNCC hasrange [-1,1]; • Wecompute the ZNCC foreach pixel center; • We take the maxvalue.
ZNCC • Whatwe can do toenhounce the model? • Ratiobetween first and secondmax; • Idea behind: if the maximum and a localmaximumhavesimilarvalue, the probabilityoferrorincrease, and wecouldrejectthesevalues (putting a treshold). • Spread; • Idea behind: a flat area meansrepetitivetexture. Just discardmaximum in flatpeaks. • Multiple windows; • Kernel shapebased on segmentation. • Computationtimeincreases!
ZNCC –Ourmodel • Twoenhouncements: • Check the epipolarline±size: • We can deal withnoise in the epipolargeometry; • For a fast computation, keepsizesmall! (1,2,3). • Inverse function: • We take the maximum, and wemake ZNCC againstartingfrom the right image; • If the newwinnerisn’t the startingpoint (or is more than a treshold far, anerroroccurred, so discard the point). Demo 1
Background subtraction • Oneof the Video SequencesSegmentationalgorithms. • Goodwithfixed camera and static background. • High level goal: • People detection. • Surveillance: • Reactive; • Proactive.
CodebookModel • BS: subtract the current frame from the background model. • Twophases: • Background training; • Foreground detection. • Improvementsto the base version.
Segmentation - background model • A codebookisbuiltforevery pixel; • A codebookiscomposedbycodewords, boxes; thatgrowto cover the common valuesseenover the time; • Samplesofeach pixel are clustered in set ofcodewords; • Incoming pixel: • Ithas a brightness in the brightnessrange AND Color Distortionlessthan a treshold = BACKGROUND; • Othervise FOREGROUND.
Segmentation - mnrl MNRL (Maximum Negative RunLenght): letustomake the background learningwithobjectsmovement. Itrefinescodebookseparatingcodebooksthat can haveforegroundfrom the real background. MNRL = 50%.
Segmentation–detectingforeground The foregroundissimplydetectedcomputing the distanceof the sample from the nearest cluster mean.
Segmentation–codebookimprovements Leftobject in the scene:
Segmentation–codebookimprovements Holesproblem:
Segmentation–codebookimprovements • LayeringModeling/Detection - 3classesofcodebook and 3parametersthatlettoswitch in the categories: • Permanent; • Non-permanent; • Training. • AdaptativeCodebookUpdating: • Retrainingisnot the solution!! • Global status updating at each frame; • Periodicalcleaniningof the oldcodebook.
Filtering the binary frame Medianfilter:
Filtering the binary frame Medianfilter:
Filtering the binary frame MorphologicalOperators Opening and Closing:
Filtering the binary frame Opening and Closing: