如何建立价值观之间的关系?

时间:2016-05-19 06:28:11

标签: python opencv

我有以下代码,它给出角落的坐标。但是,它只给出坐标。

import cv2
import numpy as np
import matplotlib.pyplot as plt

filename = 'CornerDetectionImage.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()] = [0, 0, 255]
cv2.imwrite('output.jpg', img)

coord = np.where(np.all(img == (0, 0, 255), axis=-1))

lol = zip(coord[0], coord[1])
print(lol)
print ("")

x = np.array(lol, dtype="int")
print (x)

filename1 = open("CoordinatesForCornerDetectionImage.txt", "w")
filename1.write(str(lol))
filename1.close()

filename2 = open("CoordinatesNpArray.txt", "w")
filename2.write(str(x))
filename2.close()

plt.scatter(coord[0], coord[1])
plt.show()

我使用的图像附在下面,

CornerDetectionImage

我不知道你是否能看到它,检测到的角落是红色的。 DetectedCorners

我已将A-U标记为检测到的角落的顺序。以下是结果(坐标)。

[(27, 37), (27, 38), (27, 163), (27, 164), (27, 266), (27, 267), (27, 356), (27, 357), (27, 448), (27, 449), (27, 528), (27, 529), (28, 37), (28, 38), (28, 163), (28, 164), (28, 266), (28, 267), (28, 356), (28, 357), (28, 448), (28, 449), (28, 528), (28, 529), (51, 163), (51, 164), (51, 266), (51, 267), (51, 356), (51, 357), (51, 448), (51, 449), (52, 61), (52, 62), (52, 163), (52, 164), (52, 266), (52, 267), (52, 280), (52, 305), (52, 306), (52, 356), (52, 357), (52, 448), (52, 449), (52, 504), (52, 505), (53, 61), (53, 62), (53, 280), (53, 281), (53, 305), (53, 306), (53, 504), (53, 505), (355, 61), (355, 62), (355, 280), (355, 281), (355, 305), (355, 306), (355, 504), (355, 505), (356, 61), (356, 62), (356, 280), (356, 281), (356, 305), (356, 306), (356, 504), (356, 505), (380, 37), (380, 38), (380, 528), (380, 529), (381, 37), (381, 38), (381, 528), (381, 529)]

我无法理解与这些坐标的关系。我想知道的是要理解一个带坐标的点与其他坐标一致。

例如,

A如何连接到B和T? B如何连接到A和H? C如何连接到I和D?

我如何建立这种关系?

1 个答案:

答案 0 :(得分:1)

这只是一个快速的建议(绝不是一个明确的答案)。

您可以尝试使用OpenCV LineIteratorhttp://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html#lineiterator)迭代检测到的角落之间的线条,并检查此线条上的每个像素附近是否有白色和黑色像素(在每个像素周围放一个小窗口)像素)。

这可能对您使用的图像起作用,但对于处理更复杂的图像可能过于天真。

相关问题