import cv2 import os file_path = "./ktxx" save_path = "./plate_num" imgs_list = os.listdir(file_path) for img_name in imgs_list: if img_name.endswith(".jpg"): image = cv2.imread(os.path.join(file_path, img_name)) img_w, img_h = image.shape[1], image.shape[0] file_read = open(os.path.join(file_path, img_name[0:-4] + ".txt"), "r") for line in file_read.readlines(): count = 1 bbox = line.split(" ") if int(bbox[0]) == 10: # 确定是车牌的标注 center_x = round(float(bbox[1]) * img_w) center_y = round(float(bbox[2]) * img_h) bbox_width = round(float(bbox[3]) * img_w) bbox_height = round(float(bbox[4]) * img_h) xmin = int(center_x - bbox_width / 2) ymin = int(center_y - bbox_height / 2) xmax = int(center_x + bbox_width / 2) ymax = int(center_y + bbox_height / 2) save_image = image[ymin:ymax, xmin:xmax] cv2.imwrite(os.path.join(save_path, img_name[0:-4] + "_" + str(count) + ".jpg"), save_image) print(img_name)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)