OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 20|回复: 0

《ESP32-S3使用指南—IDF版 V1.6》第六十一章 二维码识别实验

[复制链接]

1198

主题

1212

帖子

2

精华

超级版主

Rank: 8Rank: 8

积分
5165
金钱
5165
注册时间
2019-5-8
在线时间
1291 小时
发表于 2 小时前 | 显示全部楼层 |阅读模式
第六十一章 二维码识别实验

1)实验平台:正点原子DNESP32S3开发板

2)章节摘自【正点原子】ESP32-S3使用指南—IDF版 V1.6

3)购买链接:https://detail.tmall.com/item.htm?&id=768499342659

4)全套实验源码+手册+视频下载地址:http://www.openedv.com/docs/boards/esp32/ATK-DNESP32S3.html

5)正点原子官方B站:https://space.bilibili.com/394620890

6)正点原子DNESP32S3开发板技术交流群:132780729

2.jpg

3.png

乐鑫ESP-WHO二维码识别是乐鑫公司推出的二维码识别技术。该技术通过特定的算法和程序,可以快速、准确地识别二维码,读取其中的数据并进行相应的处理。本章,我们使用乐鑫AI库来实现二维码识别功能。
本章分为如下几个部分:
61.1 硬件设计
61.2 软件设计
61.3 下载验证


61.1 硬件设计

1. 例程功能
本章实验功能简介:使用乐鑫官方的ESP32-WHO AI库对OV2640和OV5640摄像头输出的数据进行二维码识别。

2. 硬件资源
1)LED灯
        LED-IO1
2)XL9555
        IIC_INT-IO0(需在P5连接IO0)
        IIC_SDA-IO41
        IIC_SCL-IO42
3)SPILCD
        CS-IO21
        SCK-IO12
        SDA-IO11
        DC-IO40(在P5端口,使用跳线帽将IO_SET和LCD_DC相连)
        PWR- IO1_3(XL9555)
        RST- IO1_2(XL9555)
4)CAMERA
        OV_SCL-IO38
        OV_SDA- IO39
        VSYNC- IO47
        HREF- IO48
        PCLK- IO45
        D0- IO4
        D1- IO5
        D2- IO6
        D3- IO7
        D4- IO15
        D5- IO16
        D6- IO17
        D7- IO18
        RESET-IO0_5(XL9555)
        PWDN-IO0_4(XL9555)

3. 原理图
本章实验使用的KPU为ESP32-S3的内部资源,因此并没有相应的连接原理图。

61.2 软件设计

61.2.1 程序流程图
程序流程图能帮助我们更好的理解一个工程的功能和实现的过程,对学习和设计工程有很好的主导作用。下面看看本实验的程序流程图:

第六十一章 二维码识别实验780.png
图61.2.1.1 程序流程图

61.2.2 程序解析
在本章节中,我们将重点关注两个文件:esp_qr_detection.cpp和esp_qr_detection.hpp。其中,esp_qr_detection.hpp主要声明了esp_qr_detection函数,其内容相对简单,因此我们暂时不作详细解释。本章节的核心关注点是esp_qr_detection.cpp文件中的函数。
接下来,我们将详细解析esp_qr_detection_ai_strat函数的工作原理。
  1. <font size="3">TaskHandle_t camera_task_handle;</font>
  2. <font size="3">QueueHandle_t xQueueAIFrameO = NULL;</font>

  3. <font size="3">/**</font>
  4. <font size="3"> * @brief       二维码识别</font>
  5. <font size="3"> * [url=home.php?mod=space&uid=271674]@param[/url]       camera_frame:图像指针</font>
  6. <font size="3"> * @retval      无</font>
  7. <font size="3"> */</font>
  8. <font size="3">extern "C" void esp_qr_scanner(camera_fb_t *camera_frame)</font>
  9. <font size="3">{</font>
  10. <font size="3">    esp_image_scanner_t *esp_scn = esp_code_scanner_create();</font>
  11. <font size="3">esp_code_scanner_config_t config = {ESP_CODE_SCANNER_MODE_FAST,</font>
  12. <font size="3">                                  ESP_CODE_SCANNER_IMAGE_RGB565,</font>
  13. <font size="3">                                 camera_frame->width, camera_frame->height};</font>
  14. <font size="3">    esp_code_scanner_set_config(esp_scn, config);</font>
  15. <font size="3">    int decoded_num = esp_code_scanner_scan_image(esp_scn, camera_frame->buf);</font>

  16. <font size="3">    if (decoded_num)</font>
  17. <font size="3">    {</font>
  18. <font size="3">        dl::image::draw_filled_rectangle((uint16_t *)camera_frame->buf,</font>
  19. <font size="3">                                          camera_frame->height, </font>
  20. <font size="3">camera_frame->width, 0, 0, 20, 20);</font>
  21. <font size="3">        esp_code_scanner_symbol_t result = esp_code_scanner_result(esp_scn);</font>
  22. <font size="3">        printf("Decoded %s symbol "%s"\n", result.type_name, result.data);</font>
  23. <font size="3">    }</font>
  24. <font size="3">    </font>
  25. <font size="3">    esp_code_scanner_destroy(esp_scn);</font>
  26. <font size="3">}</font>

  27. <font size="3">/**</font>
  28. <font size="3"> * @brief       摄像头图像数据获取任务</font>
  29. <font size="3"> * @param       arg:未使用</font>
  30. <font size="3"> * @retval      无</font>
  31. <font size="3"> */</font>
  32. <font size="3">static void esp_camera_process_handler(void *arg)</font>
  33. <font size="3">{</font>
  34. <font size="3">    arg = arg;</font>
  35. <font size="3">    camera_fb_t *camera_frame = NULL;</font>

  36. <font size="3">    while (1)</font>
  37. <font size="3">    {</font>
  38. <font size="3">        /* 获取摄像头图像 */</font>
  39. <font size="3">        camera_frame = esp_camera_fb_get();</font>

  40. <font size="3">        if (camera_frame)</font>
  41. <font size="3">        {</font>
  42. <font size="3">            /* 二维码识别 */</font>
  43. <font size="3">            esp_qr_scanner(camera_frame);</font>
  44. <font size="3">            /* 以队列的形式发送 */</font>
  45. <font size="3">            xQueueSend(xQueueAIFrameO, &camera_frame, portMAX_DELAY);</font>
  46. <font size="3">        }</font>
  47. <font size="3">    }</font>
  48. <font size="3">}</font>

  49. <font size="3">/**</font>
  50. <font size="3"> * @brief       AI图像数据开启</font>
  51. <font size="3"> * @param       无</font>
  52. <font size="3"> * @retval      1:创建任务及队列失败;0:创建任务及对了成功</font>
  53. <font size="3"> */</font>
  54. <font size="3">uint8_t esp_qr_detection_ai_strat(void)</font>
  55. <font size="3">{</font>
  56. <font size="3">    /* 创建队列及任务 */</font>
  57. <font size="3">    xQueueAIFrameO = xQueueCreate(5, sizeof(camera_fb_t *));</font>
  58. <font size="3">xTaskCreatePinnedToCore(esp_camera_process_handler,</font>
  59. <font size="3">                        "esp_camera_process_handler", 4 * 1024, </font>
  60. <font size="3">NULL, 5, &camera_task_handle, 1);</font>
  61. <font size="3">    </font>
  62. <font size="3">    if (xQueueAIFrameO != NULL </font>
  63. <font size="3">        || camera_task_handle != NULL)</font>
  64. <font size="3">    {</font>
  65. <font size="3">        return 0;</font>
  66. <font size="3">    }</font>

  67. <font size="3">    return 1;</font>
  68. <font size="3">}</font>
复制代码
在上述源码中,我们首先创建了一个消息队列和一个AI处理任务。消息队列用于传输图像数据,而AI处理任务则负责获取图像数据并进行二维码识别。如果识别成功,串口将打印成功的内容;如果识别失败,串口将打印失败的内容。最后,我们使用消息队列将当前图像数据传输至LCD进行显示。

61.3 下载验证
程序下载成功后,如果在检测过程中发现二维码,该系统会对当前二维码进行解码,并把解码内容以串口形式输出。另外,当检测二维码时,图像左上角显示蓝色矩形弹出,如下图。

第六十一章 二维码识别实验3266.png
图61.3.1 二维码识别效果图
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


关闭

原子哥极力推荐上一条 /1 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-11-25 11:37

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表