import js
import numpy as np
import cv2
def process_frame_with_opencv(video_element):
width, height = video_element.videoWidth, video_element.videoHeight
canvas = js.document.createElement("canvas")
canvas.width, canvas.height = width, height
ctx = canvas.getContext("2d")
ctx.drawImage(video_element, 0, 0, width, height)
image_data = ctx.getImageData(0, 0, width, height).data
frame = np.asarray(image_data, dtype=np.uint8).reshape((height, width, 4))
frame_bgr = cv2.cvtColor(frame, cv2.COLOR_RGBA2BGR)
return frame_bgr