diff --git a/README.md b/README.md index ecc46afaa652bd69db4893ac0561ac0f37b5777b..9d39322cd0609afea6a258a1fdce33b8ed4c8828 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,8 @@ Lockzhiner Vision Module 拥有丰富的 IO 接口,其接口图片如下图所 ## 👍 特色部署教程 * [凌智视觉模块手写数字识别部署指南](./example/special/digit_handwritten_recognition) -* [凌智视觉模块二维码识别与检测部署指南](./example/special/qr_code_recognition) +* [凌智视觉模块二维码检测与识别部署指南](./example/special/qr_code_recognition) +* [凌智视觉模块条码检测与识别部署指南](./example/special/bar_code_recognition) ## 🐛 Bug反馈 diff --git a/configs/LZ-Picodet_fp32.yaml b/configs/LZ-Picodet_fp32.yaml new file mode 100644 index 0000000000000000000000000000000000000000..acfacce907dec33da69d9808f75868c83976727f --- /dev/null +++ b/configs/LZ-Picodet_fp32.yaml @@ -0,0 +1,32 @@ +config: + mean: + - 0.406 + - 0.456 + - 0.485 + std: + - 0.225 + - 0.224 + - 0.229 + +load_onnx: + inputs: + - image + input_size_list: + - + - 1 + - 3 + - 320 + - 320 + outputs: + - sigmoid_0.tmp_0 + - split_0.tmp_1 + - sigmoid_1.tmp_0 + - split_1.tmp_1 + - sigmoid_2.tmp_0 + - split_2.tmp_1 + - sigmoid_3.tmp_0 + - split_3.tmp_1 + +build: + do_quantization: True + dataset: ./dataset.txt \ No newline at end of file diff --git a/docs/introductory_tutorial/burn_image.md b/docs/introductory_tutorial/burn_image.md index 5d732119b7240dc2778787dded8c5312217a545a..74b5bc8821ee8e3563f8e011f922624b751a8168 100644 --- a/docs/introductory_tutorial/burn_image.md +++ b/docs/introductory_tutorial/burn_image.md @@ -36,7 +36,8 @@ 在开始烧录前,我们需要做一些前期的准备: * 请准备一张 **64G 容量以下**的 SD 卡,这里我们选用的是 16G 的 SD 卡。请将 SD 卡插入读卡器并正确连接电脑。 -* 请正确下载 Lockzhiner Vision Module 的镜像软件包到你喜欢的位置。 +* 前往 [凌智视觉模块镜像下载地址](https://pan.baidu.com/s/1w28TRzvEVvRURuisywnNZg) 下载镜像,提取码为 772f +* 前往 [凌智视觉模块烧录软件下载地址](https://pan.baidu.com/s/1EdzzDu8Yn62GBFaZYe_T3A) 下载烧录软件,提取码为 hk9v ## 3 开始烧录 diff --git a/example/special/bar_code_recognition/README.md b/example/special/bar_code_recognition/README.md new file mode 100644 index 0000000000000000000000000000000000000000..bc9c834342ba2988ea468b2bacaef02a9147ef80 --- /dev/null +++ b/example/special/bar_code_recognition/README.md @@ -0,0 +1,46 @@ +

凌智视觉模块条码检测与识别部署指南

+ +发布版本:V0.0.0 + +日期:2024-09-27 + +文件密级:□绝密 □秘密 □内部资料 ■公开 + +--- + +**免责声明** + +本文档按**现状**提供,福州凌睿智捷电子有限公司(以下简称**本公司**)不对本文档中的任何陈述、信息和内容的准确性、可靠性、完整性、适销性、适用性及非侵权性提供任何明示或暗示的声明或保证。本文档仅作为使用指导的参考。 + +由于产品版本升级或其他原因,本文档可能在未经任何通知的情况下不定期更新或修改。 + +**读者对象** + +本教程适用于以下工程师: + +- 技术支持工程师 +- 软件开发工程师 + +**修订记录** + +| **日期** | **版本** | **作者** | **修改说明** | +| :--------- | -------- | -------- | ------------ | +| 2024/09/27 | 0.0.0 | 郑必城 | 初始版本 | + +## 1 简介 + +条码(Bar Code)是一种二维条形码,因其高效的编码和解码能力而得名。条码识别是视觉模块经常使用到的功能之一,经常用于识别超市的货物信息。本章节中,我们将教会你如何使用 Lockzhiner Vision Module 进行条码识别。 + +## 2 在凌智视觉模块上部署条码识别案例 + +下载模型后,请参考以下教程使用 Python 在凌智视觉模块上部署分类模型例程: + +- [凌智视觉模块条码识别 Python 部署指南](./python) + +## 4 模型性能指标 + +以下测试数据为模型执行 Predict 函数运行 1000 次耗时的平均时间 + +| 分类模型 | FPS(帧/s) | 精度(%) | +|:-------:|:----:|:----:| +|LZ-DigitHandRecog|35|96.74| diff --git a/example/special/bar_code_recognition/python/README.md b/example/special/bar_code_recognition/python/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0cb125513991a773d854c683489fb501bf77da1f --- /dev/null +++ b/example/special/bar_code_recognition/python/README.md @@ -0,0 +1,253 @@ +

凌智视觉模块条码识别 Python 部署指南

+ +发布版本:V0.0.0 + +日期:2024-09-27 + +文件密级:□绝密 □秘密 □内部资料 ■公开 + +--- + +**免责声明** + +本文档按**现状**提供,福州凌睿智捷电子有限公司(以下简称**本公司**)不对本文档中的任何陈述、信息和内容的准确性、可靠性、完整性、适销性、适用性及非侵权性提供任何明示或暗示的声明或保证。本文档仅作为使用指导的参考。 + +由于产品版本升级或其他原因,本文档可能在未经任何通知的情况下不定期更新或修改。 + +**读者对象** + +本教程适用于以下工程师: + +- 技术支持工程师 +- 软件开发工程师 + +**修订记录** + +| **日期** | **版本** | **作者** | **修改说明** | +| :--------- | -------- | -------- | ------------ | +| 2024/09/27 | 0.0.0 | 郑必城 | 初始版本 | + +## 1 简介 + +接下来让我们基于 Python 来部署条码识别案例,在开始本章节前: + +- 请确保你已经参考 [凌智视觉模块摄像头部署指南](../../../periphery/capture/README.md) 正确下载了凌智视觉模块图片传输助手。 +- 请确保你已经按照 [开发环境搭建指南](../../../../docs/introductory_tutorial/python_development_environment.md) 正确配置了开发环境。 + +## 2 Python API 文档 + +```python +class Point: + def __init__(self): + self.point = cv2.Point() + + @property + def x(self): + """ + 获取矩形左上角坐标点的 x 坐标 + + Returns: + int: 获取矩形左上角坐标点的 x 坐标 + """ + return self.rect.x + + @property + def y(self): + """ + 获取矩形左上角坐标点的 y 坐标 + + Returns: + int: 获取矩形左上角坐标点的 y 坐标 + """ + return self.rect.y + +class CodeResult: + """ + 条码识别检测结果类,用于封装和处理条码识别结果数据。 + + 该类主要提供了一个包装层,用于访问和管理由视觉模块产生的条码识别结果。 + """ + + def __init__(self): + self.qr_code_result = vision.CodeResult() + + @property + def top_left(self): + """ + 获取条码识别结果的左上角坐标 + + Returns: + Point: 左上角坐标 + """ + return self.qr_code_result.top_left + + @property + def top_right(self): + """ + 获取条码识别结果的右上角坐标 + + Returns: + Point: 右上角坐标 + """ + return self.qr_code_result.top_right + + @property + def bottom_left(self): + """ + 获取条码识别结果的左下角坐标 + + Returns: + Point: 左下角坐标 + """ + return self.qr_code_result.bottom_left + + @property + def bottom_right(self): + """ + 获取条码识别结果的右下角坐标 + + Returns: + Point: 右下角坐标 + """ + return self.qr_code_result.bottom_right + + @property + def text(self): + """ + 获取条码识别结果的文本数据 + + Returns: + Point: 条码识别结果的文本数据 + """ + return self.qr_code_result.text + +class Code39Detector: + """ + Code39Detector 类 - 用于 Code39 检测识别的封装类 + """ + + def __init__(self): + self.model = vision.Code39Detector() + + def predict(self, input_mat): + """ + 进行预测 + + Args: + input_mat (cv2.Mat): 输入的图像数据,通常是一个 cv2.Mat 变量。 + + Returns: + list(CodeResult): 预测结果对象列表,每一个预测结果包含了条码坐标和文本。 + """ + return self.model.predict(input_mat) + + +class Code93Detector: + """ + Code93Detector 类 - 用于 Code93 检测识别的封装类 + """ + + def __init__(self): + self.model = vision.Code93Detector() + + def predict(self, input_mat): + """ + 进行预测 + + Args: + input_mat (cv2.Mat): 输入的图像数据,通常是一个 cv2.Mat 变量。 + + Returns: + list(CodeResult): 预测结果对象列表,每一个预测结果包含了条码坐标和文本。 + """ + return self.model.predict(input_mat) + + +class Code128Detector: + """ + Code128Detector 类 - 用于 Code128 检测识别的封装类 + """ + + def __init__(self): + self.model = vision.Code128Detector() + + def predict(self, input_mat): + """ + 进行预测 + + Args: + input_mat (cv2.Mat): 输入的图像数据,通常是一个 cv2.Mat 变量。 + + Returns: + list(CodeResult): 预测结果对象列表,每一个预测结果包含了条码坐标和文本。 + """ + return self.model.predict(input_mat) +``` + +## 3 项目介绍 + +为了方便大家入手,我们做了一个简易的 Code128 类型的条形码检测和识别例程。该程序可以使用摄像头进行端到端推理,并可视化推理结果到凌智视觉模块图片传输助手。 + +```python +from lockzhiner_vision_module.cv2 import VideoCapture +from lockzhiner_vision_module.vision import Code128Detector, visualize +from lockzhiner_vision_module.edit import Edit +import sys + +if __name__ == "__main__": + edit = Edit() + edit.start_and_accept_connection() + + model = Code128Detector() + + video_capture = VideoCapture() + if video_capture.open(0) is False: + print("Failed to open capture") + exit(1) + + while True: + ret, mat = video_capture.read() + if ret is False: + continue + + results = model.predict(mat) + print(f"result size is {len(results)}") + for result in results: + top_left = result.top_left + top_right = result.top_right + bottom_left = result.bottom_left + bottom_right = result.bottom_right + text = result.text + print( + f"(top_left,top_right,bottom_left,bottom_right,text): [({top_left.x}),{top_left.y}),({top_right.x}),{top_right.y}),({bottom_left.x}),{bottom_left.y}),({bottom_right.x}),{bottom_right.y}),{text}]" + ) + + vis_mat = visualize(mat, results) + edit.print(vis_mat) +``` + +## 4 上传并测试 Python 程序 + +参考 [连接设备指南](../../../../docs/introductory_tutorial/connect_device_using_ssh.md) 正确连接 Lockzhiner Vision Module 设备。 + +![](../../../../docs/introductory_tutorial/images/connect_device_using_ssh/ssh_success.png) + +请使用 Electerm Sftp 依次上传以下两个文件: + +- 进入存放 **test_bar_code_recognition.py** 脚本文件的目录,将 **test_bar_code_recognition.py** 上传到 Lockzhiner Vision Module + +![](images/stfp.png) + +请使用 Electerm Ssh 并在命令行中执行以下命令: + +```bash +python test_bar_code_recognition.py +``` + +运行程序后,使用凌智视觉模块图片传输助手连接设备,屏幕上开始打印条码位置和置信度,凌智视觉模块图片传输助手出现可视化的结果 + +![alt text](images/qr_code_result.png) + + + + diff --git a/example/special/bar_code_recognition/python/images/2024_0927_10_10_00_267.png b/example/special/bar_code_recognition/python/images/2024_0927_10_10_00_267.png new file mode 100644 index 0000000000000000000000000000000000000000..3664906e5f8bfd128954841c863ac67056a72991 Binary files /dev/null and b/example/special/bar_code_recognition/python/images/2024_0927_10_10_00_267.png differ diff --git a/example/special/bar_code_recognition/python/images/qr_code_result.png b/example/special/bar_code_recognition/python/images/qr_code_result.png new file mode 100644 index 0000000000000000000000000000000000000000..4e12a63d4744590bb065ee668ad90ea00438a38e Binary files /dev/null and b/example/special/bar_code_recognition/python/images/qr_code_result.png differ diff --git a/example/special/bar_code_recognition/python/images/stfp.png b/example/special/bar_code_recognition/python/images/stfp.png new file mode 100644 index 0000000000000000000000000000000000000000..9c31239f4448987edcb4aede92c8e2ba6914727b Binary files /dev/null and b/example/special/bar_code_recognition/python/images/stfp.png differ diff --git a/example/special/bar_code_recognition/python/test_bar_code_recognition.py b/example/special/bar_code_recognition/python/test_bar_code_recognition.py new file mode 100644 index 0000000000000000000000000000000000000000..17ea37ce499d03cfd18929d64a492456fd031660 --- /dev/null +++ b/example/special/bar_code_recognition/python/test_bar_code_recognition.py @@ -0,0 +1,35 @@ +from lockzhiner_vision_module.cv2 import VideoCapture +from lockzhiner_vision_module.vision import Code128Detector, visualize +from lockzhiner_vision_module.edit import Edit +import sys + +if __name__ == "__main__": + edit = Edit() + edit.start_and_accept_connection() + + model = Code128Detector() + + video_capture = VideoCapture() + if video_capture.open(0) is False: + print("Failed to open capture") + exit(1) + + while True: + ret, mat = video_capture.read() + if ret is False: + continue + + results = model.predict(mat) + print(f"result size is {len(results)}") + for result in results: + top_left = result.top_left + top_right = result.top_right + bottom_left = result.bottom_left + bottom_right = result.bottom_right + text = result.text + print( + f"(top_left,top_right,bottom_left,bottom_right,text): [({top_left.x}),{top_left.y}),({top_right.x}),{top_right.y}),({bottom_left.x}),{bottom_left.y}),({bottom_right.x}),{bottom_right.y}),{text}]" + ) + + vis_mat = visualize(mat, results) + edit.print(vis_mat) diff --git a/example/special/qr_code_recognition/README.md b/example/special/qr_code_recognition/README.md index 3513b7338a8aed664f26c62fa16247dfa49b3691..bf0e834f4264df1c2aff472ae5451627c83f4bb2 100644 --- a/example/special/qr_code_recognition/README.md +++ b/example/special/qr_code_recognition/README.md @@ -1,4 +1,4 @@ -

凌智视觉模块二维码识别部署指南

+

凌智视觉模块二维码检测与识别部署指南

发布版本:V0.0.0 diff --git a/example/special/qr_code_recognition/python/README.md b/example/special/qr_code_recognition/python/README.md index 1c3c879575170ed8cc430367a3caf13778dd2001..0a98d4dfa768a621d4c709e65dd8d2cd5a3f6c82 100644 --- a/example/special/qr_code_recognition/python/README.md +++ b/example/special/qr_code_recognition/python/README.md @@ -61,50 +61,50 @@ class Point: """ return self.rect.y -class QRCodeResult: +class CodeResult: """ - 二维码识别检测结果类,用于封装和处理二维码识别结果数据。 + 条码识别检测结果类,用于封装和处理条码识别结果数据。 - 该类主要提供了一个包装层,用于访问和管理由视觉模块产生的二维码识别结果。 + 该类主要提供了一个包装层,用于访问和管理由视觉模块产生的条码识别结果。 """ - + def __init__(self): - self.qr_code_result = vision.QRCodeResult() + self.qr_code_result = vision.CodeResult() @property def top_left(self): """ - 获取二维码识别结果的左上角坐标 + 获取条码识别结果的左上角坐标 Returns: Point: 左上角坐标 """ return self.qr_code_result.top_left - + @property def top_right(self): """ - 获取二维码识别结果的右上角坐标 + 获取条码识别结果的右上角坐标 Returns: Point: 右上角坐标 """ return self.qr_code_result.top_right - + @property def bottom_left(self): """ - 获取二维码识别结果的左下角坐标 + 获取条码识别结果的左下角坐标 Returns: Point: 左下角坐标 """ return self.qr_code_result.bottom_left - + @property def bottom_right(self): """ - 获取二维码识别结果的右下角坐标 + 获取条码识别结果的右下角坐标 Returns: Point: 右下角坐标 @@ -114,10 +114,10 @@ class QRCodeResult: @property def text(self): """ - 获取二维码识别结果的文本数据 + 获取条码识别结果的文本数据 Returns: - Point: 二维码识别结果的文本数据 + Point: 条码识别结果的文本数据 """ return self.qr_code_result.text @@ -136,14 +136,14 @@ class QRCodeDetector: input_mat (cv2.Mat): 输入的图像数据,通常是一个 cv2.Mat 变量。 Returns: - list(QRCodeResult): 预测结果对象列表,每一个预测结果包含了二维码坐标和文本。 + list(CodeResult): 预测结果对象列表,每一个预测结果包含了二维码坐标和文本。 """ return self.model.predict(input_mat) ``` ## 3 项目介绍 -为了方便大家入手,我们做了一个简易的手写数字识别例程。该程序可以使用摄像头进行端到端推理,并可视化推理结果到凌智视觉模块图片传输助手。 +为了方便大家入手,我们做了一个简易的二维码检测识别例程。该程序可以使用摄像头进行端到端推理,并可视化推理结果到凌智视觉模块图片传输助手。 ```python from lockzhiner_vision_module.cv2 import VideoCapture