如何解决用于测量应用的 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()
对不起,弄得一团糟。就像我说的,我是 Python 新手。亚像素方法看起来不错,但它是进行这种测量应用的最佳方法吗?任何关于我想要的测量应用程序的建议都将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。