CAP_IMAGES: can't find starting number (in the name of file)

Hi programming experts,

I am having an extreme challenge trying to understand an error dispensed from my code:

I am running code to process 6 classes of 40 videos per class, one class is continuously causing the system to throw errors:

What did I do?

  1. I tried reviewing all of the videos from the problems class A and compared this with what is working in B and nothing seems to be an issue there.

  2. I checked the size of the videos, colour and resolutions in the working class B and it is a range of RGB and grayscale, what is constant is that the size of such is 320 x 240 resolution. In problem class A this is the same as well as all of the file extensions (.avi).

  3. In online forums they mentioned the label names, but I tried using the label names from the working class and that was useless. There are various labelling strategies I tried and that was also pointless.

  4. So now that the videos seem to be ok, I targeted the code but everywhere I google the solutions seems to be evading me. And this is challenging me to get a full understanding of what is actually happening.

Can someone guide me here, please?
This is literally consuming my time and I am pretty sure it is something trivial but yet I cannot seem to see this!

*** The Code***

import numpy as np
import cv2

class Videoto3D:

    def __init__(self, width, height, depth):
        self.width = width
        self.height = height
        self.depth = depth

    def video3d(self, filename, color=False, skip=True):
        cap = cv2.VideoCapture(filename)
        nframe = cap.get(cv2.CAP_PROP_FRAME_COUNT)
        if skip:
            frames = [x * nframe / self.depth for x in range(self.depth)]
            frames = [x for x in range(self.depth)]
        framearray = []

        for i in range(self.depth):
            cap.set(cv2.CAP_PROP_POS_FRAMES, frames[i])
            ret, frame =
            frame = cv2.resize(frame, (self.height, self.width))
            if color:
                framearray.append(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY))

        return np.array(framearray)

    def get_UCF_classname(self, filename):
        return filename# Controls the length of the class Name

 # def get_UCF_classname(self, filename):
 #     return filename[filename.find('_') + 1:filename.find('_', 20)]# Controls the length of the class Name


Processing All Class Labels For Video Data Input Completed
  0%|                                                     | 0/6 [00:00<?, ?it/s]**********************************************************
Generating/Join Class Labels For Video Dataset For Input Completed
100%|█████████████████████████████████████████████| 6/6 [00:12<00:00,  2.72s/it]OpenCV: Couldn't read video stream from file "./dataset/Shooting/.DS_Store"
[ERROR:0@13.430] global /Users/runner/work/opencv-python/opencv-python/opencv/modules/videoio/src/cap.cpp (166) open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.5.5) /Users/runner/work/opencv-python/opencv-python/opencv/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): ./dataset/Shooting/.DS_Store in function 'icvExtractPattern'

Traceback (most recent call last):
  File "", line 1009, in <module>
  File "", line 321, in main
    x, y = loaddata(args.videos, vid3d, args.nclass,
  File "", line 208, in loaddata
    X.append(vid3d.video3d(name, color=color, skip=skip))  
  File "/Users/", line 25, in video3d
    frame = cv2.resize(frame, (self.height, self.width))
cv2.error: OpenCV(4.5.5) /Users/runner/work/opencv-python/opencv-python/opencv/modules/imgproc/src/resize.cpp:4052: error: (-215:Assertion failed) !ssize.empty() in function 'resize'

100%|█████████████████████████████████████████████| 6/6 [00:12<00:00,  2.14s/it]

silly apple programs leave folders like this on your disk, it’s just garbage that gets in your way. (and you probably cant see “hidden” files starting with a dot in your directory)

either try to remove it manually, or filter filenames while reading in your videos
(e.g. ignore anything starting with a dot)

Hi @berak,

The thing is that it works, just not with this specific class. Relative to your answer is there a way to do this?
Can you. guide me via a link, pretty please?

oh, by the way, thank you for responding so swiftly!!

AND I just removed the .ds files as you suggested but the same error is occurring!!

are you sure it is this file or it has something to do with a size structure?
please assist, going bonkers here loloz

can you show, how you read the video files ?

python has a builtin glob function to traverse folders, you can filter for positives like *.avi

hi @berak,

See the code below for reading the classes of the video data:

and thanx once more for assisting so swiftly, really appreciate this!

def loaddata(video_dir, vid3d, nclass, result_dir, color=False, skip=True):
# This loads the .DS_Store in the class incrementing the number of classes by one

files = os.listdir(video_dir)
root = '/Users/'

dirlist = [item for item in os.listdir(
    root) if os.path.isdir(os.path.join(root, item))]
print('DIRLIST Directory Completed', dirlist)

file_paths = []
for file_name in os.listdir(root):
    file_path = os.path.join(root, file_name)
    if os.path.isfile(file_path):
        print('ALL Directory File Paths Completed', file_paths)

# folder_names = []
# for entry_name in os.listdir(root):
#     entry_path = os.path.join(root, entry_name)
#     if os.path.isdir(entry_path):
#         folder_names.append(entry_name)
#         print('**********************************************************')
#         print('ALL Directory Folder Names Completed',file_paths)

roots, dirsy, fitte = next(os.walk(root), ([], [], []))
print('ALL Directory ROOTED', roots, fitte, dirsy)

print('Processing All Class Labels For Video Data Input Completed')

X = []
# print('X labels==>', X)
labels = []
# print('The Processed Labels ==>', labels)
labellist = []
# print('Lablelist', labellist)

pbar = tqdm(total=len(files))  # generate progress bar for file processing

print('Generating/Join Class Labels For Video Dataset For Input Completed')

Accessing files and labels from dataset directory

for filename in files:
    # print('**********************************************************')
    # print('This is my Filename before join',filename)
    if filename == '.DS_Store':#.DS_Store

    namelist = os.path.join(video_dir, filename)
    # print('**********************************************************')
    # print('This is my namelist after join',namelist)#PRINTS ALL CLASSName Files
    # print('**********************************************************')
    # print('This is the name list',namelist)

    files2 = os.listdir(namelist)
    # print('**********************************************************')
    # print('This is the files2 For Class Filename',files2)#PRINTS ALL CLASSName Files

    for files3 in files2:
        name = os.path.join(namelist, files3)
        # print('**********************************************************')
        # print('This is Name For Class Filename',name)#PRINTS ALL CLASSName Files
        # print("ok")
        #print("dir is ", name)
        # getting all class names for processing
        # Calls the filename from
        label = vid3d.get_UCF_classname(filename)

        if label not in labellist:
            if len(labellist) >= nclass:
            labellist.append(label)  # storing labellist of files
            # print("This is the labellist ",labellist.append(label))
        # labels.append(label)  # storing labels
        #print("This is the labels ",labels.append(label))

        X.append(vid3d.video3d(name, color=color, skip=skip))  



again, you have to skip it (however you accomplish that)

@berak thanx pal will work on it, no luck yet but working on it

@berak I got it to work, it was one of the videos that were corrupted in the preprocessing stages thank you for your assistance… so grateful for you coming to my rescue!

I went through all of the files as I couldn’t believe that that was the case and there it was a silly error!

Happy sunday!