汽车检测使用RCNN通过实时图像从一个相机,发现车的距离

6视图(30天)
我试图找到距离图像中检测到的车和显示它但是我得到这个错误而显示在图像的距离”的列数的位置必须是4的矩形的形状,或3圈的形状。”
我的下面的代码,我被困在这个错误请帮助我
负载(“webcamsSceneReconstruction.mat”);
data =负载(“fasterRCNNVehicleTrainingData.mat”);
trainingData = data.vehicleTrainingData;
trainingData。imageFilename = fullfile (toolboxdir (“愿景”),“visiondata”,trainingData.imageFilename);
%成形层
层= data.layers
选择= trainingOptions (“个”,“InitialLearnRate”1 e-6
“MaxEpochs”, 1
“CheckpointPath”,tempdir);
%训练检测器。
探测器= trainFasterRCNNObjectDetector (trainingData层,选项)
%测试快速R-CNN探测器测试图像。
webcamlist
一个=摄像头(2);
framecount = 1;
[高度宽度频道]=大小(快照(a));
framecount < 5
img =快照(a);
im_Left = img(:, 1:宽/ 2:);
%图;
% b = imshow (im_Left);
im_Right = img(宽/ 2 + 1::宽度:);
%运行探测器。
[bbox,分数,标签]=检测(探测器,im_Left);
[bbox,分数,标签]=检测(探测器,im_Right);
detectedImg1 = insertShape (im_Left,“矩形”,bbox);
detectedImg2 = insertShape (im_Right,“矩形”,bbox);
imshow (detectedImg1)
imshow (detectedImg2)
leftimage = undistortImage (im_Left stereoParams.CameraParameters1);
rightimage = undistortImage (im_Right stereoParams.CameraParameters2);
center1 = detectedImg1 (1:2) + detectedImg1 (3:4) / 0.005;
center2 = detectedImg2 (1:2) + detectedImg2 (3:4) / 0.005;
point3d =满足(center1 center2 stereoParams);
distanceInMeters =规范(point3d) / 1000;
distanceAsString = sprintf (“% 0.2 f米”,distanceInMeters);
leftimage = insertObjectAnnotation (leftimage,“矩形”、center1 distanceAsString);
rightimage = insertObjectAnnotation (rightimage,“矩形”、center2 distanceAsString);
% leftimage = insertShape (bboxes detectedImg1,“矩形”,“线宽”,3);
% rightimage = insertShape (bboxes detectedImg2,“矩形”,“线宽”,3);
leftimage = insertShape (leftimage,“FilledRectangle”,detectedImg1);
rightimage = insertShape (rightimage,“FilledRectangle”,detectedImg2);
imshowpair (leftimage rightimage,“蒙太奇”);
framecount = framecount + 1;
结束
  • 我得到错误显示在图像*

答案(1)

穆罕默德伊尔凡
穆罕默德伊尔凡 2018年6月16日
编辑:穆罕默德伊尔凡 2018年6月16日
你好,
的问题是如何被称为函数 insertObjectAnnotation 。你最好通过它的文档 在这里
如果你想插入一个矩形,你需要一个边界框是一个1 * 4数组(x y宽度高度)。你是 center1 center2 1 * 2的大小。
我还不清楚你想做什么线
center1 = detectedImg1 (1:2) + detectedImg1 (3:4) / 0.005;
center2 = detectedImg2 (1:2) + detectedImg2 (3:4) / 0.005;
你可能想要再次经历它的逻辑。
1评论
沃尔特·罗伯森
沃尔特·罗伯森 2018年6月16日
正确的。记住insertShape返回一个RGB图像,所以detectedImag1将RGB图像,没有任何的坐标。从bbox坐标。
注意,你有
[bbox,分数,标签]=检测(探测器,im_Left);
[bbox,分数,标签]=检测(探测器,im_Right);
所以左边的检测图像和你扔掉所有的结果,覆盖检测从右边的输出变量。然后画出正确的结果 这两个 的图像。
你也有问题,有可能多个车辆被探测到。结果在bbox,超过一行。
中心的边界boxare bbox (:, (1 2)) + bbox (:, [3 - 4]) / 2

登录置评。

社区寻宝

找到宝藏在MATLAB中央,发现社区如何帮助你!

开始狩猎!