我有牛棚的视频。我想在那中间弄食物容器的角。我正尝试通过以下步骤来完成任务-
1. Freeze the video into the first frame (done using waitkey set to 0)
2. Pass the first frame into draw_circle function to get the corners
3. Play the video regularly after the first frame (done using changing waitkey value)
但是,我无法实现第二个目标。当框架冻结时,我单击了多个点,但鼠标列表仍然为空。有什么办法吗?下面提供了代码-
# import libraries
import cv2, numpy as np
# the point location will be saved into the mouse list
mouse = []
# define the function to get point location
def draw_circle(event,x,y,flags,param):
global ix,iy
if event == cv2.EVENT_LBUTTONDBLCLK:
cv2.circle(img,(x,y),100,(255,0,0),-1)
ix,iy = x,y
mouse.append([x,y])
# waitKey to freeze the video into the first frame
waitKey = 0
cap = cv2.VideoCapture("L2_clip2_16s.m4v")
while(True):
ret, frame = cap.read()
if ret:
cv2.imshow("res",frame)
# the first frame will be freezed and go through the draw_circle function
if waitKey ==0:
cv2.setMouseCallback("imshow",draw_circle)
key = cv2.waitKey(waitKey)
# when done taking point - click c to assign the value to waitkey and play the video normally
if key == ord("c"):
waitKey = 1
elif key== ord('q'):
break
else:
break
cv2.destroyAllWindows()
print (mouse)
答案 0 :(得分:0)
过程如下:
-创建一个新窗口
-附加mouseCallback
-在此窗口绘制框架
-在窗口中单击时,draw_circle函数称为
-要处理框架,请使用框架变量
-要查看更改,请重新绘制框架
mouseCallback只需要附加一次。
注意:由于存在 include ("true.html");
循环,因此无法访问代码中的print (mouse)
。
我已经修改了您的代码,以便可以使用。我只在修改代码的地方留下了注释。
while