I'm really trying to apply CLAHE to a directory of about 700 images. However, once I manage to get it running, for some reason the code stops before all the images are processed.
When I run it on Google Colab, it stops halfway (so at image# 355). Out of frustration I downloaded the image dataset to my local machine and tried to run it on a local Jupyter notebook, but even then it stops after 100 images. What's going on?
Here's my code:
import cv2 as cv
import shutil
import os
source = r"/All classes copy/0/"
destination = r"/temp dir/0/"
filelist = os.listdir(r"/All classes copy/0/")
clahe = cv.createCLAHE()
for x in filelist:
img = cv.imread(x,0)
cl1 = clahe.apply(img)
cv.imwrite(os.path.join(destination, x),cl1)
print(os.path.join(source, x), '>>>', os.path.join(destination, x))
filelist0.pop()
Here's the error, which comes up only after a couple hundred images have been CLAHE'd:
---------------------------------------------------------------------------
error Traceback (most recent call last)
Input In [28], in <cell line: 11>()
12 img = cv.imread(x,0)
13 cl1 = clahe.apply(img)
---> 14 cv.imwrite(os.path.join(r"/temp dir/0/", x),cl1)
15 print(os.path.join(source, x), '>>>', os.path.join(destination, x))
16 filelist0.pop()
error: OpenCV(4.6.0) /Users/runner/work/opencv-python/opencv-python/opencv/modules/imgcodecs/src/loadsave.cpp:801: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'
However I know for sure that these images do exist! It processes more images in Colab than locally. Is this a stability issue with OpenCV? Or is it that I'm running out of RAM?