python怎样调用opencv库,如何使用brython使用OpenCV python库

I have a fully functional Python project which have been tested directly through the terminal.

But when I searched on how to integrate Python code with a JavaScript wrapper, I found few of the open-source API's

http://www.brython.info/

http://www.skulpt.org/

http://pypyjs.org/

http://transcrypt.org/

http://stromberg.dnsalias.org/~strombrg/pybrowser/python-browser.html

I have used brython & was able to run few basic python codes

But my python project contain some import statements of libraries which I have installed directly into the OS

using

apt-get install python-opencv

apt-get install python-numpy

apt-get install python-skimage

apt-get install cython

pip install --user imutils

pip install --user scikit-image

And project contains import statements as

import imutils

from skimage.filter import threshold_adaptive

import numpy as np

import argparse

import cv2

My Aim is to be able to run my python code using the JavaScript wrapper on a Cordova project, but since these libraries will not be available by default, I tried downloading them & importing through local paths, but then I started facing many import errors & console errors thrown by brython is not understandable. I'm trying to build image processing software build using Python running on Cordova Android&iOS.

Any help would be appreciated.

Thanks in Advance

解决方案

Brython is a transpiler for Python code -

While it is nicely compliant to Python 3.5 implementation, it can, in no way, run native code. That is: projects that use native code, like openCV, among many others, can't run with Brython - as it does not "transpile" native x86 binaries into a compatible javascript object, like what it does with Python source code.

Other approaches like "skulpt" work diffrently: they compile the C code of the Python runtime itself into javascript - and if they have an option to compile binary Python modules along with the Python runtime, they could be made to work. (I am not familiar with Skulpt or the others client-side Python approaches to know if this is at least possible).

But even if it works, openCV take a lot of advantage of modern CPUs, inclding instructions SIMD, and likely even using the GPU. All of that would be emulated in Javascript (if it worked at all), bringing a performance loss of 3 or 4 orders of magnitude - not to mention the completly modified conditions for file I/O (as in: non existent - if no code you call has any file I/O side effects, you may get away with HTTP requests and HTML local storage).

There are efforts in the sense of running native-code on the Browser (nacl ) and other approaches, but I am not aware of the state of these, or these usng the cPython runtime on the browser.

What is possible then?

Have your image-dealing code server side, and build a backend that allows you to call RPC functions on the server, from code on the Brython side.

You just have to expose the desired openCV functionality in HTTP Views, using a common Python framework like Flask or Pyramid - setting up the code to transfer image data and operation meta-data between the browser and this server won't be a hard thing to do using Brython.

Another side note:

Brython won't allow you to import arbitrary files you've installed on your system - while it will likely work with any pure-Python3 code which does not perform I/O , the files have to be placed in specific paths, that are served through HTTP, so that Brython's import machinery can get them

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值