Window solution for pyscript

تبليغ
سؤال

يرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.

تبليغ
‎إلغاء

according what I’ve countered recently in py-script. you can’t open any window with it because it renders on to your browser.

so how we can solve this problem and modify our program to show the result without opening a window ?

for example in this background subtraction code :

import numpy as np
import cv2

cap = cv2.VideoCapture(‘walking.avi’)

# Initlaize background subtractor
foreground_background = cv2.createBackgroundSubtractorMOG2()

while True:

ret, frame = cap.read()

# Apply background subtractor to get our foreground mask
foreground_mask = foreground_background.apply(frame)

cv2.imshow(‘Output’, foreground_mask)
if cv2.waitKey(1) == 13:
break

cap.release()
cv2.destroyAllWindows()

it is just a normal code and works well, but when I’m trying to implement this to pyscript
I get an error like this :

it complains about imshow part of the opencv and also the waitKey part of the code.

it seems py-script works totally different in terms of event and keys and windows.

this is the complete snippet of my py-script project:

<!DOCTYPE html>
<html lang=”en”>
<head>
<link rel=”stylesheet” href=”https://pyscript.net/alpha/pyscript.css” />
<script defer src=”https://pyscript.net/alpha/pyscript.js”></script>
<py-config>
– autoclose_loader: true
– runtimes:

src: “https://cdn.jsdelivr.net/pyodide/v0.21.0a2/full/pyodide.js”
name: pyodide-0.20
lang: python
</py-config>

<title>PYScript</title>
</head>

<body>

<py-env>
– matplotlib
– numpy
– opencv-python
– paths:
– /1.mp4
</py-env>

<py-script>
import matplotlib.pyplot as plt
import numpy as np
import cv2

cap = cv2.VideoCapture(‘1.mp4’)

foreground_background = cv2.createBackgroundSubtractorMOG2()

while True:

ret, frame = cap.read()

foreground_mask = foreground_background.apply(frame)

cv2.imshow(‘Output’, foreground_mask)
if cv2.waitKey(1) == 13:
break

cap.release()
cv2.destroyAllWindows()
</py-script>

</div>
</body>
</html>

‫أضف إجابة

تصفح
تصفح

مجهول يجيب