DataBall 助力快速掌握数据集的信息和使用方式,会员享有 百种数据集,持续增加中。
需要更多数据资源和技术解决方案,知识星球: "DataBall - X 数据球(free)"
-----------------------------------------------------------------
Paddle OCR 中英文检测识别
具体实现代码如下:
python
#-*-coding:utf-8-*-
# date:2024-12-22
# Author: DataBall - XIAN
# Function: OCR 检测识别
import os
import cv2
import numpy as np
import time
from paddleocr import PaddleOCR
if __name__ == '__main__':
if False: # 中文
cls_model_dir='paddleModels/whl/cls/ch_ppocr_mobile_v2.0_cls_infer'
rec_model_dir='paddleModels/whl/rec/ch/ch_PP-OCRv4_rec_infer'
ocr = PaddleOCR(use_angle_cls=True, lang="ch", det=False,cls_model_dir=cls_model_dir,rec_model_dir=rec_model_dir) # need to run only once to download and load model into memory
else: # 英文
# ocr = PaddleOCR(use_angle_cls=True, lang="en")
cls_model_dir='paddleModels/whl/cls/en_ppocr_mobile_v2.0_cls_infer'
rec_model_dir='paddleModels/whl/rec/ch/en/en_PP-OCRv4_rec_infer'
ocr = PaddleOCR(use_angle_cls=True, lang="en", det=False,cls_model_dir=cls_model_dir,rec_model_dir=rec_model_dir) # need to run only once to download and load model into memory
img_path = "image/2.png"
img = cv2.imread(img_path)
result_det = ocr.ocr(img, cls=True)
print(type(result_det))
result_det = result_det[0]
idx_ = 0
for m_ in result_det:
idx_ += 1
bbox_,contant_ = m_
print("[{}] bbox: {}, contant: {}".format(idx_,bbox_,contant_))
pts = np.array(bbox_).astype(np.int32)
pts = pts.reshape((-1,1,2))
# 绘制区域
cv2.polylines(img,[pts],True,(255,22,150),1)
cv2.namedWindow("img",0)
cv2.imshow("img",img)
cv2.waitKey(0)
cv2.imwrite("out.png",img)
示例如下:
助力快速掌握数据集的信息和使用方式。
数据可以如此美好!