# HeathCodeReg **Repository Path**: fplei/heath-code-reg ## Basic Information - **Project Name**: HeathCodeReg - **Description**: 健康码红黄蓝绿码识别 - **Primary Language**: Python - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: https://gitee.com/fplei/heath-code-reg - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 0 - **Created**: 2022-04-10 - **Last Updated**: 2022-11-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 健康码识别(红/黄/蓝/绿) 使用场景:后台将通过收集的所有健康码图片进行批量识别后,将红马、黄码人员通知到指定人,以便后续跟踪 环境:ubuntu20 python3.9 opencv4.5 jdk8 通过Java调用脚本的传参形式实现java和python交互 ``` class:CmdProcessUtils /** * 执行python脚本 * @param pythonFile * @param url * @return */ public synchronized static String invokePython(String pythonFile,String url){ if(org.apache.commons.lang3.StringUtils.isEmpty(url)){ return null; } try { String pythonPath=pythonFile; String[] args = new String[] { "python3", pythonPath, url}; Process proc = Runtime.getRuntime().exec(args);// 执行py文件 BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream())); String line = null; StringBuffer buffer=new StringBuffer(); while ((line = in.readLine()) != null) { buffer.append(line); } in.close(); proc.waitFor(); return buffer.toString(); } catch (Exception e) { e.printStackTrace(); } return null; } ``` 将脚本上传至服务器,直接调用,将脚本输出的json结果进行接受解析即可 `String _regResult = CmdProcessUtils.invokePython("xxx/HeathCodeReg.py", localPath);`