简体   繁体   English

如何在MATLAB中的视频帧上画一条线

[英]How to draw a line on a video frame in MATLAB

I am trying to draw a thin red line along the dark stick from edge to the moving part's green point which I found before on a video. 我试图沿着暗棒从边缘到运动部分的绿点绘制一条细红线,这在视频中我之前已经找到。 I am handling the video frame by frame. 我正在逐帧处理视频。

I can find the two points ( starting and ending points) but I am stuck how to make the two points and the points between them red linearly. 我可以找到两个点(开始点和结束点),但是我仍然陷于如何使两个点以及它们之间的点线性变红的问题。

for example 例如

for the current frame in the picture the top point coordinate is 45 down and 237 right from the top left(0,0) corner and the green point's coordinate is 231 down and 238 right from the top left corner. 对于图片中的当前帧,最高点坐标位于左上角(0,0)的下方45度和右边,而绿色点的坐标位于左上角231号下方和238点。

So I need to draw a line from (237,45) to (231,238). 所以我需要从(237,45)到(231,238)画一条线。

How I made the mid point green is substituting the pixel values in the current frame matrix. 我如何使中点变为绿色是在当前帧矩阵中替换像素值。 I am trying to make a similar approach but there could be more efficient way. 我正在尝试采用类似的方法,但是可能会有更有效的方法。

在此处输入图片说明

Unfortunately, you cannot use handle graphics commands on a vision.VideoPlayer . 不幸的是,您不能在vision.VideoPlayer上使用处理图形命令。 However, there is a function insertShape , which lets you draw directly into the image, before you display it. 但是,有一个函数insertShape ,可让您在显示图像之前直接将其绘制到图像中。

imshow(image_name);
hold on
[n, m] = imsize(image_name);
plot([231 237], [n-238, n-45], 'r');

This should use the standard plotting tool to plot directly onto the image. 这应该使用标准绘图工具直接在图像上进行绘图。 you need to use n-value, as images use top left as (0,0), where plot uses bottom left. 您需要使用n值,因为图像使用的左上角为(0,0),而图使用的是左下角。 the plot command simply plots an array of 2 points which it will automatically join with a line. plot命令仅绘制一个由2个点组成的数组,它将自动与一条线连接。 You can go directly editing pixels, but finding which pixels to edit and then keeping it neat is really really messy 您可以直接编辑像素,但是找到要编辑的像素然后保持整洁真的很麻烦

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM