Hey guys, I am doing an exercise in which the program has to follow that routine: when the user clicks on any point of a video, it gets that pixel and turns all pixels in a range of 5% into red. Since it is a vidoe, I am saving the points (x,y) the user clicks in a list and making the retangle for every point. Here is the code: import numpy as np import cv2
cap =cv2.VideoCapture(-1)
creates list
lista= []
mouse callback function
def getpixel(event,x,y,flags,param):
# adds point (x,y) in pixels ont the current list
if event == cv2.EVENT_LBUTTONDOWN:
lista.append([x,y])
print (x,y),img[x][y]
while(cap.isOpened()): ret,img= cap.read() if ret: cv2.imshow('image',img) cv2.setMouseCallback('image',getpixel) i=0 #draw the retangle while i<lista.__len__(): img[int(0.95<em="">lista[i][0]):int(1.05lista[i][0]),int(0.95lista[i][1]):int(1.05lista[i][1])]=(0,0,255) i+=1 if cv2.waitKey(20) & 0xFF == 27: break
cap.release() cv2.destroyAllWindows()
I have already checked and it is creating the list, adding the points and entering in the "while" part of the code. However, I can't see the retangles. What am I missing?