Merge pull request 'yolorestart' (#1) from yolopart_restart into main
Reviewed-on: #1
This commit is contained in:
		@@ -2,16 +2,25 @@ import numpy as np
 | 
			
		||||
from paddleocr import TextRecognition
 | 
			
		||||
import cv2
 | 
			
		||||
 | 
			
		||||
class OCRProcessor:
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        self.model = TextRecognition(model_name="PP-OCRv5_server_rec")
 | 
			
		||||
        print("OCR模型初始化完成(占位)")
 | 
			
		||||
 | 
			
		||||
    def predict(self, image_array):
 | 
			
		||||
        # 保持原有模型调用方式
 | 
			
		||||
        output = self.model.predict(input=image_array)
 | 
			
		||||
        # 结构化输出结果
 | 
			
		||||
        results = output[0]["rec_text"]
 | 
			
		||||
        placeholder_result = results.split(',')
 | 
			
		||||
        return placeholder_result
 | 
			
		||||
 | 
			
		||||
# 保留原有函数接口
 | 
			
		||||
_processor = OCRProcessor()
 | 
			
		||||
 | 
			
		||||
def initialize_ocr_model():
 | 
			
		||||
    model = TextRecognition(model_name="PP-OCRv5_server_rec")
 | 
			
		||||
    print("OCR模型初始化完成(占位)")
 | 
			
		||||
    return model
 | 
			
		||||
    return _processor
 | 
			
		||||
 | 
			
		||||
def ocr_predict(image_array):
 | 
			
		||||
    # 保持原有模型调用方式
 | 
			
		||||
    output = initialize_ocr_model().predict(input=image_array)
 | 
			
		||||
    # 结构化输出结果
 | 
			
		||||
    results = output[0]["rec_text"]
 | 
			
		||||
    placeholder_result = results.split(',')
 | 
			
		||||
    return placeholder_result
 | 
			
		||||
    return _processor.predict(image_array)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user