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

Java 带有python后端的Android应用程序,java,android,python,neural-network,Java,Android,Python,Neural Network,嘿,我用python创建了一个神经网络,这个网络可以识别手写数字。我想在我的android应用程序中使用它。android应用程序将拍摄手写数字的照片,并将其发送到神经网络,神经网络将计算出数字并将其发送回应用程序。我该怎么做?我看了谷歌云平台,但我很困惑。我想知道如何将图片从应用程序发送到我的python神经网络,并将输出发送回。熟悉REST(RestEasy,Jersey,…)的概念,创建一个REST服务器,其端点可以接收包含base64图片的JSON字符串。应用程序使用base64转换图片

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

熟悉REST(RestEasy,Jersey,…)的概念,创建一个REST服务器,其端点可以接收包含base64图片的JSON字符串。应用程序使用base64转换图片并将其发送到REST服务器。在REST服务器中取消编码,将其委托给python脚本,将结果转换回JSON并发送回应用程序。应用程序本身接收JSON并从中获取数据

以下是使用WildFly server和RestEasy的方法:

//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);

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

以下是使用WildFly server和RestEasy的方法:

//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);