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/Fighting/.DS_Store in function 'icvExtractPattern'

Hi all,

I am conducting my processing and I am getting an unusual error that I am not sure how to interpret.
Can someone help me understand this error, please?

I have my code located in the datastore and what is funny is that the same code is running efficiently sometimes on the same data and then suddenly I am presented with this error.

MY 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)]
        else:
            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 = cap.read()
            frame = cv2.resize(frame, (self.height, self.width))
            if color:
                framearray.append(frame)
            else:
                framearray.append(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY))

        cap.release()
        return np.array(framearray)



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

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

My Errors****************************


Generating/Join Class Labels For Video Dataset For Input Completed
100%|█████████████████████████████████████████████| 5/5 [00:21<00:00,  5.49s/it]OpenCV: Couldn't read video stream from file "./dataset/Fighting/.DS_Store"
[ERROR:0@25.086] 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/Fighting/.DS_Store in function 'icvExtractPattern'


Traceback (most recent call last):
  File "3dcnn9.py", line 1053, in <module>
    main()
  File "3dcnn9.py", line 318, in main
    x, y = loaddata(args.videos, vid3d, args.nclass,
  File "3dcnn9.py", line 205, in loaddata
    X.append(vid3d.video3d(name, color=color, skip=skip))  
  File "/Users/mmgp0hotmail.com/opt/3DCNN/3DCNNtesting/videoto3d.py", 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'

that’s some macos-specific file. don’t read that.

how does that path manage to reach VideoCapture?

My initialisation packages.p file code below that calls another 3dcnn.py file

# %% Initialise 3DCNN Activity Recognition
!python 3dcnn9.py --batch 130 --epoch 2 --videos ./dataset/ --nclass 2 --output 3dcnnresult/ --color True --skip False --depth 12
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/mmgp0hotmail.com/opt/3DCNN/3DCNNtesting/dataset'
    
    dirlist = [item for item in os.listdir(
        root) if os.path.isdir(os.path.join(root, item))]
    print('**********************************************************')
    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):
            file_paths.append(file_path)
            print('**********************************************************')
            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('**********************************************************')
    print('ALL Directory ROOTED', roots, fitte, dirsy)

    print('**********************************************************')
    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('**********************************************************')
    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)
        pbar.update(1)
        if filename == '.DS_Store':
            continue

        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 Video3d.py
            label = vid3d.get_UCF_classname(filename)
            
            labels.append(label)

            if label not in labellist:
                if len(labellist) >= nclass:
                    continue
                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)) 

I reckon it has something to do with the directory but I am finding this rather challenging to decipher, please help and thanx in advance.
Oh by the way I tried this morning and this is the approach that was taken:

I have two classes with its subfolders: Class 1 Neutral & Class 2 Violence

Class1: Neutral which is one folder and then its subclasses inside that folder WlkFast & WlkSlow
Class2: Violence which is one folder and then its subclasses inside that folder Kicking & Punching

This approach was futile:
What i am really trying to do is call or rather pass all of the classes inclusive of the subclasses in the process
This will help me to understand what action is being performed from a high level and then sub level
for example the action detected is Netrual subclass walking

This is the best way i can represent my efforts and I am hoping that you may get the gist of the operations

thank you loads in advance… standing by

How do I get rid of the .DS_Store file? I’ve been looking this morning at this as well but nothing seems to be functioning

os.listdir call… when you iterate over those names, filter them (continue if conditions don’t match). everything has to be a file, and it’s best to check the file extension. if you have only pictures of one type, you could just check file_name.endswith(".png")

that code uses listdir for listing directories too, so don’t touch that. mind the directory structure.

this is what is confusing me!!!???!

the files are located in the right place?? this works for four classes of the same data for example

‘’’
ALL Directory ROOTED /Users/mmgp0hotmail.com/opt/3DCNN/3DCNNtesting/dataset [’.DS_Store’] [‘Violence’, ‘Neutral’]
‘’’

What i tried?
I add four different classes in the same location to see if that would do anything and that worked
I have four classes:
wlk fast 40 videos
Wlk slow 40 vids
Punching 40 vids
Kicking 40 vids

so, if I am using the same data as above in two classes as per the Neutral and Violence:
Why is it causing the error!!!

‘’’
Generating/Join Class Labels For Video Dataset For Input Completed
100%|█████████████████████████████████████████████| 3/3 [00:08<00:00, 2.98s/it]OpenCV: Couldn’t read video stream from file “./dataset/Neutral/.DS_Store”
[ERROR:0@10.270] 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/Neutral/.DS_Store in function ‘icvExtractPattern’

Traceback (most recent call last):
File “3dcnn9.py”, line 1055, in
main()
File “3dcnn9.py”, line 321, in main
x, y = loaddata(args.videos, vid3d, args.nclass,
File “3dcnn9.py”, line 208, in loaddata
X.append(vid3d.video3d(name, color=color, skip=skip))
File “/Users/mmgp0hotmail.com/opt/3DCNN/3DCNNtesting/videoto3d.py”, 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%|█████████████████████████████████████████████| 3/3 [00:09<00:00, 3.22s/it]
‘’’

the file types are all .avi videos by the way. that was the first thing I checked… and thanx for your response but this is still ongoing…
Please help if you canthis is mind-boggling!!

if .DS_Store is a directory, you need to skip it in your code.

maybe you can use python’s builtin glob function
as it allows you to filter for specific file types (like .avi)

Hi programming analysts,

I think I figured it out, it has to do with the labelling of the dataset. For example:

Some of the data are not been initialised as the operations are searching for the files in sequence and the dataset labelling format was not in sequence. As soon as this was altered, the processing was concluded. See below and thanx so much in advance, I really appreciated your efforts!

cheers!

Previous Labelling
‘’’
v_WalkingWithDog_g01_c01
v_WalkingWithDog_g01_c02
v_WalkingWithDog_g02_c03
v_WalkingWithDog_g02_c04
v_WalkingWithDog_g03_c05
v_WalkingWithDog_g03_c06
‘’’
Current labelling
‘’’
v_WalkingWithDog_g01_c0
v_WalkingWithDog_g01_c1
v_WalkingWithDog_g01_c2
v_WalkingWithDog_g01_c3
v_WalkingWithDog_g01_c4
v_WalkingWithDog_g01_c5
‘’’