python+opencv+绘制矩形框
import os import cv2 imgdir = "./test_img/" maskdir = "./train_mask/" HH=os.listdir(imgdir) for i in range(len(HH)): img_dir=HH[i] img = cv2.imread("./test_img/"+img_dir) mask_dir=maskdir+'2'+img_dir[1:]+'.txt' f = open(mask_dir,"r") lines = f.readlines() gla=lines[1].split('\n')[0] g_xmin=int(gla.split(',')[1]) g_ymin=int(gla.split(',')[2]) g_xmax=int(gla.split(',')[3]) g_ymax=int(gla.split(',')[4]) face=lines[0].split('\n')[0] f_xmin=int(face.split(',')[1]) f_ymin=int(face.split(',')[2]) f_xmax=int(face.split(',')[3]) f_ymax=int(face.split(',')[4]) f.close() cv2.rectangle(img,(f_xmin,f_ymin),(f_xmax,f_ymax),(0,0,255),2) cv2.rectangle(img,(g_xmin,g_ymin),(g_xmax,g_ymax),(255,0,0),2) cv2.imwrite("./result/"+img_dir,img) print(i,len(HH))