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

连连跨境电商网站开发精准的搜索引擎优化

连连跨境电商网站开发,精准的搜索引擎优化,如何注册一个独立网站,用来查数据的网站怎么建设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://www.cadmedia.cn/news/4435.html

相关文章:

  • 广州市城乡和住房建设局官网seo优化排名
  • 做网站推广电话如何在百度上建立网站
  • 小程序商城怎么弄账号seo是什么
  • 黑龙江新闻法治在线合肥seo排名优化
  • 阆中网站建设天津网站优化
  • 网站网站建设哪家便宜成都网站快速排名优化
  • 威海泰浩建设集团有限公司网站网站优化塔山双喜
  • 义乌购1688批发网seo外包 杭州
  • 微信小程序开发工具下载哪个版本新网站百度seo如何做
  • 网站建设制作公司都选万维科技企业seo排名有 名
  • html在线编写网站夫唯seo怎么样
  • 东莞汽车总站停止营业客户营销
  • 本地app制作公司地址百度seo优化多少钱
  • 西安市政府网站建设seo建站公司
  • 会员管理系统app免费版网页优化seo广州
  • 建设一个电商网站的流程是什么欧洲站fba
  • 新浪推网站人工智能培训
  • 乌鲁木齐微信小程序制作公司做seo要投入什么
  • 天河微网站建设怎么做网站广告
  • 最火的传奇手游网站深圳今日头条新闻
  • 百川网站维护网站页面优化方案
  • 每日军事新闻报道沈阳seo公司
  • 产品设计专业介绍seo推广有哪些
  • 网站建设开发步骤自助建站平台源码
  • 大型建站公司是干嘛的sem和seo是什么
  • 中国著名b2b电子商务网站周口搜索引擎优化
  • 网站文章在哪发布做seo适合seo的建站系统
  • 公司建设官方网站太原做网站的
  • 网站推广服务具体内容包括哪些青岛百度关键词优化
  • 一站式营销型网站建设服务关键词排名点击工具