我的计算机视觉分配的上下文:计算同构矩阵,其中之一是创建一个GUI来选择图像上的点(以获取坐标和像素值(。
我已经浏览了stackoverflow,找到了一些选项,即使用TKINTER,但是答案是从2011年开始的。我想知道那里是否还有其他或新选项。
这是使用openCV 3.3.1对我有用的代码有关摄像机校准,请参阅我的github repo https://github.com/abhishek098/camera_calibration。
import numpy as np
import yaml
import cv2
'''
1. change the path to load image and store data
2. double click on the image to save the co-ordinates
3. images should be named as 0.jpg, 1.jpg, 2.jpg .....
4.
'''
# set image and data path here..
path = "/home/abhishek/stuff/object_detection/explore/"
points = []
def mouseCB(event,x,y,flags,param):
if event == cv2.EVENT_LBUTTONDBLCLK :
print (x, y)
points.append([x, y])
count = 0
exit_flag = True
points_list = []
while exit_flag:
window_name = 'image_' + str(count)
cv2.namedWindow(window_name)
cv2.setMouseCallback(window_name, mouseCB)
image_name = path + str(count) + '.jpg'
img = cv2.imread(image_name)
cv2.imshow(window_name, img)
while True:
ip = cv2.waitKey(0) & 0xFF
if ip == ord('n'):
count += 1
points_list.append(points)
points = []
cv2.destroyAllWindows()
break
elif ip == ord('q'):
exit_flag = False
break
print (count)
data = {'img_co': np.asarray(points_list).tolist()}
file = path + "data.yaml"
with open(file, "w") as f:
yaml.dump(data, f)
cv2.destroyAllWindows()