【发布时间】:2017-01-03 05:55:37
【问题描述】:
# import the necessary packages
import decimal
import imutils
import cv2
import numpy as np
import matplotlib.pyplot as plt
# load the image, convert it to grayscale, and blur it slightly
image = cv2.imread("hand.jpg",0)
# threshold the image, then perform a series of erosions +
# dilations to remove any small regions of noise
thresh = cv2.threshold(image, 45, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.erode(thresh, None, iterations=2)
thresh = cv2.dilate(thresh, None, iterations=2)
# find contours in thresholded image, then grab the largest one
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
c = max(cnts, key=cv2.contourArea)
size = len(c);
refer_point = (207,130)
data = np.genfromtxt("data.txt", delimiter=',')
X = data[:,][:,0]
Y = data[:,][:,1]
for i in range(0,size):
dist1= (((abs(207-X))**2)+((abs(130-Y))**2))**(1.0/2.0)
dist3 = round(dist1,2)
print dist3
plt.plot([dist3])
plt.show()
我正在处理上面的代码。代码执行得很完美,但是图像的轮廓点完全错误。我在绘制图表后观察到了这个错误。帮我解决这个问题。
【问题讨论】:
-
这段代码 sn -p 的输入图像和输出是什么?
-
它们是图像,我无法在评论行中附加任何图像。
-
然后上传它们并在此处提供链接
-
@AnanthReddy 编辑您的帖子并上传图片。
-
您可以通过编辑帖子来上传您的图片。还是您找到了解决方案??
标签: python opencv opencv-contour