我正在使用 Paddle OCR,我想知道 bbx off paddle OCR 的输出格式是什么。我在Paddle的github上找不到。这是我的代码。
from paddleocr import PaddleOCR,draw_ocr
ocr = PaddleOCR(use_angle_cls=False, lang='en', rec=False) # need to run only once to download and load model into memory
result = ocr.ocr(img, cls=False)
Run Code Online (Sandbox Code Playgroud)
输出
[[[[8.0, 12.0], [89.0, 12.0], [89.0, 25.0], [8.0, 25.0]],
('@kheengz_yfk', 0.9460259079933167)],
[[[6.0, 31.0], [227.0, 29.0], [227.0, 44.0], [6.0, 46.0]],
('EBIT is a week old today. and', 0.847086489200592)],
[[[4.0, 47.0], [225.0, 49.0], [225.0, 64.0], [4.0, 62.0]],
('the homebors came together...Seemore', 0.942597508430481)],
[[[7.0, 70.0], [183.0, 70.0], [183.0, 83.0], [7.0, 83.0]],
('Joriginal sound-kheengz_yfk(Cont', 0.8839073181152344)]]
Run Code Online (Sandbox Code Playgroud)
我想手动绘制边界框。
我的想法是,第一个是x0,y0(左上),最后一个是x1,y1(右下)
rect = cv2.rectangle(img.copy(), (int(result[0][0][0][0]), int(result[0][0][0][1])), (int(result[0][0][-1][0]),int(result[0][0][-1][0]) ), (0, 255, 0), -1)
plt.imshow(rect)
Run Code Online (Sandbox Code Playgroud)
但这不能正常工作。对此有任何帮助。谢谢。
测试图像。
原始 Paddle OCR draw_ocr 输出。
from PIL import Image
image = Image.fromarray(img).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores, font_path='/usr/share/fonts/opentype/malayalam/Chilanka-Regular.otf')
plt.imshow(im_show)
Run Code Online (Sandbox Code Playgroud)
小智 5
要绘制所有框,假设您的图像已加载PIL.Image.open()并称为 thisImage 并且您有一个名为 的 PaddleOCR 结果result
draw = PIL.ImageDraw.Draw(thisImage)
for i, box in enumerate(result[0]):
box = np.array(box[0]).astype(np.int32)
xmin = min(box[:, 0])
ymin = min(box[:, 1])
xmax = max(box[:, 0])
ymax = max(box[:, 1])
draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=1)
draw.text((xmin, ymin), f"{i}", fill="black")
Run Code Online (Sandbox Code Playgroud)
(在本例中,我已将结果索引号添加到框中以供交叉引用)