I am trying to draw a circle in a video frame but I have problem, for example:
vid1=cv2.VideoCapture('animal_video.mp4')
if vid1.isOpened():
print('is opened')
def mousedf(event,x,y,flags,params):
global nx,ny
if event == cv2.EVENT_LBUTTONDOWN:
nx,ny=x,y
if flags & cv2.EVENT_FLAG_LBUTTON:
radius=int(math.sqrt((x-nx)**2+(y-ny)**2))
cv2.circle(frame,(nx,ny),radius,(0,0,200),3)
cv2.namedWindow('frame')
cv2.setMouseCallback('frame',mousedf)
while True:
ret,frame=vid1.read()
if not ret:
print('Not enough Frame, will break')
break
k=cv2.waitKey(30)
if k == 27:
break
cv2.imshow('frame',frame)
vid1.release()
cv2.destroyAllWindows()
In the above code, I can see the circle in each frame.
However, if I change the order of cv2.imshow() and cv2.waitkey(),
I cannot see the circle.
while True:
ret,frame=vid1.read()
if not ret:
print('Not enough Frame, will break')
break
cv2.imshow('frame',frame)
k=cv2.waitKey(30)
if k == 27:
break
I would like to know the reason of the problem, and the relationship between cv2.setMouseCallback() and cv2.waitkey().