gpt4 book ai didi

python - 如何建立值(value)观之间的关系?

转载 作者:行者123 更新时间:2023-12-02 17:45:11 24 4
gpt4 key购买 nike

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

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连接?

我如何建立这种关系?

最佳答案

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

您可以尝试使用OpenCV LineIterator(http://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html#lineiterator)遍历检测到的角之间的线,并检查该行上每个像素附近是否都有白色和黑色像素(在每个像素周围留一个小窗口)。

这可以在您使用的图像上工作,但是对于更复杂的图像来说可能太幼稚了。

关于python - 如何建立值(value)观之间的关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37315411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com