I have the following code, which is supposed to
- go through all files
- Collect all photos which belong in folders "0" or "1"
- Transform the photos a bit
- Place them into a new folders,---all "0-photos" go to a unique folder. Same for 1
Here it is
import cv2
import os
import random as rnd
outdir0='cancerdata\\0'
outdir1='cancerdata\\1'
readdir='sample'
j=0;
for dirs in os.listdir(readdir):
dpath=os.path.join(readdir,dirs)
for subdir in os.listdir(dpath):
fpath=os.path.join(dpath,subdir)
for file in os.listdir(fpath):
rfile=os.path.join(fpath,file)
image=cv2.imread(rfile,0)
size=rnd.randint(50,100)
img=cv2.resize(image,(size,size),interpolation=cv2.INTER_AREA)
print(img)
if subdir == '0':
wfile=os.path.join(outdir0,file)
cv2.imwrite(os.path.join(outdir0,file),img)
elif subdir == '1':
wfile=os.path.join(outdir1,file)
cv2.imwrite(os.path.join(outdir1,file),img)
It does NOT give an error, but for some reason does not save any of the files. Whenever I try to save a single image via
cv2.imwrite(r'sample\cancerdata\1\8865_idx5_x2101_y851_class1.png',img)
All I get is FALSE.