当前位置: 首页 > wzjs >正文

第一次做网站做后感一个人如何做跨境电商

第一次做网站做后感,一个人如何做跨境电商,企业门户样式,php开源网站管理系统paddle ocr paddle ocr笔记准备工作referenceto onnx文本检测文本检测文字识别 paddle ocr笔记 准备工作 下载字典ppocr_keys_v1.txt,下标从1开始模型转换 reference paddlepaddle to onnx 下载模型,或者直接使用python跑一下并且把本地模型拿过来…

paddle ocr

  • paddle ocr笔记
    • 准备工作
    • reference
    • to onnx
    • 文本检测
    • 文本检测
    • 文字识别

paddle ocr笔记

准备工作

  1. 下载字典ppocr_keys_v1.txt,下标从1开始
  2. 模型转换

reference

  • paddlepaddle

to onnx

下载模型,或者直接使用python跑一下并且把本地模型拿过来用,一共三个模型:文本检测,文本方向校准,文字识别模型

paddle2onnx --model_dir ./det/ch/ch_PP-OCRv4_det_infer --model_filename inference.pdmodel  --params_filename inference.pdiparams  --save_file ./det-model.onnx  --opset_version 11  --enable_onnx_checker Truepaddle2onnx --model_dir ./rec/ch/ch_PP-OCRv4_rec_infer --model_filename inference.pdmodel  --params_filename inference.pdiparams  --save_file ./rec-model.onnx  --opset_version 11  --enable_onnx_checker Truepaddle2onnx --model_dir ./cls/ch_ppocr_mobile_v2.0_cls_infer --model_filename inference.pdmodel  --params_filename inference.pdiparams  --save_file ./cls-padmodel.onnx  --opset_version 11  --enable_onnx_checker True

文本检测

import onnxruntime
import cv2
import numpy as np# 读取图片
# image = cv2.imread("chinese.png")
image = cv2.imread("none.png")# 加载 ONNX 文本检测模型
det_session = onnxruntime.InferenceSession("./onnx/det-model.onnx")# 预处理
det_input = cv2.resize(image, (640, 640)) / 255.0  # 归一化
det_input = np.transpose(det_input, (2, 0, 1))[np.newaxis, :, :, :].astype(np.float32)# 推理
input_name = det_session.get_inputs()[0].name
output_name = det_session.get_outputs()[0].name
det_output = det_session.run([output_name], {input_name: det_input})[0]# 获取非零值的索引(文本区域)
non_zero_indices = np.nonzero(det_output)print(f'--------------------------')
print(f'len:{len(non_zero_indices[0])}')
# 打印非零值的索引及对应的值
for i in range(len(non_zero_indices[0])):print(f'--------------------------')coords = tuple(non_zero_indices[j][i] for j in range(len(non_zero_indices)))print(f"坐标: {coords}, 值: {det_output[coords]}")

文本检测

import onnxruntime
import cv2
import numpy as np# 读取图片
# image = cv2.imread("chinese.png")
# image = cv2.imread("none.png")
image = cv2.imread("oneline.png")# 加载 ONNX 文本检测模型
det_session = onnxruntime.InferenceSession("./onnx/det-model.onnx")# 预处理
det_input = cv2.resize(image, (640, 640)) / 255.0  # 归一化
# det_input = image / 255.0  # 归一化
det_input = np.transpose(det_input, (2, 0, 1))[np.newaxis, :, :, :].astype(np.float32)# 推理
input_name = det_session.get_inputs()[0].name
output_name = det_session.get_outputs()[0].name
det_output = det_session.run([output_name], {input_name: det_input})[0]#
#
#
# 获取非零值的索引(文本区域)
# non_zero_indices = np.nonzero(det_output)# print(f'--------------------------')
# print(f'len:{len(non_zero_indices[0])}')
# # 打印非零值的索引及对应的值
# for i in range(len(non_zero_indices[0])):
#     print(f'--------------------------')
#     coords = tuple(non_zero_indices[j][i] for j in range(len(non_zero_indices)))
#     print(f"坐标: {coords}, 值: {det_output[coords]}")# 5. 确保 `det_output` 是 4D (batch, channels, height, width)
print("det_output shape:", det_output.shape)# 6. 获取二值化文本区域
box_thresh = 0.3
text_mask = (det_output[0, 0, :, :] > box_thresh).astype(np.uint8) * 255# 7. 确保 `text_mask` 是单通道 2D 图像
print("text_mask shape:", text_mask.shape)  # 应该是 (height, width)# 8. 显示二值化结果(可选)
cv2.imshow("Text Mask", text_mask)
cv2.waitKey(0)
cv2.destroyAllWindows()# 9. 确保 `text_mask` 兼容 OpenCV
if len(text_mask.shape) == 3:text_mask = cv2.cvtColor(text_mask, cv2.COLOR_BGR2GRAY)# 10. 轮廓检测
contours, _ = cv2.findContours(text_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)# 11. 打印检测到的文本框
for contour in contours:x, y, w, h = cv2.boundingRect(contour)print(f"检测到的文本框: x={x}, y={y}, w={w}, h={h}")

文字识别

import onnxruntime
import cv2
import numpy as np# 读取图片
image = cv2.imread("rec-cv2.imread.png")target_height = 48
h, w = image.shape[:2]
new_w = int(w * (target_height / h))
new_w = max(32, (new_w // 32) * 32)
image = cv2.resize(image, (new_w, target_height));
print(f'resize: {image.shape}')# image = cv2.imread("none.png")# 加载 ONNX 文本检测模型
rec_session = onnxruntime.InferenceSession("./onnx/rec-model.onnx")# 预处理
# rec_input = cv2.resize(image, (640, 640)) / 255.0  # 归一化
rec_input = image / 255.0  # 归一化
rec_input = np.transpose(rec_input, (2, 0, 1))[np.newaxis, :, :, :].astype(np.float32)print(f'shape: {rec_input.shape}')# 推理
input_name = rec_session.get_inputs()[0].name
output_name = rec_session.get_outputs()[0].name
print(f'input_name: {input_name}')
print(f'output_name: {output_name}')
rec_output = rec_session.run([output_name], {input_name: rec_input})[0]with open('onnx/dict.txt', 'r', encoding='utf-8') as f:dict_list = f.readlines()dict_list = [line.strip() for line in dict_list]# 返回下标的字典dict_index = {i + 1: char for i, char in enumerate(dict_list)}print(rec_output[0].shape)# 假设 rec_output[0] 的 shape 为 (60, 6625)
probabilities = rec_output[0]  # 取出 (60, 6625)# Step 1: 找到每个时间步概率最高的索引
max_indices = np.argmax(probabilities, axis=1)  # shape: (60,)# print(f'--dict: {dict_index}')
# Step 2: CTC 处理(去重)
decoded_text = []
prev_index = -1  # 记录前一个索引,避免重复
for index in max_indices:if index != prev_index and index in dict_index:  # 避免重复 & 确保索引合法print(f'--index: {index}, dict[{index}] = dict_index[{index}]')decoded_text.append(dict_index[index])prev_index = index# Step 3: 转换为字符串
decoded_text = "".join(decoded_text)print("识别结果:", decoded_text)

文章转载自:

http://Rui2O0WH.pcrjL.cn
http://ApGaS1hG.pcrjL.cn
http://SO2Qm7Pa.pcrjL.cn
http://BH8SzrVa.pcrjL.cn
http://Url8eByD.pcrjL.cn
http://el2lM1Ml.pcrjL.cn
http://yanosAD9.pcrjL.cn
http://pHPGjxcd.pcrjL.cn
http://7lQV5H9d.pcrjL.cn
http://xZe9PmGA.pcrjL.cn
http://98Mx9Tsi.pcrjL.cn
http://zbOjI6oV.pcrjL.cn
http://1lRA0Xoe.pcrjL.cn
http://pr2ewchD.pcrjL.cn
http://NCz43dlb.pcrjL.cn
http://ujGQZDuY.pcrjL.cn
http://VAQAkl3M.pcrjL.cn
http://jN8X0UbK.pcrjL.cn
http://LI0E4ReJ.pcrjL.cn
http://QhZ16K3A.pcrjL.cn
http://D01be2OS.pcrjL.cn
http://mIXONf5B.pcrjL.cn
http://es4d0WNX.pcrjL.cn
http://PHim0KPi.pcrjL.cn
http://aRcaiVuP.pcrjL.cn
http://8bjavwjU.pcrjL.cn
http://XsrLebg3.pcrjL.cn
http://R3p5zTnn.pcrjL.cn
http://8AsoGWyh.pcrjL.cn
http://LasQ2GED.pcrjL.cn
http://www.dtcms.com/wzjs/647080.html

相关文章:

  • 企业网站修改流程wordpress免费商城模板
  • 广州做网站信科分公司网页设计与制作教程第六版答案
  • 棠下手机网站建设报价怎么开一个平台
  • 郑州企业建设网站服务高校网站群建设
  • 基于flash网站设计建站之星有手机版模板
  • 如何建立网站 个人魔贝课凡seo课程好吗
  • 杭州网站建设公司推荐采集做网站
  • 网站怎么做更好推广如何套模板做网站
  • 云南省建设系统网站公司前台设计
  • 网站建设对企业经营网站seo 优化
  • 网页设计与网站建设设计报告营销方向有哪些
  • 外贸网站中的搜索产品功能如何实现网站没有地图怎么做的
  • 网站开发哪一种语言好现在去北京安全吗
  • 百度网站推广关键词怎么查教育建设网站
  • 为何网站建设公司报价不同ps转页面wordpress插件
  • 如何做网站栏目规划浙江省住房和城乡建设行业网站
  • html网页设计环保网站网站建设设计书
  • 南宁网站建站推广门户网站开发专业
  • 电子商务网站建设及推广在网上怎么赚钱快
  • 软件开发可以做网站么私人网站建设成本
  • 做网站的个人总结优良的定制网站建设
  • 西宁企业网站营销推广什么是交互式网站
  • 月嫂的个人简历网站模板做航空产品的网站有哪些
  • 廊坊做网站的大公司网站开发前台和后台
  • 做博客的网站有哪些功能WordPress是静态的吗
  • 网络推广有哪些渠道长沙网站整站优化
  • 3 阐述网站建设的步骤过程 9分qq是谁开发出来的软件?
  • 杭州网站建设中心网站分析 实例
  • 网站建设教育类旧式网站高端网站建设费用情况
  • 济南营销网站建设西安谷歌推广