1

我试图在视频帧上绘制一个多边形。像这样:

boxPolygon = [1, 1;...                           % top-left
        size(boxImage, 2), 1;...                 % top-right
        size(boxImage, 2), size(boxImage, 1);... % bottom-right
        1, size(boxImage, 1);...                 % bottom-left
        1, 1];                   % top-left again to close the polygon
newBoxPolygon = transformPointsForward(tform, boxPolygon);

Poly = [newBoxPolygon(1,1) newBoxPolygon(1,2) newBoxPolygon(2,1) newBoxPolygon(2,2) ...
        newBoxPolygon(3,1) newBoxPolygon(3,2) newBoxPolygon(4,1) newBoxPolygon(4,2)...
        newBoxPolygon(5,1) newBoxPolygon(5,2)];
sceneImage = insertShape(sceneImage, 'Polygon', Poly, 'Color', 'green');
step(hVideoOut, sceneImage);

之后,我收到一个错误: Error using vision.VideoPlayer/step 如果不先调用 release() 方法,则不允许更改输入 1 的大小。

如果我删除函数“insertShape”,那么一切都很好,只是没有绘制图形。

4

1 回答 1

1

我的猜测是您正在使用灰度视频,当没有检测到任何内容时,您正在将灰度图像传递给视频播放器。但是,insertShape返回一个 RGB 图像,因为您要在其中插入一个绿色多边形。问题是,一旦调用 的step方法vision.VideoPlayer,就无法更改在后续调用中传递给它的图像大小。因此,您必须确保始终显示 RGB 图像,即使未检测到任何内容。您可以使用 RGB 视频,也可以通过将灰度图像复制 3 次来创建 3 平面图像(例如,使用cat(3, sceneImage, sceneImage, sceneImage).

于 2013-12-25T18:21:27.967 回答