0
PythonError:
Traceback (most recent call last):
  File "/lib/python3.10/asyncio/futures.py", line 201, in result
    raise self._exception
  File "/lib/python3.10/asyncio/tasks.py", line 232, in __step
    result = coro.send(None)
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 506, in eval_code_async
    await CodeRunner(
  File "/lib/python3.10/site-packages/_pyodide/_base.py", line 357, in run_async
    coroutine = eval(self.code, globals, locals)
  File "", line 1, in
ModuleNotFoundError: No module named 'cv2'

Open Cv code should run with py-script

code:

import cv2
import numpy as np



def image_overlay(img1, img2, location):
    h1, w1 = img1.shape[:2]
    h2, w2 = img2.shape[:2]
    x, y =location
    img1[y:y+h2, x:x+w2] = img2

    return img1




if __name__ == '__main__':
    img1 = cv2.imread('img.png')
    overlay = cv2.imread('new.png')
    results = image_overlay(img1, overlay, location=(1, 1))
    print(results)
    # cv2.imshow('results', results)
    # cv2.imwrite("new.jpg", results)
    cv2.waitKey(0)
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • you didn't install packages. check [this](https://stackoverflow.com/a/41895783/20307768) out. – Constantin Hong Nov 22 '22 at 13:45
  • don't expect too much of pyscript. opencv is a binary library, not plain python. -- [tour], [ask], [mre] – Christoph Rackwitz Nov 22 '22 at 14:33
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 22 '22 at 14:40
  • `cv2` is a third-party library. It does not come built in to python. You have to install it yourself. Did you install it? – John Gordon Nov 22 '22 at 14:41
  • This has been covered already in [Is it possible to use OpenCV module in PyScript?](https://stackoverflow.com/a/72207892/8508004). Be sure to look into the '[UPDATE]' section and review versions. – Wayne Nov 22 '22 at 16:00
  • It does work in pyodide it seems. I just went to [JupyterLite main page](https://jupyterlite.readthedocs.io/en/latest/) and pressed 'Lab' in the upper left and was able to use it. (A lot of times the kernel would just hang and things had to be reloaded in the browser to get a notebook with a good start-up after dismissing I didn't want the demo.) Produced [this notebook](https://nbviewer.org/gist/fomightez/2277f4f55cfdb02ea6a7a5d3ca0e335f). **I know it isn't pyscript**, but it's much easier to work things out in an active JupyterLite session where the kernel is pyodide-based. – Wayne Nov 22 '22 at 17:03

0 Answers0