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

asked 2019-03-22 15:52:29 -0600

zAsdf gravatar image

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)
    vid.write(img_rgb)
    cv2.imshow("", img_rgb)
    key = cv2.waitKey(1)
    if key == 27:
        break
vid.release()
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

Comments

Do you understand your code? answer to your question is in your code

LBerger gravatar imageLBerger ( 2019-03-23 02:44:38 -0600 )edit