java python numpy,从Java运行python脚本(具有numpy依赖项)

在Java应用中,若需要使用依赖Numpy的Python图像处理算法,通常建议通过调用Python子进程来实现。将图片保存为临时文件,然后在Python脚本中处理,并返回结果。可以考虑设置一个简单的Python数据处理服务器,该服务器接收请求并返回处理后的数据。
摘要由CSDN通过智能技术生成

In a java application I need to use a specific image processing algorithm that is currently implemented in python.

What would be the best approach, knowing that this script uses the Numpy library ?

I alreayd tried to compile the script to java using the jythonc compiler but it seems that it doesn't support dependencies on native libraries like Numpy.

I also tried to use Jepp but I get an ImportError when importing Numpy, too.

Any suggestion ?

解决方案

If you're using Numpy you probably have to just use C Python, as it's a compiled extension. I'd recommend saving the image to disk, perhaps as a temporary file, and then calling the Python as a subprocess. If you're dealing with binary data you could even try memory mapping the data in Java and passing in in the path to the subprocess.

Alternatively, depending on your circumstances, you could set up a simple data processing server in Python which accepts requests and returns processed data.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值