各位大神好
想请问假设我希望将它们人脸画矩形裁切出来
并个别储存成档案
https://imgur.com/GWpEeXn.jpg
不过我手边已有annotate_dict.pkl是定界框的资讯
而图片是存在data_dir资料夹里
目前卡的点是不会读取这档并一次画出来
当然土法炼钢一个一个设应该可行但这效率太低QQ
希望有大神愿意提点一下感激不尽
import os, sys
import numpy as np
import cv2
import dlib
import matplotlib.pyplot as plt
pkl_path = 'annotation.pkl'
annotate_dict = pickle.load(open(pkl_path,"rb"))
data_dir = 'data_dir'
def draw_bbox():
for img_name in annotate_dict:
img_path= os.path.join(data_dir, img_name)
img = cv2.imread(img_path)
for bbox in annotate_dict[img_name]:
x1, y1, x2, y2 = bbox
cv2.rectangle(img, (x1,y1), (x2,y2), (0,255,0), thickness=2)
img_crop= img[y1:y2, x1:x2]
cv2.imwrite('fuck.jpg',img_crop)
# cv2.rectangle(img, (150,125), (195,190), (0,255,0), thickness=2)
# cv2.rectangle(img, (250,100), (300,160), (0,255,0), thickness=2)
# cv2.rectangle(img, (361,84), (400,145), (0,255,0), thickness=2)
# cv2.rectangle(img, (492,62), (533,118), (0,255,0), thickness=2)
# cv2.rectangle(img, (601,74), (641,128), (0,255,0), thickness=2)
img= img[:,:,::-1] # convert from BGR to RGB
plt.imshow(img)
plt.show()
pass
draw_bbox()
如果这样执行完只能画出一个方框而已QQ
https://imgur.com/C4pFIR7.jpg