This example shows how to detect people in video taken with a calibrated stereo camera and determine their distances from the camera.
Load the Parameters of the Stereo Camera
Load the stereoParameters
object, which is the result of calibrating the camera using either the stereoCameraCalibrator
app or the estimateCameraParameters
function.
Create Video File Readers and the Video Player
Create System Objects for reading and displaying the video.
Read and Rectify Video Frames
The frames from the left and the right cameras must be rectified in order to compute disparity and reconstruct the 3-D scene. Rectified images have horizontal epipolar lines, and are row-aligned. This simplifies the computation of disparity by reducing the search space for matching points to one dimension. Rectified images can also be combined into an anaglyph, which can be viewed using the stereo red-cyan glasses to see the 3-D effect.
Compute Disparity
In rectified stereo images any pair of corresponding points are located on the same pixel row. For each pixel in the left image compute the distance to the corresponding pixel in the right image. This distance is called the disparity, and it is proportional to the distance of the corresponding world point from the camera.
Reconstruct the 3-D Scene
Reconstruct the 3-D world coordinates of points corresponding to each pixel from the disparity map.
Detect People in the Left Image
Use the vision.PeopleDetector
system object to detect people.
Determine The Distance of Each Person to the Camera
Find the 3-D world coordinates of the centroid of each detected person and compute the distance from the centroid to the camera in meters.
Process the Rest of the Video
Apply the steps described above to detect people and measure their distances to the camera in every frame of the video.
Summary
This example showed how to localize pedestrians in 3-D using a calibrated stereo camera.
References
[1] G. Bradski and A. Kaehler, "Learning OpenCV : Computer Vision with the OpenCV Library," O'Reilly, Sebastopol, CA, 2008.
[2] Dalal, N. and Triggs, B., Histograms of Oriented Gradients for Human Detection. CVPR 2005.