当前位置:   article > 正文

百科荣创嵌入式android_百科荣创安卓

百科荣创安卓

2个二维码按钮分别是红色二维码识别和多个二维码识别

本项目是将yolov5训练好的模型转换为tflite模型进行部署

python export.py --weights yolov5s.pt --include tflite --img 640

这段代码采用了多线程的方式,使得模型的加载过程可以在后台进行,不影响主线程的UI交互。这样能够保持应用的流畅性和响应性。

  1. //===============================模型初始化========================================
  2. private void Preload(){
  3. executor.execute(new Runnable() {
  4. @Override
  5. public void run() {
  6. try {
  7. detector_shape=DetectorFactory.getDetector(getAssets(),
  8. "graphics/yolov5s-fp16.tflite");//图形模型
  9. detector_shape.useCPU();
  10. detector_light = DetectorFactory.getDetector(getAssets(), "light/yolov5s-fp16.tflite");//红绿灯模型
  11. detector_light.useCPU();
  12. detector_flag = DetectorFactory.getDetector(getAssets(), "Trafflc_Flag/yolov5s-fp16.tflite");//交通标识物模型
  13. detector_flag.useCPU();
  14. detector_tv=DetectorFactory.getDetector(getAssets(),"Tv/yolov5s-fp16.tflite");//红色二维码模型
  15. detector_tv.useCPU();
  16. detector_qr=DetectorFactory.getDetector(getAssets(),"qr/qr.tflite");//二维码模型
  17. detector_qr.useCPU();
  18. }catch (final IOException e){
  19. e.printStackTrace();
  20. }
  21. }
  22. });
  23. }

detector_tv是要使用的模型   bitmap:要识别的图片 

最终返回的results是识别后的类别名称,坐标,准确率

handleResult类用于在bitmap图片上画出识别到的框以便观察是否识别正确

  1. //开始识别
  2. List<Classifier.Recognition>results=detector_tv.recognizeImage(bitmap);
  3. System.out.println(results);
  4. // 2显示识别结果
  5. handleResult(bitmap, results);

想要代码可私聊

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/847603
推荐阅读
相关标签
  

闽ICP备14008679号