Fixed errors in tqdm implementation for progress tracking
This commit is contained in:
37
refacer.py
37
refacer.py
@@ -60,6 +60,10 @@ class Refacer:
|
|||||||
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
||||||
print(f"Total frames: {total_frames}")
|
print(f"Total frames: {total_frames}")
|
||||||
|
|
||||||
|
#probe = ffmpeg.probe(video_path)
|
||||||
|
#video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
|
||||||
|
#print(video_stream)
|
||||||
|
|
||||||
fps = cap.get(cv2.CAP_PROP_FPS)
|
fps = cap.get(cv2.CAP_PROP_FPS)
|
||||||
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
||||||
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
||||||
@@ -67,26 +71,25 @@ class Refacer:
|
|||||||
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
||||||
output = cv2.VideoWriter(output_video_path, fourcc, fps, (frame_width, frame_height))
|
output = cv2.VideoWriter(output_video_path, fourcc, fps, (frame_width, frame_height))
|
||||||
|
|
||||||
pbar = tqdm(total=total_frames)
|
with tqdm(total=total_frames) as pbar:
|
||||||
while cap.isOpened():
|
while cap.isOpened():
|
||||||
flag, frame = cap.read()
|
flag, frame = cap.read()
|
||||||
if flag and len(frame)>0:
|
if flag and len(frame)>0:
|
||||||
pos_frame = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
|
#pos_frame = int(cap.get(cv2.CAP_PROP_POS_FRAMES))
|
||||||
|
pbar.update(1)
|
||||||
|
|
||||||
pbar.update(pos_frame)
|
faces = self.face_app.get(frame)
|
||||||
|
res = frame.copy()
|
||||||
|
|
||||||
faces = self.face_app.get(frame)
|
for face in faces:
|
||||||
res = frame.copy()
|
for rep_face in replacement_faces:
|
||||||
|
sim = self.rec_app.compute_sim(rep_face[0], face.embedding)
|
||||||
|
if sim>=rep_face[2]:
|
||||||
|
res = self.face_swapper.get(res, face, rep_face[1], paste_back=True)
|
||||||
|
|
||||||
for face in faces:
|
output.write(res)
|
||||||
for rep_face in replacement_faces:
|
else:
|
||||||
sim = self.rec_app.compute_sim(rep_face[0], face.embedding)
|
break
|
||||||
if sim>=rep_face[2]:
|
|
||||||
res = self.face_swapper.get(res, face, rep_face[1], paste_back=True)
|
|
||||||
|
|
||||||
output.write(res)
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
cap.release()
|
cap.release()
|
||||||
output.release()
|
output.release()
|
||||||
|
|||||||
Reference in New Issue
Block a user