프레임번호 :
import cv2
from js import document, setInterval, \
setTimeout, ImageData, Uint8ClampedArray, \
CanvasRenderingContext2D as Context2d
from pyodide.ffi import create_proxy, to_js
import asyncio
import gc
import numpy as np
상체인식 = cv2.CascadeClassifier('haarcascade_upperbody.xml')
하체인식 = cv2.CascadeClassifier('haarcascade_lowerbody.xml')
몸체인식 = cv2.CascadeClassifier('haarcascade_fullbody.xml')
캡쳐 = cv2.VideoCapture('pixabay-6387.mp4')
프레임번호 = 0
canvas = document.getElementById("view")
ctx = canvas.getContext("2d")
def draw_image(ctx, x, y, image):
data = Uint8ClampedArray.new(to_js(image.tobytes()))
height, width, _ = image.shape
image_data = ImageData.new(data, width, height)
ctx.putImageData(image_data, 0, 0, x, y, width, height)
def ShowFrame():
global 캡쳐, 그래프, cv2, 프레임번호, document, 상체인식, 하체인식, 몸체인식
캡쳐.set(cv2.CAP_PROP_POS_FRAMES, 프레임번호)
ret, frame = 캡쳐.read() # 두 개의 값을 반환하므로 두 변수 지정
reverse = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
판독된상체들 = 상체인식.detectMultiScale(reverse, maxSize = (100,100))
판독된하체들 = 하체인식.detectMultiScale(reverse, maxSize = (100,100))
판독된몸체들 = 몸체인식.detectMultiScale(reverse, maxSize = (120,220))
for (x, y, w, h) in 판독된상체들:
cv2.rectangle(reverse, (x, y), (x + w, y + h), (0, 255, 0, 255), 3)
for (x, y, w, h) in 판독된하체들:
cv2.rectangle(reverse, (x, y), (x + w, y + h), (0, 0, 255, 255), 3)
for (x, y, w, h) in 판독된몸체들:
cv2.rectangle(reverse, (x, y), (x + w, y + h), (255, 0, 0, 255), 1)
draw_image(ctx, 0, 0, reverse)
document.getElementById('frameNo').innerHTML=프레임번호
프레임번호=프레임번호+10
gc.collect()
setTimeout(ShowFrameProxy, 0)
ShowFrameProxy = create_proxy(ShowFrame)
setTimeout(ShowFrameProxy, 0)