1
我想获取下面图像中检测到的红色线中的坐标。 但是当我运行下面的代码,我得到的所有坐标(红色线及其他标识的对象):要获得红色线中的坐标
import cv2
import numpy as np
import matplotlib.pyplot as plt
filename = 'detectedRoof.jpg'
img = cv2.imread(filename)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv2.cornerHarris(gray, 2, 3, 0.04)
# Threshold for an optimal value, it may vary depending on the image.
img[dst > 0.01*dst.max()] = [255, 0, 0]
cv2.imwrite('outputsimple.jpg', img)
coord = np.where(np.all(img == (255, 0, 0), axis=-1))
lol = zip(coord[0], coord[1])
print(lol)
print ("")
x = np.array(lol, dtype="int")
print (x)
filename1 = open("coordinates_simple.txt", "w")
filename1.write(str(lol))
filename1.close()
plt.scatter(coord[0], coord[1])
plt.show()
输入图像
谁能帮助我得到的只有坐标的红色线条。