我已经取出了这张图片的激光曲线:
original image http://img4.hostingpics.net/thumbs/mini_367400simple21.png curve http://img4.hostingpics.net/thumbs/mini_646613curve.png
现在,我试图获得一组点(越多越好),这些点位于此曲线的中间。 我试图将图像分割成垂直条纹,然后检测质心。 但它并没有计算出很多分数,而且根本不满意!
img = cv2.Canny(img,50,150,apertureSize = 3)
sub = 100
step=int(img.shape[1]/sub)
centroid=[]
for i in range(sub):
x0= i*step
x1=(i+1)*step-1
temp = img[:,x0:x1]
hierarchy,contours,_ = cv2.findContours(temp, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
if contours <> []:
for i in contours :
M = cv2.moments(i)
if M['m00'] <> 0:
centroid.append((x0+int(M['m10']/M['m00']),(int(M['m01']/M['m00']))))
我也试过cv2.fitLine()
,但它也不令人满意。
如何有效地检测此曲线中间的点?问候。
答案 0 :(得分:0)
由于以下两个原因,我认为你得分较少:
请尝试以下方法。
# threshold the image using a threshold value 0
ret, bw = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY)
# find contours of the binarized image
contours, heirarchy = cv2.findContours(bw, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
# curves
curves = np.zeros((img.shape[0], img.shape[1], 3), np.uint8)
for i in range(len(contours)):
# for each contour, draw the filled contour
draw = np.zeros((img.shape[0], img.shape[1]), np.uint8)
cv2.drawContours(draw, contours, i, (255,255,255), -1)
# for each column, calculate the centroid
for col in range(draw.shape[1]):
M = cv2.moments(draw[:, col])
if M['m00'] != 0:
x = col
y = int(M['m01']/M['m00'])
curves[y, x, :] = (0, 0, 255)
我得到这样的曲线:
您还可以使用距离变换,然后获取与各个轮廓的每列相关的最大距离值的行。