py4j

1、java端

package com.bd;
import py4j.GatewayServer;
import com.arcsoft.face.FaceFeature;

public class FaceMain {
    public Double getFeature(String path1, String path2){
        MyEntryPoint my = new MyEntryPoint();
        my.init();
        FaceFeature faceFeature = my.getInfo(path1);
        FaceFeature faceFeature2 = my.getInfo(path2);
        Double compareResult = my.compareFeature(faceFeature, faceFeature2);
        return compareResult;
    }


    public static void main(String[] args) {
        FaceMain app = new FaceMain();
        // py4j服务
        GatewayServer gatewayServer = new GatewayServer(app);

        gatewayServer.start();
        System.out.println("Gateway Server Started");
    }
}

2、python端

from py4j.java_gateway import JavaGateway

# 初始化


class CompareAvatar:
    def __init__(self, path):
        self.path = path

    def get_compare(self):
        gateway = JavaGateway()
        path1 = "D:\\img\\a.jpg"
        path2 = "D:\\img\\b.jpg"
        path3 = "D:\\img\\c.jpg"
        path4 = "D:\\img\\d.jpg"
        path_lst = [path1, path2, path3, path4]
        compare_lst =[]
        for path in path_lst:
            compare_res = gateway.entry_point.getFeature(self.path, path)
            compare_lst.append(compare_res)
        max_index = compare_lst.index(max(compare_lst))
        return path_lst[max_index]


if __name__ == '__main__':
    path = "D:\\img\\a.jpg"
    compare_avatar = CompareAvatar(path)
    res = compare_avatar.get_compare()
    print(res)

 

posted @ 2020-07-11 14:24  市丸银  阅读(235)  评论(0编辑  收藏  举报