首页 > 解决方案 > 错误:“NoneType”和“int”的实例之间不支持“>”

问题描述

我正在尝试运行此代码,但是出现 TypeError: '>' not supported between 'NoneType' 和 'int' 的实例。我能做些什么来消除这个错误?我仍然是使用 python 的初学者。希望任何人都可以帮助我。

author = 'Rocco'

    import math
    
    import numpy as np 
    import cv2 from skimage 
    import feature from scipy 
    import ndimage 

class PHogFeatures(): 
def init(self): 
pass
    
    def get_features(self, image_path, bins=8, angle=360., pyramid_levels=3):

        feature_vec = self.phog(image_path, bins, angle, pyramid_levels)
        feature_vec = feature_vec.T[0]  # Transpose vector, take the first array
        return feature_vec

    def phog(self, image_path, bin, angle, pyramid_levels): 
         grayscale_img = cv2.imread(r'C:\Users\user\Documents\FYP\Dataset\Train', 0) # 0 converts it to grayscale 
         bh = np.array([]) 
         bv = np.array([])
    
    if np.sum(np.sum(grayscale_img)) > 100.:
         edges_canny = feature.canny(grayscale_img, sigma=math.sqrt(2)) 
         [GradientY, GradientX] = np.gradient(np.double(grayscale_img)) 
         GradientYY = np.gradient(GradientY)[1] # Take only the first matrix 
         Gr = np.sqrt((GradientX * GradientX + GradientY * GradientY))
    
         index = GradientX == 0.
         index = index.astype(int)  # Convert boolean array to an int array
         GradientX[np.where(index > 0)] = np.power(10, -5)
         YX = GradientY / GradientX

这是我得到的错误截图

标签: pythonerror-handlingcompiler-errorsjupyter-notebooksyntax-error

解决方案


推荐阅读