在学习一段代码的时候 有段代码阅读的不是很懂 该段代码的目的是通过旋转虚拟指针找到和原指针重合最高的地方 并求出角度
t1 = img.copy(); t1[temp[:, :, 2] == 255] = 255; c = img[temp[:, :, 2] == 255]; points = c[c == 0]; freq_list.append((len(points), i))
这五行代码就十分疑惑不知所云 不知道各位朋友能不能详细解惑一番
def get_pointer_rad(img):
shape = img.shape
c_y, c_x, depth = int(shape[0] / 2), int(shape[1] / 2), shape[2]
x1=c_x+c_x*0.8
src = img.copy()
freq_list = []
for i in range(361):
x = (x1 - c_x) * cos(i * pi / 180) + c_x
y = (x1 - c_x) * sin(i * pi / 180) + c_y
temp = src.copy()
cv2.line(temp, (c_x, c_y), (int(x), int(y)), (0, 0, 255), thickness=3)
t1 = img.copy()
t1[temp[:, :, 2] == 255] = 255
c = img[temp[:, :, 2] == 255]
points = c[c == 0]
freq_list.append((len(points), i))
cv2.imshow('d', temp)
cv2.imshow('d1', t1)
cv2.waitKey(1)
print('当前角度:',max(freq_list, key=lambda x: x[0]),'度')
cv2.destroyAllWindows()
return max(freq_list, key=lambda x: x[0])