我正在努力让我的代码工作! 图纸正在工作,只有螺纹不工作。在
我想检查图像中的一些点并将其存储在全局变量points中。因此,每一次鼠标点击都应该触发一个事件集,以继续到下一个要选择的点。在
当我第一次调用线程时,线程就开始了,我可以 在图像中创建一些圆圈,但不是我想要的那样。 程序在线程中卡住了,我只能用esc键停止它。在
即使是第一条打印消息也不会弹出。在
我真的很感谢你的回答!! 程序在没有e.wait()的情况下运行。所以我试着检查所有我想要的点,然后用esc键返回到另一个函数,但是这不是线程的工作方式吗?如果可能的话,我希望它能按照描述运行:)
非常感谢! 汉斯
import cv2
import cv
import time
import numpy as np
from threading import Thread
from threading import Event
import sys
points = []
e = Event()
key = Event()
winName3 = "hsv image colors?"
imCalRGB = np.zeros((512,512,3), np.uint8)
calibrationComplete = False
def calibrate():
cam = cv2.VideoCapture(0)
global imCalRGB
imCalRGB = np.zeros((512,512,3), np.uint8)
global calibrationComplete
global e
global key
e = Event()
key = Event()
calibrationComplete = False
while calibrationComplete == False:
cv2.namedWindow(winName3, cv2.CV_WINDOW_AUTOSIZE)
cv2.imshow(winName3, imCalRGB)
t = Thread(CalibrationWindowThread(imCalRGB), "Get Points")
t.start()
time.sleep(4)
print "Please select the center of the 20 points outermost rim."
e.wait()
e.clear()
cv2.circle(imCalRGB, points[0], 3,(255, 0, 0),2, 8)
cv2.imshow(winName3, imCalRGB)
print "Please select the center of the 3 points outermost rim."
e.wait()
e.clear()
cv2.circle(imCalRGB, points[1], 3,(255, 0, 0),2, 8)
cv2.imshow(winName3, imCalRGB)
print "Please select the center of the 11 points outermost rim."
e.wait()
e.clear()
cv2.circle(imCalRGB, points[2], 3,(255, 0, 0),2, 8)
cv2.imshow(winName3, imCalRGB)
print "Please select the center of the 6 points outermost rim."
e.wait()
e.clear()
cv2.circle(imCalRGB, points[3], 3,(255, 0, 0),2, 8)
cv2.imshow(winName3, imCalRGB)
height, width = imCalRGB.shape[:2]
...
def CalibrationWindowThread(im):
cv2.imshow(winName3, im)
cv2.setMouseCallback(winName3, on_mouse)
global key
while True:
if not key.is_set():
test = cv2.waitKey(1)
if test == 27:
#cv2.destroyWindow(winName3)
break
else:
break
def on_mouse(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
#events
global points
global e
#append user clicked points
points.append((x, y))
e.set()
print points
cv2.circle(imCalRGB, (x, y), 3,(255, 0, 0),2, 8)
cv2.imshow(winName3, imCalRGB)
#key.set()
if __name__ == '__main__':
print "Welcome to darts!"
calibrate()][1]
目前没有回答
相关问题 更多 >
编程相关推荐