Switch to unified view

a b/Create_inputImage-checkpoint.py
1
import cv2
2
import os
3
import sys
4
import time
5
6
# Reading input and setting the frames
7
inp = cv2.VideoCapture("C:\\Users\\Vishal R\\Downloads\\DownwardDog.mp4")
8
9
# Check if the video file opened successfully
10
if not inp.isOpened():
11
    print("Error: Unable to open video file.")
12
    sys.exit()
13
14
# Get total frame count to ensure we're processing all frames
15
total_frames = int(inp.get(cv2.CAP_PROP_FRAME_COUNT))
16
print(f"Total frames in video: {total_frames}")
17
18
# Setting the starting frame (you can change this if needed)
19
inp.set(1, 400)
20
21
# Check if the directory for images exists, if not, create it
22
try:
23
    if not os.path.exists('inp_images'):
24
        os.makedirs('inp_images')
25
except OSError:
26
    print('Error creating input directory')
27
28
# Current frame number
29
curr_frame = 0
30
31
# Reads the frame and stores it in the directory
32
while True:
33
    inp.set(cv2.CAP_PROP_POS_FRAMES, curr_frame)  # Set the current frame manually
34
    ret, frame = inp.read()
35
36
    # Check if frame is read successfully
37
    if not ret:
38
        print(f"Failed to read frame {curr_frame} or end of video.")
39
        break
40
    
41
    # Save the frame as an image
42
    name = './inp_images/inp_image_' + str(curr_frame) + '.jpg'
43
    print(f"Creating... {name}")
44
    cv2.imwrite(name, frame)
45
    
46
    # Increment the frame counter
47
    curr_frame += 1
48
    
49
    # Optional: add a small delay to help with frame processing
50
    time.sleep(0.1)
51
52
    # Stop if we've processed all frames
53
    if curr_frame >= total_frames:
54
        break
55
56
# Release the video capture object and close any OpenCV windows
57
inp.release()
58
cv2.destroyAllWindows()