首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有python后端的Android应用程序

带有python后端的Android应用程序
EN

Stack Overflow用户
提问于 2016-01-18 06:54:11
回答 1查看 871关注 0票数 1

嘿,我用python创建了一个神经网络,这个网络可以识别手写数字。我想在我的android应用程序中使用这个。android应用程序将拍摄一张手写数字的照片,并将其发送到神经网络,神经网络将计算出该数字并将其发送回应用程序。我该怎么做?我看了谷歌云平台,但我很困惑。我想知道如何将图片从应用程序发送到我的python神经网络,并将输出发回。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-18 07:21:57

熟悉REST的概念(RestEasy、泽西、.),创建一个具有端点的REST服务器,该端点可以接收包含base64图片的JSON字符串。该应用程序使用base64转换图片并将其发送到REST服务器。在REST服务器中解压缩它,将其委托给python脚本,将结果转换回JSON并将其发送回应用程序。应用程序本身接收JSON并从中获取数据。

这就是我使用WildFly服务器和RestEasy所做的工作:

代码语言:javascript
复制
//app side 
PictureInputBo pictureInputBo = new PictureInputBo([your binary]); //encodes it to base64

//This is working Java code and can be used.
//It will automatically convert to JSON and sent to the "convert" endpoint of the server
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("http://yourserver:8080/your-webservice/rest/convert/");
Response response = target.request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(pictureInputBo, "application/json;charset=UTF-8;version=1"));


//Server side..."Converter Endpoint", this is also working Java code.
//it will automatically converted back to the Java object "PictureInputBo" by RestEasy
@POST
@Path("/convert")
@Consumes(MediaType.APPLICATION_JSON)
public Response convertPicture(@NotNull(message = "Must not be null") @Valid PictureInputBo inputBo)
{
    //Here you pass your business object to the converter service which processes the data
    //(pass it to python or whatever) 
    PictureOutputBo result = converterService.convert(inputBo);

    //Resteasy converts it back to JSON and responds it to the app.
    return Response.ok().entity(result).build();
}


//Back in your app.
check if response.getStatus() == 200) //HTTP Status OK
PictureOutputBo pictureOutputBo = response.readEntity(PictureOutputBo.class);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34848817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档