在录制视频中检测特定对象的角度

huangapple go评论112阅读模式
英文:

angle detection of a particular object in a recorded video

问题

我正在尝试找出下面照片中黑条纹的角度,并希望对整个记录的视频进行分析。我尝试在网上找到相关代码,但只能找到适用于图像或需要手动绘制线条并查找角度的代码。您是否了解类似于这个问题的项目或开源代码?

在录制视频中检测特定对象的角度

我尝试查找开源代码,发现了GitHub上的姿势估计和图像中物体角度检测的项目。但没有找到适用于已记录的视频和物体跟踪的解决方案。

英文:

I am trying to find out the angle of the black stripe in the below photo for the entire recorded video. I was trying to find code online but was only able to find code for images or requiring manual input of drawing lines on image and finding angle. Do you know any projects or opensource code which is similar to this problem?

在录制视频中检测特定对象的角度

Tried to find opensource codes , found github projects on pose estimation and angle detection of objects in an image. Didn't find anything for recorded videos and object tracking

答案1

得分: 1

我认为第一步应该是将您的视频分解成一系列图像,然后您可以单独处理它们(例如,按照这个方法)。您很可能不需要处理它们全部,因为我想象您可能只对骑手的倾斜角度感兴趣,我怀疑您无法在此设置下测量到1/帧速率数量级的时间尺度内的角度变化。

假设您只关心视频帧的水平或垂直角度(我没有看到其他基准点存在),您可以使用Canny边缘检测:

import cv2

img = cv2.imread("image.png", flags=0)
img_blur = cv2.GaussianBlur(img, (3, 3), 0, 0)

edges = cv2.Canny(image=img_blur, threshold1=100, threshold2=200)

cv2.imshow("Edges", edges)
cv2.waitKey(0)

这将允许您检测马甲上条纹的边缘。您可以使用感兴趣区域来仅考虑帧的某个特定部分,然后查找角点或边缘,并找到这些边缘相对于水平的角度。

我不确定是否有一个现成的方法来执行此操作,因为我认为使用其他对象跟踪方法,您只需找到该区域的质心而无需其他步骤。

英文:

I think the first step would just be to first decompose your video into a series of images, then you could process them individually (e.g. following this method). You most likely wouldn't need to process them all as I would imagine you are interested in lean angle of the rider and I doubt you would be able to measure angle changes with timescales on the order of 1/frame rate with this setup.

Assuming you are just interested in the angle with respect to the horizontal or vertical of the video frame (I didn't see any other fiducials present) you could then use a Canny edge detection:

import cv2

img = cv2.imread("image.png", flags=0)
img_blur = cv2.GaussianBlur(img, (3, 3), 0, 0)

edges = cv2.Canny(image=img_blur, threshold1=100, threshold2=200)

cv2.imshow("Edges", edges)
cv2.waitKey(0)

Which would allow you to detect the edges of the stripe on the vest. You could use a region of interest to only consider a certain section of the frame and then look for the corners or edges and find the angle of those edges with respect to the horizontal.

I'm not sure if there is a drop in place method to do this as I think with other object tracking methods you would just be finding the centroid of that area without additional steps.

答案2

得分: 0

**1.- 输入图像**

    A=imread('001.jpg');
    hf=figure(1);
    ax=gca
    imshow(A);

**2.- 调整对比度**

    th_low=.3  % 低对比度阈值
    th_high=.7  % 高对比度阈值
    
    A2=imadjust(A,[th_low th_low th_low; th_high th_high th_high],[]);

没有调整对比度会出现一些'环状'展示我所称的样本横截面上的'环状'

[![在这里输入图片描述][1]][1]

    hold(ax,'on');
    plot(ax,[130:190],200,'b*')
    
     图(2);
     stem([130:190],A(200,[130:190],1),'Color','r');
     网格 on
     hold on
     标题('未调整对比度')
     stem([130:190],A(200,[130:190],2),'Color','g');
     stem([130:190],A(200,[130:190],3),'Color','b');

[![在这里输入图片描述][2]][2]

     图(3);
     stem([130:190],A2(200,[130:190],1),'Color','r');
     网格 on
     hold on
     标题('调整对比度后')
     stem([130:190],A2(200,[130:190],2),'Color','g');
     stem([130:190],A2(200,[130:190],3),'Color','b');

[![在这里输入图片描述][3]][3]

感兴趣区域横截面的方差要低得多,
在改善对比度后,边缘更为清晰。

**3.- 在感兴趣区域内选择单个参考点**

我知道你希望没有任何交互,谁会不同意呢。

然而,一个单独的点只是为了跳过识别感兴趣区域的步骤,即目标条带。

这样的排序并不困难,但很繁琐,我希望你同意这样的分类至少需要另一个问题,例如:这将是'在这些分割区域中找到头盔、路界限、自行车...直到得到感兴趣的条带。

    图(4)
    ax4=gca
    imshow(A2)
    hold(ax4,'on');

[![在这里输入图片描述][4]][4]
    
    print('在感兴趣区域内单击一个点');
    [y0,x0]=ginput(1);
    
    x0=floor(x0);y0=floor(y0);
    
    plot(ax4,y0,x0,'g*');
    
    Ar=A2(:,:,1);  % 红色
    Ag=A2(:,:,2);  % 绿色 
    Ab=A2(:,:,3);  % 蓝色
    
    ar0=double(Ar(x0,y0))
    ag0=double(Ag(x0,y0))
    ab0=double(Ab(x0,y0))
    
    er_r=.05;er_g=.05;er_b=.05;  % 误差阈值 1%
    
    d1=5;  % 非欧几里得,绝对距离
    
    nxr=1;nxl=1;nyu=1;nyd=1;
    
    A0=[Ar(x0,y0) Ag(x0,y0) Ab(x0,y0)]
    
    A_right=[Ar(x0+nxr,y0) Ag(x0+nxr,y0) Ab(x0+nxr,y0)]
    A_left=[Ar(x0-nxl,y0) Ag(x0-nxl,y0) Ab(x0-nxl,y0)]
    A_up=double([Ar(x0,y0+nyu) Ag(x0,y0+nyu) Ab(x0,y0+nyu)])
    A_down=double([Ar(x0,y0-nyd) Ag(x0,y0-nyd) Ab(x0,y0-nyd)])
    
    while abs(double(A0(1))-double(A_right(1)))<d1 && ...       % 右
            abs(double(A0(2))-double(A_right(2)))<d1 && ...
            abs(double(A0(3))-double(A_right(3)))<d1 && ...
            y0+nxr<size(Ar,2)
    
            plot(ax4,y0+nxr,x0,'b*')
            nxr=nxr+1;
            A_right=[Ar(x0,y0+nxr) Ag(x0,y0+nxr) Ab(x0,y0+nxr)]
            plot(ax4,y0+nxr,x0,'r*')
    end
    
    while abs(double(A0(1))-double(A_left(1)))<d1 && ...      % 左
            abs(double(A0(2))-double(A_left(2)))<d1 && ...
            abs(double(A0(3))-double(A_left(3)))<d1 && ...
            y0-nxl>1
    
            plot(ax4,y0-nxl,x0,'b*')
            nxl=nlx+1;
            A_left=[Ar(x0,y0-nxl) Ag(x0,y0-nxl) Ab(x0,y0-nxl)]
            plot(ax4,y0-nxl,x0,'r*')
    end
    
    while abs(double(A0(1))-double(A_down(1)))<d1 && ...      % 下
            abs(double(A0(2))-double(A_down(2)))<d1 && ...
            abs(double(A0(3))-double(A_down(3)))<d1 && ...
            x0+nyd<size(Ar,1)
    
            plot(ax4,y0,x0+nyd,'b*')
            nyd=nyd+1;
            A_down=[Ar(x0+nyd,y0) Ag(x0+nyd,y0) Ab(x0+nyd,y0)]
            plot(ax4,y0,x0+nyd,'r*')
    end
    
    while abs(double(A0(1))-double(A_up(1)))<d1 && ...      % 上
            abs(double(A0(2))-double(A_up(2)))<d1 && ...
            abs(double(A0(3))-double(A_up(3)))<d1 && ...
            x0-nyu>1
    
            plot(ax4,y0,x0-nyu,'b*') % 检查
            nyu=nyu+1;
           

<details>
<summary>英文:</summary>

**1.- Input Image**

    A=imread(&#39;001.jpg&#39;);
    hf=figure(1);
    ax=gca
    imshow(A);

**2.- Adjusting Contrast**

    th_low=.3  % low contrast threshold
    th_high=.7  % high contrast threshold
    
    A2=imadjust(A,[th_low th_low th_low; th_high th_high th_high],[]);

Without adjusting contrast there&#39;s some &#39;ringing&#39;.
Showing what I call &#39;ringing&#39; along a sample cross section

[![enter image description here][1]][1]

    hold(ax,&#39;on&#39;);
    plot(ax,[130:190],200,&#39;b*&#39;)
    
     figure(2);
     stem([130:190],A(200,[130:190],1),&#39;Color&#39;,&#39;r&#39;);
     grid on
     hold on
     title(&#39;without contrast adjustment&#39;)
     stem([130:190],A(200,[130:190],2),&#39;Color&#39;,&#39;g&#39;);
     stem([130:190],A(200,[130:190],3),&#39;Color&#39;,&#39;b&#39;);

[![enter image description here][2]][2]

     figure(3);
     stem([130:190],A2(200,[130:190],1),&#39;Color&#39;,&#39;r&#39;);
     grid on
     hold on
     title(&#39;with contrast adjustment&#39;)
     stem([130:190],A2(200,[130:190],2),&#39;Color&#39;,&#39;g&#39;);
     stem([130:190],A2(200,[130:190],3),&#39;Color&#39;,&#39;b&#39;);

[![enter image description here][3]][3]

The variance of a cross section of the are of interest is far lower
along inside the are of interest, and the endges are sharper, after improving contrast

**3.- Take Single Point reference inside area of interest**

I know you&#39;d like it without any interaction, who would disagree.

However, a single point is only to skip discerning the area of interest, the targeted strip.

Such sorting is not difficult, but laborious and I hope you agree upon the fact that such classification would need at least another question, for instance: That would be &#39;find among this segmented zones the helmet, the road limits, the byke .. until getting to the strip of interest.

    figure(4)
    ax4=gca
    imshow(A2)
    hold(ax4,&#39;on&#39;);

[![enter image description here][4]][4]
    
    print(&#39;click on 1 point inside area of interest&#39;);
    [y0,x0]=ginput(1);
    
    x0=floor(x0);y0=floor(y0);
    
    plot(ax4,y0,x0,&#39;g*&#39;);
    
    Ar=A2(:,:,1);  % red
    Ag=A2(:,:,2);  % green 
    Ab=A2(:,:,3);  % blue
    
    ar0=double(Ar(x0,y0))
    ag0=double(Ag(x0,y0))
    ab0=double(Ab(x0,y0))
    
    er_r=.05;er_g=.05;er_b=.05;  % error threshold 1%
    
    d1=5;  % NOT euclidean, ABS distance
    
    nxr=1;nxl=1;nyu=1;nyd=1;
    
    A0=[Ar(x0,y0) Ag(x0,y0) Ab(x0,y0)]
    
    A_right=[Ar(x0+nxr,y0) Ag(x0+nxr,y0) Ab(x0+nxr,y0)]
    A_left=[Ar(x0-nxl,y0) Ag(x0-nxl,y0) Ab(x0-nxl,y0)]
    A_up=double([Ar(x0,y0+nyu) Ag(x0,y0+nyu) Ab(x0,y0+nyu)])
    A_down=double([Ar(x0,y0-nyd) Ag(x0,y0-nyd) Ab(x0,y0-nyd)])
    
    while abs(double(A0(1))-double(A_right(1)))&lt;d1 &amp;&amp; ...       % right
            abs(double(A0(2))-double(A_right(2)))&lt;d1 &amp;&amp; ...
            abs(double(A0(3))-double(A_right(3)))&lt;d1 &amp;&amp; ...
            y0+nxr&lt;size(Ar,2)
    
            plot(ax4,y0+nxr,x0,&#39;b*&#39;)
            nxr=nxr+1;
            A_right=[Ar(x0,y0+nxr) Ag(x0,y0+nxr) Ab(x0,y0+nxr)]
            plot(ax4,y0+nxr,x0,&#39;r*&#39;)
    end
    
    while abs(double(A0(1))-double(A_left(1)))&lt;d1 &amp;&amp; ...      % left
            abs(double(A0(2))-double(A_left(2)))&lt;d1 &amp;&amp; ...
            abs(double(A0(3))-double(A_left(3)))&lt;d1 &amp;&amp; ...
            y0-nxl&gt;1
    
            plot(ax4,y0-nxl,x0,&#39;b*&#39;)
            nxl=nxl+1;
            A_left=[Ar(x0,y0-nxl) Ag(x0,y0-nxl) Ab(x0,y0-nxl)]
            plot(ax4,y0-nxl,x0,&#39;r*&#39;)
    end
    
    while abs(double(A0(1))-double(A_down(1)))&lt;d1 &amp;&amp; ...      % down
            abs(double(A0(2))-double(A_down(2)))&lt;d1 &amp;&amp; ...
            abs(double(A0(3))-double(A_down(3)))&lt;d1 &amp;&amp; ...
            x0+nyd&lt;size(Ar,1)
    
            plot(ax4,y0,x0+nyd,&#39;b*&#39;)
            nyd=nyd+1;
            A_down=[Ar(x0+nyd,y0) Ag(x0+nyd,y0) Ab(x0+nyd,y0)]
            plot(ax4,y0,x0+nyd,&#39;r*&#39;)
    end
    
    while abs(double(A0(1))-double(A_up(1)))&lt;d1 &amp;&amp; ...      % up
            abs(double(A0(2))-double(A_up(2)))&lt;d1 &amp;&amp; ...
            abs(double(A0(3))-double(A_up(3)))&lt;d1 &amp;&amp; ...
            x0-nyu&gt;1
    
            plot(ax4,y0,x0-nyu,&#39;b*&#39;) % check
            nyu=nyu+1;
            A_up=[Ar(x0-nyu,y0) Ag(x0-nyu,y0) Ab(x0-nyu,y0)]
            plot(ax4,y0,x0-nyu,&#39;r*&#39;) % check
    end

The resulting cross

[![enter image description here][5]][5]

the plot lines inside the while loops are just to make sure &#39;the cross&#39;
end up where it should.

What you call the &#39;orientation&#39; can now be found further processing
the upper side of &#39;the cross&#39;. This is, it should be easy to find whether
the upper side &#39;turns&#39; left or right hence the &#39;visual orientation&#39; of
the driver, which is likely what you need to obtain just from the attitude of the driver&#39;s back marked with the strip.

In black &amp; white it&#39;s easier, but now you have the possibility
to directly look for charcteristic hi-vi vest fluorescent green
to solve the corner I cut aiming with a single mouse click.

I would to further elaborate and add more script precisely developing
these closing comments, but perhaps it&#39;s better to get some feed back
first.

For the following steps, if you need further help just post another question and let me know the link to next question.


  [1]: https://i.stack.imgur.com/n6Zvf.jpg
  [2]: https://i.stack.imgur.com/zJzWG.jpg
  [3]: https://i.stack.imgur.com/CDrD7.jpg
  [4]: https://i.stack.imgur.com/2TYSS.jpg
  [5]: https://i.stack.imgur.com/5KLSd.jpg

</details>



huangapple
  • 本文由 发表于 2023年7月18日 05:20:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76708151.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定