Convert ndarray to numpy (perform tracking on screenshot) [closed]
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.
sorry, but we cannot help with your 3rdparty screengrabbing library.
opencv can perform operations on the screenshot. So it fully relates to opencv. The screenshot is a numpy array.
again, we cannot help with your screenshot aqcuisition.
but btw, you have to enable a flag in the videowriter to write grayscale frames, like now it will just reject them.
I don't have a problem with the screenshot acquisition, I have a problem with the tracker.update(screen) part, since opencv returns 'False' for the 'ok' variable each time. Trying to convert that into a 'frame' (basically a frame from a webcam video) with screen.read() results in the above error.