Perform tracking on screenshot [closed]

asked 2019-05-23 13:25:59 -0500

I want to be able to take an opencv screenshot image, and apply image tracking to it. But I get this error:

AttributeError: 'numpy.ndarray' object has no attribute 'read'

I use win32api to take a screenshot, then convert it to a numpy array with opencv.

The tutorials I've looked at involved using a webcam, and apparently the frame that you would read from it using ___.read() is not the same as the opencv screenshot image.

I was thinking of using OBS or another streaming service to send a video to python, and then everything should work, but I've found nothing on that.

I've tried converting the screenshot to a video, then doing the read() function, but nothing works.

Main python file (in a while loop)

if __name__ == '__main__':
    screen = g.grab_screen(region = (0, 0, 640, 480))

    scr = screen.copy()

    screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)

    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    vid = cv2.VideoWriter('output.avi', fourcc, 6, (640,480))

    vid.write(screen)
    frame = screen.read()

    # Update tracker
    ok, bbox = tracker.update(frame)

grab_screen() comes from custom python file which uses win32api to take a screenshot, then return an image which you can then perform cv2.cvtcolour() on. This means that the screenshot is compatible with opencv. I want to be able to perform image tracking on the screenshot (which will become a video stream, in essence). In my mind, the screenshot is essentially the same thing as a frame in a webcam video.

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by berak
close date 2019-05-23 13:30:45.275744