我在Rosetta Code的 MATLAB中找到了Hough变换的实现,但是我无法理解它.另外我想修改它以显示原始图像和重建线(de-Houghing).
理解它和de-Houghing的任何帮助表示赞赏.谢谢
为什么图像会翻转?
theImage = flipud(theImage);
我无法绕过规范功能.它的目的是什么,是否可以避免?
编辑: norm只是欧几里德距离的同义词:sqrt(width ^ 2 + height ^ 2)
rhoLimit = norm([width height]);
有人可以解释如何/为什么计算rho,theta和houghSpace?
rho = (-rhoLimit:1:rhoLimit);
theta = (0:thetaSampleFrequency:pi);
numThetas = numel(theta);
houghSpace = zeros(numel(rho),numThetas);
Run Code Online (Sandbox Code Playgroud)我怎么能去霍夫空间来重建线条呢?
使用使用身份(眼睛)功能创建的对角线的10x10图像调用该功能
theImage = eye(10)
thetaSampleFrequency = 0.1
[rho,theta,houghSpace] = houghTransform(theImage,thetaSampleFrequency)
Run Code Online (Sandbox Code Playgroud)
实际功能
function [rho,theta,houghSpace] = houghTransform(theImage,thetaSampleFrequency)
%Define the hough space
theImage = flipud(theImage);
[width,height] = size(theImage);
rhoLimit = norm([width height]);
rho = (-rhoLimit:1:rhoLimit);
theta = (0:thetaSampleFrequency:pi);
numThetas = numel(theta);
houghSpace = zeros(numel(rho),numThetas);
%Find the "edge" …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用GPUImage的HoughTransform来检测名片的边缘,因为它似乎是使用此框架从我发现的类似问题/问题中实现此任务的最佳方式.
我能得到的最好结果就是将lineDetectionThreshold设置为0.25,这样就可以给出4行界定名片,同时最小化行总数.
我无法确定edgeThreshold参数是否有帮助.
通过我得到的线条,我将过滤掉彼此非常相似的线条(通常在每条边缘上找到很多!),将它们分成水平和垂直,然后找到2条水平线和2条垂直线,可以形成一个矩形.
由于文本或名片本身的形状,我仍然找到很多行,数字越大,视频流的性能越差.
我试图添加一些预处理,但不是很成功,可能是因为我不知道哪种技术可以帮助我.
如何才能改善仅确定边缘的4条线的检测?实际上,有可能吗?
编辑:
这里有一些图片来说明.我删除了名片中的徽标和详细信息以保护隐私.
使用0.25阈值获得的原始线(此阈值有时会在处理视频时丢失一些边缘)
使用相同图像手动过滤后的行:
另一个例子,虽然这可能更难,甚至添加预处理步骤:
原线:
过滤线:
image-processing edge-detection hough-transform ios gpuimage
我试图使用不同的方法检测灰度图像中的白色矩形:轮廓检测和霍夫变换.不幸的是,我正在处理的图像有一些限制,即
对于contonours方法,一些图像的轮廓被打破.此外,图像可能包含矩形等特征(例如字符"D").我不确定这是不是一个好方法.
我看过许多文章/论坛建议使用Hough变换检测矩形,如下面的帖子.不幸的是,我必须设置最小行长度的小值,并看到重复的行.我不知道如何处理上面提到的几点(例如,组合所有重复的行并为每个边选择一行,如何区分大多数部分的特征是线但是像'D'那样的小弧,以及如何隔离正方形,其中一条边与一条长直线合并,等等.
欢迎任何建议!
编辑:添加一些图片
角色D.
带徽标的矩形和边缘与长直线合并
梯形(顶部有阴影,底部形成梯形)
我有一组点,我需要使用它们的附近分组到相应的正弦线.我尝试使用标准Hough变换确定线条,但这并没有解决问题(只检测到几行).
我想测试RANSAC是否能更好地检测各种正弦曲线.你有类似算法的例子吗?
我知道RANSAC不是找到多行的最佳工具,所以我要做的是a)找到适合大多数点的函数; b)迭代搜索,仅考虑其余的搜索.
我在OpenCV中使用拉普拉斯变换进行边缘检测,然后使用霍夫线变换检测其中的线.这些识别的线最终需要从图像中移除.
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('Feb_16-0.jpg',0)
kernel = np.ones((1,1),np.uint8)
opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
blur = cv2.GaussianBlur(opening,(1,1),0)
ret3,th4 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
laplacian = cv2.Laplacian(th4,cv2.CV_8UC1)
cst = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
minLineLength = 100
maxLineGap = 10
lines = cv2.HoughLinesP(laplacian,1,np.pi/180,100,minLineLength,maxLineGap)
for x1,y1,x2,y2 in lines[0]:
cv2.line(cst,(x1,y1),(x2,y2),(0,255,0),2)
cv2.imwrite('houghlines5.jpg',cst)
Run Code Online (Sandbox Code Playgroud)
拉普拉斯边缘检测的结果如下:
而Hough Line Transform返回的结果只标识了下图中绿线所标记的一条线:
任何人都可以帮我弄清楚代码中需要进行哪些修改,以便识别出互联网法案的所有大胆的横向/纵向线?
python opencv image-processing computer-vision hough-transform
我试图检测图像中的弯曲输送机.我使用以下代码使用Hough变换来检测其边缘
%# load image, and process it
I = imread('ggp\2.jpg');
g = rgb2gray(I);
bw = edge(g,'Canny');
[H,T,R] = hough(bw);
P = houghpeaks(H,500,'threshold',ceil(0.4*max(H(:))));
% I apply houghlines on the grayscale picture, otherwise it doesn't detect
% the straight lines shown in the picture
lines = houghlines(g,T,R,P,'FillGap',5,'MinLength',50);
figure, imshow(g), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
deltaY = xy(2,2) - xy(1,2);
deltaX = xy(2,1) - xy(1,1);
angle = atan2(deltaY, deltaX) * 180 / pi;
if (angle == 0)
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green'); …
Run Code Online (Sandbox Code Playgroud) matlab image-processing computer-vision edge-detection hough-transform
我有一个图像,我试图将Hough圆形变换应用于视图中的圆形对象.
我很难找到一个适合气缸外部阴影的圆圈.可以做些什么来正确地分割这个阴影并轻松地适应它的圆圈?
码:
img = cv2.medianBlur(im,7)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
plt.imshow(cimg)
plt.show()
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
param1=50,param2=150,minRadius=100,maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(255,0,0),10)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),20)
radius = i[2]
print 'radius', radius, 'px'
plt.imshow(cimg)
plt.show()
Run Code Online (Sandbox Code Playgroud) 我的任务是找到线(startX,startY,endX,endY)和矩形(4条线)的坐标。这是输入文件:
我使用下一个代码:
img = cv2.imread(image_src)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, thresh1 = cv2.threshold(gray,127,255,cv2.THRESH_BINARY)
edges = cv2.Canny(thresh1,50,150,apertureSize = 3)
minLineLength = 100
maxLineGap = 10
lines = cv2.HoughLinesP(edges,1,np.pi/180,10,minLineLength,maxLineGap)
print(len(lines))
for line in lines:
cv2.line(img,(line[0][0],line[0][1]),(line[0][2],line[0][3]),(0,0,255),6)
Run Code Online (Sandbox Code Playgroud)
从上一张图像中,您可以看到大量的小红线。
问题:
在OpenCV 3.4.2中,添加了返回HoughLines()返回的每一行的投票数(累加器值)的选项.在python中,似乎支持以及在我的OpenCV安装的python docstring中读取:
"每条线由2或3个元素向量(ρ,θ)或(ρ,θ,votes)表示."
它也包含在文档中(有一些破碎的格式). 但是我找不到在python中返回3元素选项(ρ,θ,votes)的方法. 以下是演示此问题的代码:
import numpy as np
import cv2
print('OpenCV should be at least 3.4.2 to test: ', cv2.__version__)
image = np.eye(10, dtype='uint8')
lines = cv2.HoughLines(image, 1, np.pi/180, 5)
print('(number of lines, 1, output vector dimension): ', lines.shape)
print(lines)
Run Code Online (Sandbox Code Playgroud)
输出
OpenCV should be at least 3.4.2 to test: 3.4.2
(number of lines, 1, output vector dimension): (3, 1, …
Run Code Online (Sandbox Code Playgroud) 我试图使用HoughCircles检测下图中的圆圈.
这是我正在调整以找到所有圈子的代码.
import cv2
import numpy as np
img = cv2.imread("images/coins.jpg", 0)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
minDist = 247
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,minDist,
param1=170,param2=80,minRadius=0,maxRadius=0)
print(circles)
#print("Number of circles detected ", circles.length)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
对于我尝试的一切,我无法检测到一枚硬币.检测到的圆圈如下所示.
我这里有三个问题:
minDist
参数呢?你能解释一下它的工作原理吗?我阅读了文档,但无法理解.minRadius
和maxRadius
的zero
平均值在这里?