Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 视频中的线功率检测_Matlab_Image Processing - Fatal编程技术网

Matlab 视频中的线功率检测

Matlab 视频中的线功率检测,matlab,image-processing,Matlab,Image Processing,我有一个小项目“检测列车上的电线”使用Matlab 。我用红色圈出的电线是我需要检测的 我尝试了egde检测,但不知道下一步该怎么做。有人能提出一些方法吗?以下是可用于测线的。的链接 我的大部分文章都基于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 pixe

我有一个小项目“检测列车上的电线”使用Matlab

。我用红色圈出的电线是我需要检测的

我尝试了egde检测,但不知道下一步该怎么做。有人能提出一些方法吗?以下是可用于测线的。

的链接

我的大部分文章都基于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');
%从imgur读取输入图像
I=imread('https://i.stack.imgur.com/EcHfy.png');
J=零(尺寸(I,1),尺寸(I,2));
%选择暗像素(假定导线是暗的)。
J((I(:,:,1)<80)和(I(:,:,2)<80)和(I(:,:,3)<80))=1;
%数字;imshow(J);
%使用边缘函数查找图像中的边缘。
BW=边缘(J,'canny');
%数字;imshow(BW);
%计算边缘返回的二值图像的Hough变换。
[H,θ,rho]=hough(BW);
%显示由hough函数返回的变换H。
%数字;imshow(imadjust(mat2gray(H))、[]、‘扩展数据’、‘θ’、‘YData’、‘rho’、‘初始放大’、‘拟合’;
%xlabel(“\θ(度)”;ylabel('\rho');轴心;轴法线;等等彩色地图(gca、hot);
%使用houghpeaks函数查找Hough变换矩阵H中的峰值。
P=小时峰值(H,5,'阈值'),ceil(0.3*最大值(H(:)));
%在识别峰值的变换图像上叠加一个图。
%x=θ(P(:,2));y=rho(P(:,1));绘图(x,y,'s','color','black');
%使用houghlines函数查找图像中的线条。
直线=houghlines(BW、θ、ρ、P、'FillGap',50、'MinLength',7);
%创建一个打印,显示原始图像,并在其上叠加线条。
图,imshow(I),稍等
最大长度=0;
对于k=1:长度(线)
xy=[行(k).point1;行(k).point2];
绘图(xy(:,1),xy(:,2),“线宽”,2,“颜色”,“绿色”);
%绘制线的起点和终点
绘图(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
绘图(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
%确定最长线段的端点
len=范数(直线(k).点1-直线(k).点2);
如果(长度>最大长度)
max_len=len;
xy_long=xy;
结束
结束
%突出显示最长的线段
绘图(xy_-long(:,1),xy_-long(:,2),“线宽”,“颜色”,“红色”);
结果:

备注:
您可以使用形态学操作来改进结果。
修改我的代码“选择暗像素(假设导线是暗的)。

更改Hough变换参数

感谢Rotem,您的示例非常适合单帧。然而,我试着将其应用于整体。我试着用implay,但还是做不到。你能帮我吗?你可以使用
视频阅读器
:,逐帧读取视频。对每一帧分别执行行检测不是最好的方法,但这是一个良好的开端。