json reads pictures in batches and then recognizes them

Main points:

  • Fast Verification Algorithm


a single image

frame = cv2.imread('../save_img/0517_img/0-0515-310912.jpg')

# img_show('frame', frame)
mask_path = 'ocr_masks/31 进厂水流量计.json'

data = json.load(open(mask_path, encoding='utf-8'))
# 获取屏幕范围点
shapes = data['shapes']
target_label = '1'
for shape in shapes:
    label = shape['label']
    if label == target_label:
        points = [[float(round(x[0])), float(round(x[1]))] for x in shape['points']]
        points = np.float32(sort_points(points))

    elif label == '2':
        aim_points = [[float(round(x[0])), float(round(x[1]))] for x in shape['points']]
        aim_points = np.float32(sort_points(aim_points))

aim_img = extract_and_transform_image(frame, aim_points)
img_show('aim_img', aim_img)

Two batch viewing

# 算法批量识别
path = "../save_img/0517_img/"  # 修改为你自己的图片路径

for i, filename in enumerate(os.listdir(path)):
    if filename.split('.')[-1] != 'jpg':
        continue
    print('查看文件名:', filename)
    img_name = '../save_img/0517_img/' + filename
    frame = cv2.imread(img_name)

    frame_to_push = cv2.resize(frame, (int(frame.shape[1]*0.5), int(frame.shape[0]*0.5)), interpolation=cv2.INTER_AREA)
    img_show('frame_to_push', frame_to_push)

    k = int(filename.split('-')[0])
    mask_path = mask_list[k]

    data = json.load(open(mask_path, encoding='utf-8'))
    # 获取屏幕范围点
    shapes = data['shapes']
    target_label = '1'
    for shape in shapes:
        label = shape['label']
        if label == target_label:
            points = [[float(round(x[0])), float(round(x[1]))] for x in shape['points']]
            points = np.float32(sort_points(points))

        elif label == '2':
            aim_points = [[float(round(x[0])), float(round(x[1]))] for x in shape['points']]
            aim_points = np.float32(sort_points(aim_points))

    aim_img = extract_and_transform_image(frame, aim_points)
    img_show('aim_img', aim_img)
    ocr_result = digital_recognize(aim_img)
    print('识别结果:', ocr_result)

3 View the video stream

camera_list = [
    # 取水泵房仪表间球机
    'rtsp://10.0.58.253:9090/dss/monitor/param?cameraid=1003517%248&substream=1',
    # 送水泵房出水水质间球机
    'rtsp://10.0.58.253:9090/dss/monitor/param?cameraid=1003517%2418&substream=1',
    # 滤池水质间球机
    'rtsp://10.0.58.253:9090/dss/monitor/param?cameraid=1003517%2410&substream=1',
    # 滤池廊道浊度仪1号
    'rtsp://10.0.58.253:9090/dss/monitor/param?cameraid=1003517%244&substream=1',
    # 滤池廊道浊度仪2号
    'rtsp://10.0.58.253:9090/dss/monitor/param?cameraid=1003517%246&substream=1'
]

rtsp_url = camera_list[2]
cap = cv2.VideoCapture(rtsp_url)

save_dir = '../00get_new_img/'

while True:
    ret, frame = cap.read()
    if ret:

        cv2.imshow('frame', frame)
        key = cv2.waitKey(1)
        if key == ord('s'):
            print('img_shape:', frame.shape)
            img_name = f'{save_dir}0510_1# {time.time()}.jpg'
            cv2.imwrite(img_name, frame)
            print(f'Saved image to {img_name}')
        elif key == ord('q'):
            break
    else:
        print('Failed to read frame')
        break

cap.release()
cv2.destroyAllWindows()

Guess you like

Origin blog.csdn.net/March_A/article/details/130720427