大佬教程收集整理的这篇文章主要介绍了OpenCV 图像距离计算故障排除,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在跟踪 the following tutorial 以确定图片中两个相似对象之间的距离。问题是,当我在自己的图片上运行代码时,程序似乎在奇怪的地方绘制了边界框。
我确定我需要调整某种超参数才能使框围绕正确的对象,问题是我不知道我需要调整原始代码中的哪些。任何见解?我已经在图片下方发布了我的代码以供参考。非常感谢您提供任何帮助。
代码
from scipy.spatial import distance as dist
from imutils import perspective
from imutils import contours
import numpy as np
import argparse
import imutils
import cv2
def mIDpoint(ptA,ptB):
return ((ptA[0] + ptB[0]) * 0.5,(ptA[1] + ptB[1]) * 0.5)
image = cv2.imread('D:\GIT\cover glass slIDe\VIDeo1_New_combined.jpg')
gray = cv2.cvtcolor(image,cv2.color_BGR2GRAY)
gray = cv2.GaussianBlur(gray,(7,7),0)
edged = cv2.CAnny(gray,50,100)
edged = cv2.dilate(edged,None,iterations=1)
edged = cv2.erode(edged,iterations=1)
cnts = cv2.findContours(edged.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
(cnts,_) = contours.sort_contours(cnts)
colors = ((0,255),(240,159),(0,165,(255,255,0),255))
refObj = None
for c in cnts:
if cv2.contourArea(C) < 100:
conTinue
Box = cv2.minAreaRect(C)
Box = cv2.cv.boxPoints(BoX) if imutils.is_cv2() else cv2.boxPoints(BoX)
Box = np.array(Box,dtype="int")
Box = perspective.order_points(BoX)
cX = np.average(Box[:,0])
cY = np.average(Box[:,1])
if refObj is None:
(tl,tr,br,bl) = Box
(tlblX,tlblY) = mIDpoint(tl,bl)
(trbrX,trbrY) = mIDpoint(tr,br)
D = dist.euclIDean((tlblX,tlblY),(trbrX,trbrY))
refObj = (Box,(cX,cY),D / 70)
conTinue
orig = image.copy()
cv2.drawContours(orig,[Box.astype("int")],-1,2)
cv2.drawContours(orig,[refObj[0].astype("int")],2)
refCoords = np.vstack([refObj[0],refObj[1]])
objCoords = np.vstack([Box,cY)])
for ((xA,yA),(xB,yB),color) in zip(refCoords,objCoords,colors):
cv2.circle(orig,(int(xA),int(yA)),5,color,-1)
cv2.circle(orig,(int(xB),int(yB)),-1)
cv2.line(orig,2)
D = dist.euclIDean((xA,yB)) / refObj[2]
(mX,mY) = mIDpoint((xA,yB))
cv2.putText(orig,"{:.1f}in".format(D),(int(mX),int(mY - 10)),cv2.Font_HERShey_SIMPLEX,0.55,2)
cv2.imshow("Image",orig)
cv2.waitKey(0)
cv2.destroyAllwindows()
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的OpenCV 图像距离计算故障排除全部内容,希望文章能够帮你解决OpenCV 图像距离计算故障排除所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。