Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Saving captured frames to separate folders

Currently working on extracting frames from videos and have noticed that the images get overwritten. Would be nice to create a folder for each of the captured frames but I’m unsure how to do that.

data_folder = r"C:\Users\jagac\Downloads\Data"
sub_folder_vid = "hmdb51_org"
path2videos = os.path.join(data_folder, sub_folder_vid)

for path, subdirs, files in os.walk(path2videos):
    for name in files:
        vids = os.path.join(path, name)

        cap = cv2.VideoCapture(vids)
        i = 0
        
        frame_skip = 10
        frame_count = 0

        while(cap.isOpened()):
            ret, frame = cap.read()
            if ret == False:
                break
            
            if i > frame_skip - 1:
                frame_count += 1
                
                path2store= r"C:\Users\jagac\OneDrive\Documents\CSC578\final\HumanActionClassifier\images"
                os.makedirs(path2store, exist_ok= True)
                path2img = os.path.join(path2store, 'test_' + str(frame_count*frame_skip) + ".jpg")
                cv2.imwrite(path2img, frame)
                
                i = 0
                continue
            i += 1 
        cap.release()
        cv2.destroyAllWindows() 

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The problem is that you’re not incorporating name into your path, so each video is overwriting the previous. You can either add the file name to path2img, or add name to the path2store variable before you make the directory.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading