def hog_features_list(img, hog_channel, orient, pix_per_cell, cell_per_block, color_space='BGR'): if color_space != 'BGR': img = CameraImage.convert_color_space(img, color_space) hif_list = [] if hog_channel == 'ALL': for channel in range(img.shape[2]): hif_list.append(HogImageFeatures( img[:, :, channel], orient, pix_per_cell, cell_per_block)) else: hif_list.append(HogImageFeatures( img[:, :, hog_channel], orient, pix_per_cell, cell_per_block)) return hif_list
def hog_channel_features(img_channel, sp: SearchParams, vis=False, feature_vec=False, transform_sqrt=False): orient = sp.orient pix_per_cell, cell_per_block = sp.pix_per_cell, sp.cell_per_block hif = HogImageFeatures(img_channel, orient, pix_per_cell, cell_per_block) return hif.features
def feature_extract(image, cspace='BGR', orient=9, pix_per_cell=8, cell_per_block=2, hog_channel=0, spatial_size=(32, 32), hist_bins=32, hist_range=(0, 256)): # apply color conversion if other than 'RGB' if cspace != 'BGR': if cspace == 'HSV': feature_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) elif cspace == 'LUV': feature_image = cv2.cvtColor(image, cv2.COLOR_BGR2LUV) elif cspace == 'HLS': feature_image = cv2.cvtColor(image, cv2.COLOR_BGR2HLS) elif cspace == 'YUV': feature_image = cv2.cvtColor(image, cv2.COLOR_BGR2YUV) elif cspace == 'YCrCb': feature_image = cv2.cvtColor(image, cv2.COLOR_BGR2YCrCb) else: feature_image = np.copy(image) # bsf = BinSpatialFeatures(feature_image, size=spatial_size) # chf = ColorHistFeatures( # feature_image, nbins=hist_bins, bins_range=hist_range) # Call get_hog_features() hog_features = Features([]) if hog_channel == 'ALL': for channel in range(feature_image.shape[2]): hog_features += HogImageFeatures(feature_image[:, :, channel], orient, pix_per_cell, cell_per_block) else: hog_features += HogImageFeatures(feature_image[:, :, hog_channel], orient, pix_per_cell, cell_per_block) # return np.concatenate((hog_features.values, chf.values)) # features = hog_features + chf return hog_features.features