【发布时间】:2022-09-23 05:17:37
【问题描述】:
我正在尝试获取附加图像中框边缘的坐标[x, y]。
这是我用来获取边缘坐标的图像:
我发现很难获得。任何人,请帮助我获得坐标。
image= Image.open(r\"C:/Users/LikithP/OneDrive - Ennoventure Inc/Documents/Projects/Gold_Bar/finding_corner_points/mask_images/enc-1.jpg\")
numpy_data=np.array(image)
img = numpy_data[:,:,0]
_, th = cv2.threshold(img, img.mean(), 255, cv2.THRESH_BINARY_INV)
th = cv2.morphologyEx(th, cv2.MORPH_CLOSE, np.ones((3,3)))
x1, y1 = 0, 0
y2, x2 = th.shape[:2]
while np.all(th[:,x1]==255):
x1 = x1+1
while np.all(th[:,x2-1]==255):
x2 = x2-1
while np.all(th[y1,:]==255):
y1 = y1+1
while np.all(th[y2-1,:]==255):
y2 = y2-1
cv2.imwrite(\"image.jpg\",image[y1:y2-1,x1:x2-1])
这给出了错误TypeError: \'JpegImageFile\' object is not subscriptable
-
看起来像一个错字。最后一行,在 cv2.imwrite() 中,您索引对象而不是应该是 img 而不是图像的实际图像。