Questions about build new extension with RPython
Hi all, I am a newbie in PyPy. But with some experience in CPython, and also OpenCV-Python binding and OpenCV-Julia binding.I want to bring OpenCV into PyPy. Then use PyPy to do my research. First, I read some PyPy and RPython document in recent days. I want to wrap OpenCV in PyPy in "low level". Like OpenCV-CPython, it use Python-C API and Numpy C-API to wrap function and class. Then write a autowrap script to wrap it. In this way, OpenCV-CPython can communicate with NumPy array type. If my understanding is correct. NumPy-PyPy wrote in RPython, wrap the corresponding C and Fortran function. I want wrap OpenCV in PyPy just like OpenCV-CPython. Let NumPy ndarray hold the image matrix. But RPython documentation said "It(Write with RPython) cannot be used by any 3rd-party module". Does it mean if wrap OpenCV in PyPy with cffi. OpenCV-PyPy could not use ndarray? I plan to use RPython, but RPython documentation said it need rebuild PyPy it self, and the module write in RPython will become a built-in module. Rebuild PyPy seems unacceptable in OpenCV-PyPy. Is there has a way to wrap OpenCV in PyPy that could communicate with NumPy-PyPy and without rebuild PyPy it self? Please correct me if my understanding was wrong. Regards, Sun
Hi Boxiang. You're far better off doing it with cffi and writing part of it in C (pure C) or Python. Cffi on pypy is quite well optimized and should not really present a performance overhead. On Sun, Jun 21, 2015 at 1:33 AM, Boxiang Sun <daetalusun@gmail.com> wrote:
Hi all,
I am a newbie in PyPy. But with some experience in CPython, and also OpenCV-Python binding and OpenCV-Julia binding.I want to bring OpenCV into PyPy. Then use PyPy to do my research.
First, I read some PyPy and RPython document in recent days. I want to wrap OpenCV in PyPy in "low level". Like OpenCV-CPython, it use Python-C API and Numpy C-API to wrap function and class. Then write a autowrap script to wrap it. In this way, OpenCV-CPython can communicate with NumPy array type.
If my understanding is correct. NumPy-PyPy wrote in RPython, wrap the corresponding C and Fortran function.
I want wrap OpenCV in PyPy just like OpenCV-CPython. Let NumPy ndarray hold the image matrix. But RPython documentation said "It(Write with RPython) cannot be used by any 3rd-party module". Does it mean if wrap OpenCV in PyPy with cffi. OpenCV-PyPy could not use ndarray?
I plan to use RPython, but RPython documentation said it need rebuild PyPy it self, and the module write in RPython will become a built-in module. Rebuild PyPy seems unacceptable in OpenCV-PyPy.
Is there has a way to wrap OpenCV in PyPy that could communicate with NumPy-PyPy and without rebuild PyPy it self?
Please correct me if my understanding was wrong.
Regards, Sun
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev
Hi Boxiang, On 21 June 2015 at 01:33, Boxiang Sun <daetalusun@gmail.com> wrote:
Does it mean if wrap OpenCV in PyPy with cffi. OpenCV-PyPy could not use ndarray?
I don't know OpenCV myself, but writing a CFFI module accessing it should be easy, even if there are functions that take numpy arrays. You can do: ffi.from_buffer(some_ndarray) which returns a ffi ``char *`` pointer, pointing to the data from the ndarray. You can pass this raw pointer to C functions from OpenCV. There is no copy of the data; if the C function modifies the data, it will be modified in the numpy array too. A bientôt, Armin.
Thanks to Armin and Maciej. I will try to build a OpenCV-PyPy prototype with cffi first. Regards, Sun 2015-06-21 19:04 GMT+08:00 Armin Rigo <arigo@tunes.org>:
Hi Boxiang,
On 21 June 2015 at 01:33, Boxiang Sun <daetalusun@gmail.com> wrote:
Does it mean if wrap OpenCV in PyPy with cffi. OpenCV-PyPy could not use ndarray?
I don't know OpenCV myself, but writing a CFFI module accessing it should be easy, even if there are functions that take numpy arrays. You can do:
ffi.from_buffer(some_ndarray)
which returns a ffi ``char *`` pointer, pointing to the data from the ndarray. You can pass this raw pointer to C functions from OpenCV. There is no copy of the data; if the C function modifies the data, it will be modified in the numpy array too.
A bientôt,
Armin.
participants (3)
-
Armin Rigo
-
Boxiang Sun
-
Maciej Fijalkowski