【发布时间】:2018-04-03 19:52:53
【问题描述】:
我需要找到特定于轮廓的坐标,如this image 所示。我能够绘制特定的轮廓(以红色突出显示),但 .txt 文件给出了相同的坐标集,即使我正在更改轮廓。
import numpy as np
import cv2
im = cv2.imread("ceramic.bmp")
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,55,255,0)
_th,contours, hierarchy =
cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
print" Number of contours detected %d.>"%len(contours)
cv2.drawContours(im,contours,55,(1,70,255)) #-1 fills it
area = cv2.contourArea(contours[55])
print (area)
cv2.imshow("Contours",im)
text_file = open("contour_list_55.txt", "w") ##### Write the
coordinates (x,y) of a contour in an txt file python
text_file.write( "%s"% contours)
text_file.close()
cv2.waitKey(0)
cv2.destroyAllWindows()`
【问题讨论】:
-
我们可以用数字标记每个轮廓,然后使用上面的代码很容易找到任何特定的轮廓。请为此提供帮助
标签: python coordinates opencv3.0 opencv-contour