用于测量应用的 Python 边缘检测

问题描述

我是 Python 新手,正在寻找单行或单列的边缘检测。我想做一个测量应用程序,我必须检测特定区域的边缘。

我尝试了两种方法。其中之一是 Sobel 边缘检测,但可能不会准确。

索贝尔法:

def findPoint(image,points,treshhold):
ROI=image[points[0]:points[1],points[2]:points[3]]
sobely = cv.sobel(ROI,cv.CV_64F,1,ksize=3)
sobely *= 255.0 / np.max(sobely)                 
sobely[sobely<0]=0                               
sobely=cv.GaussianBlur(sobely,(3,3),sigmaX=1)
sobely=sobely>treshhold
cv.rectangle(img,(points[2],points[0]),(points[3],points[1]),(255,0),2)

labeled = measure.label(sobely)
regions = measure.regionprops(labeled)

for props in regions:
    row,col = props.centroid
    row=row+points[0]
    col=col+points[2]
    rowi=int(row)
    coli=int(col)
    cv.circle(img,(coli,rowi),3,(0,255,-1)
return row,col
img = cv.imread("Resimler/3.jpg",0)
points1=[405,430,355,360]
trh1=30
points2=[360,385,310,315]
trh2=30

row1,col1=findPoint(img,points1,trh1)
row2,col2=findPoint(img,points2,trh2)
dist=abs(col2-col1)
cv.putText(img,"{} px".format(dist),(220,300),cv.FONT_HERShey_COMPLEX,2,3)

trying to get kind of mesaurement

我的第二次尝试是 subpixel_edges 库。

from subpixel_edges import subpixel_edges    
img = cv2.imread("Resimler/3.jpg")
img=cv2.GaussianBlur(img,(5,5),0)

img_gray = (cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)).astype(float)
points1=[360,315]
ROI=img_gray[points1[0]:points1[1],points1[2]:points1[3]]

edges = subpixel_edges(ROI,10,2)
print(edges.x,edges.y)

plt.imshow(img)
plt.quiver(edges.x+points1[2],edges.y+points1[0],edges.nx,-edges.ny,scale=30)
plt.show()

Here is Subpixel Result(i wrote it in same pattern as sobel method). It looks way better but i dont have data to test repeatebility.

对不起,弄得一团糟。就像我说的,我是 Python 新手。亚像素方法看起来不错,但它是进行这种测量应用的最佳方法吗?任何关于我想要的测量应用程序的建议都将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)