0

I am trying to get HOG features on my images with the use of OpenCV. I have tried some of the solutions that I've read here: Get HOG image features from OpenCV + Python?

Here is the portion of my code:

hog = cv2.HOGDescriptor()

for i in Categories:
    path=os.path.join(datadir,i)
    for img in os.listdir(path):
        img_array=cv2.imread(os.path.join(path,img))
        img_resized=resize(img_array,(128,64))
        h = hog.compute(img_resized)
        hist = desc.describe(img_resized)
        feat = np.hstack([h,hist])
        flat_data_arr.append(feat)
        
        target_arr.append(Categories.index(i))
    print(f'loaded category:{i} successfully')
    
flat_data=np.array(flat_data_arr)
target=np.array(target_arr)
df=pd.DataFrame(flat_data)
df['Target']=target

However, all the solutions I've tried produces the same error:

OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\objdetect\src\hog.cpp:244: error: (-215:Assertion failed) img.type() == CV_8U || img.type() == CV_8UC3 in function 'cv::HOGDescriptor::computeGradient'
General Grievance
  • 4,555
  • 31
  • 31
  • 45

0 Answers0