深度估计立体视频

这个例子展示了如何检测人在视频拍摄与校准立体相机和确定他们的距离从相机。

加载立体声相机的参数

加载立体塔纳米仪对象,这是使用校准相机使用的结果立体帕拉匹配剂应用程序或估计估计功能。

%加载Stereoparameters对象。加载(“handshakeStereoParams.mat”);%可视化相机外部特性。showextrinsics(默认帕拉姆);

创建视频文件读取器和视频播放器

创建系统对象以阅读和显示视频。

Videofileleft =.'handshake_left.avi';VideoFileright =.“handshake_right.avi”;readerLeft = VideoReader (videoFileLeft);readerRight = VideoReader (videoFileRight);球员=愿景。放像机(“位置”,[20,200,740 560]);

读取并纠正视频帧

必须纠正左侧和右摄像机的帧以计算差异并重建3-D场景。整流图像具有水平骨骼线,并且是排序的。这通过减少匹配点到一个维度来简化视差计算。整流图像也可以组合成一个骨骼相位,可以使用立体声红青色玻璃来观看3D效果。

frameLeft = readFrame (readerLeft);frameRight = readFrame (readerRight);[Frameftrect,FrameRightrette] =......rectifystereoImages(FrameLeft,Frameright,Stereoparams);图;imshow(立体式(立体式)(弗雷塞(Framereftrect,Framerightrett));标题('纠正的视频框架');

计算差异

在整流立体图像中,任何一对相应点位于同一像素行上。对于左图像中的每个像素计算到右图像中的对应像素的距离。该距离称为视差,与来自相机的相应世界点的距离成比例。

frameLeftGray = rgb2gray (frameLeftRect);frameRightGray = rgb2gray (frameRightRect);disitymap = disityysgm (frameLeftGray, frameRightGray);图;, 64年imshow (disparityMap [0]);标题('差异地图');COLOROMAP.喷射colorbar

重建3-D场景

从视差图中重建每个像素对应点的三维世界坐标。

points3D = reconstructScene(disparityMap, stereoParams);%转换为米并创建PointCloud对象points3D = points3D ./ 1000;ptCloud = pointCloud (points3D,“颜色”,frameleftrect);%创建流点云查看器player3D = pcplayer([- 3,3], [- 3,3], [0,8]),“VerticalAxis”'是'......'verticalaxisdir'“下来”);%可视化点云查看(Player3D,PtCloud);

探测左侧图像的人

使用Vision.peopledetector系统对象检测人。

%创建人员检测器对象。限制最小对象大小%的速度。peopleDetector =愿景。PeopleDetector ('迷你'83年[166]);%检测人。bboxes = peopleDetector.step (frameLeftGray);

确定每个人到摄像机的距离

找到每个检测到的人的质心的三维世界坐标,并将距质心的距离计算为以米为单位的距离。

%找到被发现的人的质心。Centroids = [round(bboxes(:, 1) + bboxes(:, 3) / 2),......Round (bboxes(:, 2) + bboxes(:, 4) / 2)];%找到了质心的三维世界坐标。centroidsIdx = sub2ind(size(disparityMap), centroids(:, 2), centroids(:, 1));X = pointts3d (:,:, 1);Y = pointts3d (:,:, 2);Z = pointts3d (:,:, 3);centroids3D = [X (centroidsIdx) ';Y (centroidsIdx) ';Z (centroidsIdx)];%以米为单位的相机找到距离。sqrt(sum(centroids3D .^ 2));%显示检测到的人的距离。标签=单元格(1,NUMER(DIST));为了i = 1:numel(dists)标签{i} = sprintf('%0.2F米'距离(我));结尾图;imshow(InsertObjectAnnotation(framereftrect,“矩形”、bboxes标签);标题(“发现人”);

处理其余的视频

应用上述步骤在视频的每一帧中检测人和测量他们与摄像机的距离。

Hasfame(ReaderLeft)&& hasfame(readeright)%阅读框架。frameLeft = readFrame (readerLeft);frameRight = readFrame (readerRight);%矫正帧。[Frameftrect,FrameRightrette] =......rectifystereoImages(FrameLeft,Frameright,Stereoparams);%转换为灰度。frameLeftGray = rgb2gray (frameLeftRect);frameRightGray = rgb2gray (frameRightRect);%计算差异。disparitymap = disparitysgm(framereftray,framerightgray);%重建3d场景。points3D = reconstructScene(disparityMap, stereoParams);points3D = points3D ./ 1000;ptCloud = pointCloud (points3D,“颜色”,frameleftrect);查看(Player3D,PtCloud);%检测人。bboxes = peopleDetector.step (frameLeftGray);如果〜isempty(bboxes)%找到被发现的人的质心。Centroids = [round(bboxes(:, 1) + bboxes(:, 3) / 2),......Round (bboxes(:, 2) + bboxes(:, 4) / 2)];%找到了质心的三维世界坐标。centroidsIdx = sub2ind(size(disparityMap), centroids(:, 2), centroids(:, 1));X = pointts3d (:,:, 1);Y = pointts3d (:,:, 2);Z = pointts3d (:,:, 3);centroids3d = [x(centroidsidx),y(centroidsidx),z(centroidsidx)];%以米为单位的相机找到距离。dists = sqrt(sum(centroids3d。^ 2,2));%显示检测人员及其距离。标签=单元格(1,NUMER(DIST));为了i = 1:numel(dists)标签{i} = sprintf('%0.2F米'距离(我));结尾dispFrame = insertObjectAnnotation (frameLeftRect,“矩形”,bboxes,......标签);别的dispFrame = frameLeftRect;结尾%显示帧。步骤(播放器,Dispframe);结尾

%清理释放(球员);

总结

此示例显示了如何使用校准的立体声相机在3-D中本地化行人。

参考文献

[1] G. Bradski和A.Kaehler,“学习OpenCV:与OpenCV图书馆的计算机愿景,”O'Reilly,Sebastopol,2008年,2008年。

[2] Dalal, N.和Triggs, B.,人类检测的定向梯度直方图。CVPR 2005。