update for bakeup

This commit is contained in:
王庆刚
2024-08-06 20:00:29 +08:00
parent 27d57b21d4
commit 5109400a57
19 changed files with 497 additions and 352 deletions

View File

@ -14,30 +14,38 @@ import cv2
# import sys
# from scipy.spatial.distance import cdist
def video2imgs(videopath):
# =============================================================================
# videopath视频文件地址在该地址的 "/file_imgs/" 文件加下存储视频帧图像
# =============================================================================
path, filename = os.path.split(videopath)
file, ext = os.path.splitext(filename)
savepath = os.path.join(path, "{}_imgs".format(file))
if not os.path.exists(savepath):
os.makedirs(savepath)
cap = cv2.VideoCapture(videopath)
VideoFormat = ['.mp4', '.avi']
def video2imgs(videopath, savepath):
k = 0
while True:
ret, frame = cap.read()
if not ret:
break
k += 1
cv2.imwrite(os.path.join(savepath, "{}.png".format(k)), frame)
have = False
for filename in os.listdir(videopath):
file, ext = os.path.splitext(filename)
if ext not in VideoFormat:
continue
basename = os.path.basename(videopath)
imgbase = basename + '_' + file
imgdir = os.path.join(savepath, imgbase)
if not os.path.exists(imgdir):
os.mkdir(imgdir)
video = os.path.join(videopath, filename)
cap = cv2.VideoCapture(video)
i = 0
while True:
ret, frame = cap.read()
if not ret:
break
imgp = os.path.join(imgdir, file+f"_{i}.png")
i += 1
cv2.imwrite(imgp, frame)
cap.release()
print(filename + f" haved resolved")
k+=1
if k==1000:
break
def videosave(bboxes, videopath="100_1688009697927.mp4"):
@ -84,4 +92,15 @@ def videosave(bboxes, videopath="100_1688009697927.mp4"):
break
vid_writer.release()
cap.release()
cap.release()
def main():
videopath = r'C:\Users\ym\Desktop'
savepath = r'C:\Users\ym\Desktop'
video2imgs(videopath, savepath)
if __name__ == '__main__':
main()