Python边缘检测在测量中的应用

Python边缘检测在测量中的应用,python,opencv,scikit-image,edge-detection,Python,Opencv,Scikit Image,Edge Detection,我是Python新手,希望在单行或列上进行边缘检测。我想做一个测量应用程序,我必须检测特定区域的边缘 我尝试了两种方法。其中之一是Sobel边缘检测,但它可能不会精确 索贝尔法: def findPoint(image,points,treshhold): ROI=image[points[0]:points[1],points[2]:points[3]] sobely = cv.Sobel(ROI,cv.CV_64F,0,1,ksize=3) sobely *= 255.0 / np.max(

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

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

索贝尔法:

def findPoint(image,points,treshhold):
ROI=image[points[0]:points[1],points[2]:points[3]]
sobely = cv.Sobel(ROI,cv.CV_64F,0,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,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,0),-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,(255,0,0),3)


抱歉搞砸了。就像我说的,我是python新手。亚像素法看起来不错,但它是最好的方法,使这样的测量应用?我想提出的任何关于测量应用的建议都将不胜感激。

欢迎来到SE。这里我们不是一般性的讨论论坛。您的问题是一般性的,要求提供建议/建议,但在这里我们对具体问题给出具体的答案。你能试着问一个更具体的问题吗?谢谢你的回答。我只是以亚像素的精度检测单行中的边缘。“我没有数据来测试可重复性。”:如果你想进行认真的测量,测试可重复性是绝对必要的。
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,385,310,315]
ROI=img_gray[points1[0]:points1[1],points1[2]:points1[3]]

edges = subpixel_edges(ROI, 10, 1, 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()