#!/usr/bin/env python
# -*- coding: utf-8 -*
# FileName: table_test ;
# Author: renoyuan
# e_mail: renoyuan@foxmail.com
# Date: 2021/12/23
"""
输入图片坐标给图片画框
"""
import json
import os
import base64
import cv2
with open("table_test.json", 'r', encoding='utf-8') as f:
json_data = json.load(f)
table = json_data["content"]["table"]
img = json_data["content"]["image"]
with open("save.jpg", "wb") as f:
f.write(base64.b64decode(img))
img = cv2.imread("save.jpg")
sp = img.shape //宽高
print(sp)
for info in table:
for i in info:
bbox = i.get("bbox", "")
if bbox:
cv2.rectangle(img, (int(bbox[0]), int(bbox[1])), (int(bbox[2]), int(bbox[3])), (0, 0, 255), 1)
img_save_path = os.path.join("aa" + '.png')
cv2.imwrite(img_save_path, img)