I try to do:
- take screenshot using python-mss
- resize and then convert to base64
- using JS load by ajax using python-flask request handler and paste the result to src attribute in img tag like
data:image/png;base64,{{base64}}
get_base64_screenshot.py
import mss, cv2, base64
import numpy as np
MSS = mss.mss()
# screenshot
frame_bytes = MSS.grab(MSS.monitors[2])
# BGRA -> RGB
frame_array = np.array(frame_bytes)
frame_array = np.flip(frame_array[:, :, :3], 2)
# resize
frame_resized = cv2.resize(frame_array, (640, 360), interpolation = cv2.INTER_CUBIC)
# base64
frame_base64 = base64.b64encode(frame_resized)
What am I doing wrong? I think it's wrong decoding.
