Closed Qasimster closed 3 years ago
Hi @Qasimster - what comes to mind is the file path that you write the file to (Videoclassi/ttt/) might not exist. If you write to a path that does not exist it can appear like opencv are saving the frames but you won't find them.
Before your loop, after grabbing the video:
import os
my_path = r"D:\New Projects Pycharm\Videoclassi\tttt"
if not os.path.exists(my_path)
os.makedirs(my_path)
and in your loop:
filename = 'frame' + str(counter) + '.png'
save_name.= os.path.join(my_path, filename)
cv2.imwrite(save_name, frame)
counter+=1
Sir tttt exists and i tried your method too still it isnt working. Have a look
import cv2 # for capturing videos import math # for mathematical operations import matplotlib.pyplot as plt # for plotting the images
import pandas as pd from keras.preprocessing import image # for preprocessing the images import numpy as np # for mathematical operations from keras.utils import np_utils from skimage.transform import resize # for resizing images from sklearn.model_selection import train_test_split import glob from tqdm import tqdm
f = open("trainlist01.txt", "r") temp = f.read() videos = temp.split('\n')
train = pd.DataFrame() train['video_name'] = videos train = train[:-1] print("Train ",train.head())
f = open("testlist01.txt", "r") temp = f.read() videos = temp.split('\n')
test = pd.DataFrame() test['video_name'] = videos test = test[:-1] print("Test ",test.head())
print("-----------------------------------------------------------------------------------------------------------")
train_video_tag = [] for i in range(train.shape[0]): train_video_tag.append(train['video_name'][i].split('/')[0])
train['tag'] = train_video_tag
test_video_tag = [] for i in range(test.shape[0]): test_video_tag.append(test['video_name'][i].split('/')[0])
test['tag'] = test_video_tag
print("Train tags ----------------") print(train['tag']) print('---------------------------------------------------------') print("Test tags ------------------") print(test['tag'])
print("-----------------------------------------------------------------------------------------------------------")
for i in tqdm(range(train.shape[0])): count = 0 videoFile = train['video_name'][i] cap = cv2.VideoCapture('UCF/'+videoFile.split(' ')[0].split('/')[1]) # capturing the video from the given path frameRate = cap.get(5) #frame rate x=1 while(cap.isOpened()): frameId = cap.get(1) #current frame number ret, frame = cap.read() if (ret != True): break if (frameId % math.floor(frameRate) == 0):
my_path = r"D:\New Projects Pycharm\Videoclassi\tttt"
if not os.path.exists(my_path):
os.makedirs(my_path)
filename = 'frame' + str(counter) + '.png'
save_name= os.path.join(my_path, filename)
cv2.imwrite(save_name, frame)
counter += 1
cap.release()
Just before saving the frame in the script, do a:
print(frame) print(save_name)
It's either of those two, or both but most likely the path. What's printed?
It displays nothing.
nothing? does it print an empty string?
It just displays nothing not even empty string
Hmm.. that would mean that the code does not reach the print statement, it gets stuck somewhere before
Whenever i extract frame rates from a video dataset folder to a train_1 folder. After extracting frame rates the folder is empty where as pycharm shows it has been done successfully. Any one aware of this issue? My code for i in tqdm(range(train.shape[0])): count = 0 videoFile = train['video_name'][i] cap = cv2.VideoCapture('UCF/'+videoFile.split(' ')[0].split('/')[1]) # capturing the video from the given path frameRate = cap.get(5) #frame rate x=1 while(cap.isOpened()): frameId = cap.get(1) #current frame number ret, frame = cap.read() if (ret != True): break if (frameId % math.floor(frameRate) == 0):
storing the frames in a new folder named train_1
Originally posted by @Qasimster in https://github.com/sgoldenlab/simba/issues/8#issuecomment-756070871