I am trying to the do edge detection and apply laplacian, HOG on multiple images stored in a folder at a time for feature extraction but I am unable to do so. I have actually saved the images of the directory in a list and now when i am trying to process these images, it is throwing an error.
import numpy as np
import cv2
import os
import matplotlib.pyplot as plt
def resize():
data = []
img_size = 244
data_dir = r'C:\technocolab project2\testing'
for img in os.listdir(data_dir):
try:
imgPath = os.path.join(data_dir,img)
global images
images = cv2.imread(imgPath, cv2.IMREAD_GRAYSCALE)
global image_resized
image_resized = cv2.resize(images,(img_size,img_size))
data.append(image_resized)
#except Exception as e:
#print(e)
except:
pass
return data
data = resize()
for i in range(len(data)):
data[i]=data[i].astype('float32')
splitting the dataset
training = data[:int(0.2*len(data))]
validation = data[int(0.2*len(data)):int(0.4*len(data))]
testing = data[int(0.4*len(data)):int(0.5*len(data))]
train_norm =[]
valid_norm = []
test_norm = []
for a in range(len(training)):
train_norm.append(training[a]/255)
print(train_norm[0])
for b in range(len(validation)):
valid_norm.append(validation[b]/255)
print(valid_norm[0])
for c in range(len(testing)):
test_norm.append(testing[c]/255)
print(test_norm[0])
train_edge = []
for e in range(len(train_norm)):
train_edge.append(cv2.Canny(train_norm[e],90,300))
OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\canny.cpp:829: error: (-215:Assertion failed) _src.depth() == CV_8U in function 'cv::Canny'