0
A
回答
1
您可以使用Hough Transform进行在线检测。
我的大部分文章都是基于Hough变换文档。
示例代码:
%Read input image from imgur
I = imread('https://i.stack.imgur.com/EcHfy.png');
J = zeros(size(I,1), size(I,2));
%Select dark pixels (assume wires are dark).
J((I(:,:,1) < 80) & (I(:,:,2) < 80) & (I(:,:,3) < 80)) = 1;
%figure;imshow(J);
%Find the edges in the image using the edge function.
BW = edge(J,'canny');
%figure;imshow(BW);
%Compute the Hough transform of the binary image returned by edge.
[H,theta,rho] = hough(BW);
%Display the transform, H, returned by the hough function.
% figure;imshow(imadjust(mat2gray(H)),[], 'XData',theta, 'YData',rho, 'InitialMagnification','fit');
% xlabel('\theta (degrees)');ylabel('\rho');axis on;axis normal ;hold on;colormap(gca,hot);
%Find the peaks in the Hough transform matrix, H, using the houghpeaks function.
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
%Superimpose a plot on the image of the transform that identifies the peaks.
%x = theta(P(:,2));y = rho(P(:,1));plot(x,y,'s','color','black');
%Find lines in the image using the houghlines function.
lines = houghlines(BW,theta,rho,P,'FillGap',50,'MinLength',7);
%Create a plot that displays the original image with the lines superimposed on it.
figure, imshow(I), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if (len > max_len)
max_len = len;
xy_long = xy;
end
end
% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');
备注:
完全可以提高使用形态操作的结果。
修改我的代码“选择暗像素(假设电线很暗)”。
更改Hough变换参数。
相关问题
- 1. Python频率检测
- 2. [portaudio]发送和检测频率 - 视窗
- 3. 声音频率检测
- 4. 检测视频量
- 5. 在Android上使用BoofCV检测视频中的路径
- 6. 检测原始音频(PCM)中的特定频率/音调
- 7. 如何检测视频中的文物?
- 8. 检测视频中的广告组
- 9. 检测视频文件中的脸部
- 10. 如何检测嵌入式视频编码比特率
- 11. c基本频率+语音检测#
- 12. DirectShow过滤器检测特定频率
- 13. 实时检测事件频率峰值
- 14. 检测禁用Youtube视频
- 15. Swift:检测视频结束
- 16. Affdex视频检测器
- 17. YouTube视频中的音频比特率?
- 18. 路线效率
- 19. OpenCV - 获取视频帧内检测到的图像的法线
- 20. 检测视图中的路由值
- 21. 从JavaScript中检测Youtube视频状态
- 22. 检测mp4视频的基线/配置文件
- 23. 虚拟音频的频率/音调检测
- 24. C#频率检索
- 25. 使用cordova插件的Android/ios中的频率检测?
- 26. MediaRecorder视频帧率
- 27. 建立在频域中具有频率(MHz)和功率值(DBM)
- 28. 从视频视频计算比特率
- 29. Python中的多路频率函数?
- 30. R中的三路频率表
感谢Rotem,你的例子对于单帧完美工作。但是,我试图将其应用于整个[视频](https://www.dropbox.com/s/m3j4or1dxxv3fmt/Eric_Video.avi?dl=0)。我试图使用implay,但仍然无法做到。你可以帮我吗 ? – ngoduyvu
您可以使用'VideoReader':[https://www.mathworks.com/help/matlab/ref/videoreader-object.html](https://www.mathworks.com/help/matlab/ref/videoreader- object.html),用于逐帧读取视频。单独为每个帧执行行检测并不是最好的方法,但这是一个好的开始。 – Rotem