目录

后端获取数据:

在ScoresController中的addd:

识别结果处理:

SampleTwo中的identity方法:


后端获取数据:

在ScoresController中的addd:

这个方法主要完成的工作包括:

1、解析前端传来的json,包括该课程的课程编号cs_id、课序号les_ord、图片对象数组imgimg。然后再对图片数组进行处理,提取数组中的图片对象对应的base64信息。

因为前端传的数据imgimg也是字符串格式,所以用字符串切割的处理方式,用picbase64=作为分隔符来进行字符串切割,进而获取每个图片的base64;

2、将处理后的base64信息图片传递给识别接口SampleTwo中的identify方法,该方法再完成识别的同时进行成绩的计算工作,然后将成绩返回给addd方法;

3、再由addd方法完成数据库update的调用,进而完成学生成绩的插入工作。

    /***   添加(图片上传的addd)** @param map* @return*/@AutoLog(value = "临时的临时成绩-添加-图片上传")@ApiOperation(value="临时的临时成绩-添加-图片上传", notes="临时的临时成绩-添加-图片上传")@PostMapping(value = "/addd")    public Result<String> addd(@RequestBody Map<String,Object> map) {//scoresService.save(scores);System.out.println("-----------test图片上传--------");String url = new String();String cs_id = new String();String les_ord = new String();String ScrMeth = new String();List<Pic> base64arr = new ArrayList<Pic>();Pic pic = new Pic();String base64 = "";int picnum = 0;String substr[] = new String[10];String picbase64[] = new String[10];if (map.containsKey("url")){url = map.get("url").toString();System.out.println(url);}if (map.containsKey("filename")){String filename = map.get("filename").toString();System.out.println(filename);}if (map.containsKey("imgimg")){Object list = map.get("imgimg");String liststr = list.toString();//System.out.println(liststr);String str[] = liststr.split("picuid");picnum = str.length-1;System.out.println("picnum = "+picnum);for(int i=0;i<picnum;i++){substr[i] = liststr.split("picbase64=")[i+1];picbase64[i] = substr[i].split("}")[0];// System.out.println(picbase64[i]);}}if(map.containsKey("cs_id")){cs_id = map.get("cs_id").toString();}if(map.containsKey("les_ord")){les_ord = map.get("les_ord").toString();}if (map.containsKey("ScrMeth")){ScrMeth = map.get("ScrMeth").toString();System.out.println(ScrMeth);}System.out.println("获取成功");
//       return "success";System.out.println("------识别(不带位置)------");String path_pic = MinioUtil.path_pic;System.out.println("path_pic in system= "+path_pic);//成绩比例处理int usualScores=-1;int testScores=-1;int scoreNum=-1;if(this.temporaryScores.getTestPercent()==null){this.temporaryScores.setTestPercent(0);}if(this.temporaryScores.getUsualPercent()==null){this.temporaryScores.setUsualPercent(0);}double test_percent=this.temporaryScores.getTestPercent()*0.01;double usual_percent = this.temporaryScores.getUsualPercent()*0.01;for(int j=0;j<picnum;j++) {String pic64 = picbase64[j];SampleTwo.ChangeForm(pic64);String path65 = "D:/aaa.jpg";List<List<Object>> Slist = SampleTwo.identify(path65,test_percent,usual_percent);//List<List<Object>> Slist = SampleTwo.identify(path_pic);//识别结果处理List<Object> scorelist = new ArrayList<Object>();Scores scores = new Scores();int Sl_lenth = Slist.size();for (int i = 0; i < Sl_lenth; i++) {scorelist = Slist.get(i);String stu_name = (String) scorelist.get(0);String stu_id = (String) scorelist.get(1);int exam_score = (int) scorelist.get(2);int usual_score = (int) scorelist.get(3);int test_score = (int) scorelist.get(4);int scr = (int) scorelist.get(5);String score = scr + "";if (ScrMeth.equals("评级制")) {score = UtilClass.ScrChange(score);}boolean a = scoresService.updateExamScores(exam_score, cs_id, les_ord, stu_id);boolean b = scoresService.updateUsualScores(usual_score, cs_id, les_ord, stu_id);boolean c = scoresService.updateTestScores(test_score, cs_id, les_ord, stu_id);boolean d = scoresService.updateScores(score, cs_id, les_ord, stu_id);if (a && b && c && d) {System.out.println(stu_id + " " + stu_name + " 同学的成绩插入成功");}}}return Result.OK("添加成功!");}
    <select id="updateUsualScores"  resultType="org.jeecg.modules.demo.ScoresInput.entity.Scores">update scoressetusual_Scores = #{usual_Scores}wherecs_id = #{cs_id} and stu_id=#{stu_id} and les_ord=#{les_ord}</select><select id="updateExamScores" resultType="org.jeecg.modules.demo.ScoresInput.entity.Scores">update scoressetexam_Scores = #{exam_Scores}wherecs_id = #{cs_id} and stu_id=#{stu_id} and les_ord=#{les_ord}</select><select id="updateScores"  resultType="org.jeecg.modules.demo.ScoresInput.entity.Scores">update scoressetscores = #{scores}wherecs_id = #{cs_id} and stu_id=#{stu_id} and les_ord=#{les_ord}</select><select id="updateTestScores" resultType="org.jeecg.modules.demo.ScoresInput.entity.Scores">update scoressettest_scores = #{test_scores}wherecs_id = #{cs_id} and stu_id=#{stu_id} and les_ord=#{les_ord}</select>

从前端获取到的图片的base64信息需要进行格式转换,方法如下:

    public static String ChangeForm(String basestr){String data = basestr;// System.out.println("data = "+data);String base64Data =  data.split(",")[1];// System.out.println("base64Data = "+base64Data);/*** 2.解码成字节数组*/Base64.Decoder decoder = Base64.getDecoder();byte[] bytes = decoder.decode(base64Data);/*** 3.字节流转文件*/FileOutputStream fos = null;try {try {fos = new FileOutputStream("D:\\aaa.jpg");} catch (FileNotFoundException e) {e.printStackTrace();}try {fos.write(bytes);} catch (IOException e) {e.printStackTrace();}return base64Data;} finally {if (fos != null){try {fos.close();} catch (IOException e) {e.printStackTrace();}}}}

识别结果处理:

上传的图片经过识别后是json格式的字符串,所以下面可以根据字符串的处理方式来对获得结果进行处理,进而获取我们想要的信息;

SampleTwo中的identity方法:

public class SampleTwo {//设置APPID/AK/SKpublic static final String APP_ID = "26041291";public static final String API_KEY = "3zSCXcXcHcw7KEHlk5SLOxug";public static final String SECRET_KEY = "z2HRbmgH7LNxH7AII2EmdLheKoHsj7aj";
……
}

identify方法主要完成的工作包括:

1、调用百度文字识别API,对ScoresControll中获得的图片进行识别,获取到识别结果的json形式的字符串;

2、对字符串进行处理:

需要考虑上传图片的格式不同的问题

3、将获取到的学生信息和对应成绩存入Scores实体的list中

再此过程中需要完成对成绩的计算工作,利用出入该方法的参数(平时成绩占比、实验成绩占比)算出学生的最终成绩score ;

    public static List<List<Object>> identify(String path,double test_percent,double usual_percent){// 初始化一个AipOcrAipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);// 可选:设置网络连接参数client.setConnectionTimeoutInMillis(2000);client.setSocketTimeoutInMillis(60000);// 可选:设置代理服务器地址, http和socket二选一,或者均不设置//client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理//client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理// 可选:设置log4j日志输出格式,若不设置,则使用默认配置// 也可以直接通过jvm启动参数设置此环境变量System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");// 调用接口JSONObject res = client.basicGeneral(path, new HashMap<String, String>());String string = "";List<List<Object>> Slist = new ArrayList<List<Object>>();try {int length = res.length();System.out.println("length = "+length);int num = res.getInt("words_result_num");// int num = Integer.parseInt(res.getString("word_result_num"));int row = num/5;System.out.println("num = "+num+", row = "+row);String s = res.toString();String str = s.substring(16);String strm = "";String stri = "";int m = 0;String stu_name = "";String stu_id = "";String score_exam = "";String score_usual = "";String score_lab = "";int sc_exam = 0;int sc_usual = 0;int sc_lab = 0;int score = 0;double a = test_percent;double b = usual_percent;double c = 1-a-b;String substr1 = str.split(":")[1];System.out.println("substr1 = "+substr1);String title = "报表";boolean withtitle = substr1.contains(title);System.out.println("withtitle = "+withtitle);String substr3 = str.split(":")[3];String header = "姓名";System.out.println("substr3 = "+substr3);boolean withheaderandtitle = substr3.contains(header);boolean withonlyheader = substr1.contains(header);for(int i=0;i<row-1;i++){System.out.println("------学生"+i+1+"-------");//strm = str.split(":")[i+1];// stri = strm.split("\"")[1];//System.out.println("strm = "+strm+"   stri = "+stri);for(int j=0;j<5;j++){System.out.println("------第"+j+1+"项-------"+j);//  String strj1 = str.split(":")[5*i+j+1+5];//   System.out.println("j = "+j);//   System.out.println("strj1 = "+strj1);String strj1 = "";if(withonlyheader){strj1 = str.split(":")[5*i+j+1+5];System.out.println("11"+strj1);}if(withtitle){strj1 = str.split(":")[5*i+j+1+7];System.out.println("22"+strj1);}if(!withtitle){if(!withonlyheader){strj1 = str.split(":")[5*i+j+1];System.out.println("33"+strj1);}}String strj2 = strj1.split("\"")[1];//  System.out.println("strj1 = "+strj1+", strj2 = "+strj2);switch(j){case 0:{stu_name = strj2;//      System.out.println("stu_name = "+stu_name+", j = "+j);break;}case 1:{stu_id = strj2;//   System.out.println("stu_id = "+stu_id+", j = "+j);break;}case 2:{score_exam = strj2;//  System.out.println("score_exam = "+score_exam+", j = "+j);sc_exam = UtilClass.checkNum(strj2);// sc_exam = Integer.parseInt(score_exam);//  System.out.println("sc_exam = "+sc_exam);break;}case 3:{score_usual = strj2;// System.out.println("score_usual = "+score_usual+", j = "+j);sc_usual = UtilClass.checkNum(strj2);//sc_usual = Integer.parseInt(score_usual);// System.out.println("sc_usaul = "+sc_usual);break;}case 4:{score_lab = strj2;// System.out.println("score_lab = "+score_lab+", j = "+j);sc_lab = UtilClass.checkNum(strj2);///sc_lab = Integer.parseInt(score_lab);// System.out.println("sc_lab = "+sc_lab);break;}}}double sc = 0;sc = a*sc_exam + b*sc_usual + c*sc_lab;score = (int) Math.round(sc);
//                score = Integer.parseInt(String.valueOf(sc));System.out.println("stu_name = "+stu_name+", stu_id = "+stu_id+", sc_exam = "+sc_exam+", sc_usual = "+sc_usual+", sc_lab = "+sc_lab+", score = "+score);List<Object> scoresList = new ArrayList<Object>();scoresList.add(0,stu_name);scoresList.add(1,stu_id);scoresList.add(2,sc_exam);scoresList.add(3,sc_usual);scoresList.add(4,sc_lab);scoresList.add(5,score);Slist.add(scoresList);}// System.out.println(res.toString(2));string = res.toString(2);} catch (JSONException e) {e.printStackTrace();}return Slist;}

IEMS_8_图片识别_2相关推荐

  1. Python实现图片识别加翻译,高薪必备技能

    Python使用百度AI接口实现图片识别加翻译 python python诞生30周年 encoding:utf-8 import requests import base64 from PIL im ...

  2. 物联网技术周报第 141 期: 使用 Alexa Voice 和 Raspberry Pi 构建图片识别应用

    新闻 \\ \\t <Ubuntu 16.04 LTS 已在英特尔 NUC 和物联网主板上获得认证>在全球拥有数百万用户的热门GNU/Linux发行版本--Ubuntu的背后公司Canon ...

  3. iOS--OCR图片识别

    应公司财务需求,要做一个收据识别功能.所以在网上搜索了下三方SDK,其中tesseract-ocr受到了大多数网友的推荐.我当然是前往https://github.com/gali8/Tesserac ...

  4. Atitit java 二维码识别 图片识别

    Atitit java 二维码识别 图片识别 1.1. 解码1 1.2. 首先,我们先说一下二维码一共有40个尺寸.官方叫版本Version.1 1.3. 二维码的样例:2 1.4. 定位图案2 1. ...

  5. plt保存图片_人工智能Keras CNN卷积神经网络的图片识别模型训练

    CNN卷积神经网络是人工智能的开端,CNN卷积神经网络让计算机能够认识图片,文字,甚至音频与视频.CNN卷积神经网络的基础知识,可以参考:CNN卷积神经网络 LetNet体系结构是卷积神经网络的&qu ...

  6. [验证码识别技术]-初级的滑动式验证图片识别

    初级的滑动式验证图片识别方案 1 abstract 验证码作为一种自然人的机器人的判别工具,被广泛的用于各种防止程序做自动化的场景中.传统的字符型验证安全性已经名存实亡的情况下,各种新型的验证码如雨后 ...

  7. DL之CNN:利用卷积神经网络算法(2→2,基于Keras的API-Functional)利用MNIST(手写数字图片识别)数据集实现多分类预测

    DL之CNN:利用卷积神经网络算法(2→2,基于Keras的API-Functional)利用MNIST(手写数字图片识别)数据集实现多分类预测 目录 输出结果 设计思路 核心代码 输出结果 下边两张 ...

  8. DL之CNN:利用卷积神经网络算法(2→2,基于Keras的API-Sequential)利用MNIST(手写数字图片识别)数据集实现多分类预测

    DL之CNN:利用卷积神经网络算法(2→2,基于Keras的API-Sequential)利用MNIST(手写数字图片识别)数据集实现多分类预测 目录 输出结果 设计思路 核心代码 输出结果 1.10 ...

  9. DL之DNN:利用DNN【784→50→100→10】算法对MNIST手写数字图片识别数据集进行预测、模型优化

    DL之DNN:利用DNN[784→50→100→10]算法对MNIST手写数字图片识别数据集进行预测.模型优化 导读 目的是建立三层神经网络,进一步理解DNN内部的运作机制 目录 输出结果 设计思路 ...

最新文章

  1. Tips_发送请求时添加一个随机数参数,让浏览器每次都重新发请求到服务器
  2. python爬虫实例-python爬虫实例大全
  3. Reverse Linked List
  4. 在ubuntu上实现基于webrtc的多人在线视频聊天服务
  5. Nacos发布0.5.0版本,轻松玩转动态 DNS 服务
  6. 中国程序员的前景并非一片黑暗,教你如何拥有光明的前程
  7. 翁恺老师C语言学习笔记(十一)字符串_字符串常量
  8. redhat7扩容linux,vmware中Centos 7 linux的LVM磁盘扩容
  9. AI安全隐患凸显,行业安全生态迫在眉睫
  10. win10 安装oracle11g R2的64位版本
  11. 大神带你实现 NLP 从入门到获奖,还有免费算力可以薅
  12. discuzx3.2自定义积分操作日志,discuzx积分二次开发完全记录
  13. 1,python基础入门
  14. GPyTorch中的超参数
  15. Slic3r基础知识
  16. android路由器安装wifidog,openwrt下的wifidog安装及web认证界面设置
  17. android 腾讯云聊天,腾讯云视频通话
  18. 【面试题】单链表的操作2
  19. FORCE_CONSTANTS中3阶力常数大小与原子间距的分析脚本
  20. ZYNQ开发系列——使用AXI4LITE接口进行PS和PL交互

热门文章

  1. FPGA串口接收学习
  2. 遇见--CondaHTTPError: HTTP 000 CONNECTION FAILED for url 怎么解决
  3. tkinter 小说编写器,文本编辑器,小说阅读器
  4. Python 魔法方法详解
  5. 百度首页天气html制作,使用百度天气API实现自己的天气预报
  6. 基于matlab的频率特性测试仪,基于虚拟仪器的网络频率特性测试仪
  7. Android开发中长度单位简介
  8. java计算机毕业设计中国民航酒店分销系统源码+系统+lw+数据库+调试运行
  9. HP打印机显示状态出错
  10. 苹果恢复出厂设置系统也会还原吗_手机出毛病了就恢复出厂设置,会损伤手机吗?影响有多大呢...