Ask Your Question

Revision history [back]

How to measure a pixel's color every frame of a video?

Let me preface this that I'm currently still learning python and just grabbing code out of places, putting stuff together and see what happens. I've just been messing around and now I'm just very deep into it.

I've successfully found code to stream a video in given coordinates. Now, I want to know how do you track whether a pixel has changed color. Say the pixel @ (640,860) is always black, but every now and then it will change to red for a few frames. How do I measure that pixel's color and check on it every frame?

This is my code for the video so far:

fourcc = cv2.VideoWriter_fourcc(*'XVID')
vid = cv2.VideoWriter('record.avi', fourcc, 8, (w,h))
while True :
    img = ImageGrab.grab(bbox = (x, y, x+w,y+h)) #bbox = (585, 700, 585+480,700+222)
    img_np = np.array(img)
    img_rgb = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB)
    cv2.imshow("", img_rgb)
    key = cv2.waitKey(1)
    if key == 27: