这里的算法复现思路
代码下载地址
这里都是基本的读取代码
if __name__ == "__main__" :
import time
device = 'cuda' if torch.cuda.is_available() else 'cpu'
DBface_Detect = dbface_detect(device=device, align=True)
start_time=time.time()
cap = cv2.VideoCapture('2560×1440.mp4')
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))//3
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))//3
# print("width:",width, "height:", height)
video_fps = cap.get(cv2.CAP_PROP_FPS)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('downsample3.mp4', fourcc, video_fps, (width, height)) # 现实的格式尺寸
# yolonet = yolov5(confThreshold=args.confThreshold, nmsThreshold=args.nmsThreshold,
# objThreshold=args.objThreshold)
# srcimg = cv2.imread(args.imgpath)
i=0
ret, srcimg = cap.read()
while(ret):
time_flag1 = time.time()
srcimg=cv2.resize(srcimg, (width, height))
# dets = yolonet.detect(srcimg)
# srcimg = yolonet.postprocess(srcimg, dets)
# drawimg, face_rois = yoloface_detect.detect(srcimg)
# drawimg, face_rois = facebox_detect.detect(srcimg)
drawimg, face_rois = DBface_Detect.detect(srcimg)
# print("face",face_rois)
winName = 'Deep learning object detection in OpenCV'
cv2.namedWindow(winName, 0)
cv2.imshow(winName, drawimg)
cv2.waitKey(2)
i+=1
time_flag2 = time.time()
print(f"cost: {time_flag2 - time_flag1}")
out.write(drawimg)
ret, srcimg = cap.read()
end_time = time.time()
print(f'Done. Total cost: {end_time - start_time}')
print(f'each image cost: {(end_time - start_time)/i}')
cap.release()
out.release()