codon icon indicating copy to clipboard operation
codon copied to clipboard

Any plans for opencv?

Open schnitzlein opened this issue 1 year ago • 3 comments

Hi I am just curious about this project.

Testing it with default libs works great. Than I go with written documentation for opencv2 aka cv2 ... along with matplotlib as plt.

But codon.codon_jit.JITError: ...codon_test.py: no module named 'cv2'

I try it with python3 and with codon run but seems not callable. Also with the explizit maker @python .

Any ideas?

greetings

schnitzlein avatar Mar 20 '23 13:03 schnitzlein

Hi @schnitzlein -- for libraries that aren't supported natively, you can do from python import <library>, e.g. from python import matplotlib. In JIT mode you can also pass the module to Codon with pyvars: https://docs.exaloop.io/codon/interoperability/decorator#passing-globals-to-codon -- e.g. @codon.jit(pyvars=['cv2']). Let me know if this solves your issue!

arshajii avatar Mar 20 '23 14:03 arshajii

Hi @arshajii thanks for the quick Reply, I will work with this hints!

Thanks

schnitzlein avatar Mar 21 '23 07:03 schnitzlein

Hi @arshajii I'm using your solution, but it takes longer than a simple Python solution.

`import codon from time import time import cv2 def is_prime_python(): img=cv2.imread("./01.jpg") a=0 for i in range(img.shape[0]): for j in range(img.shape[1]): a+=i*img.shape[0]+j print("is_prime_python") print(a) return True

@codon.jit(pyvars=["cv2"]) def is_prime_codon(): img=cv2.imread("./01.jpg") a=0 for i in range(img.shape[0]): for j in range(img.shape[1]): a+=i*img.shape[0]+j print("is_prime_codon") print(a)

return True

t0 = time() ans = is_prime_python() t1 = time() print(f'[python] {ans} | took {t1 - t0} seconds')

t0 = time() ans = is_prime_codon() t1 = time() print(f'[codon] {ans} | took {t1 - t0} seconds') `

image

mmmahdiii avatar Oct 17 '23 11:10 mmmahdiii