def neg_hog_rand(path, num_samples, window_size, num_window_per_image):
rows = window_size[0]
cols = window_size[1]
features = []
cnt = 0
for dirpath, dirnames, filenames in walk(path):
for my_file in filenames:
if cnt < num_samples:
print cnt,my_file
cnt = cnt + 1
im = cv2.imread(path + my_file)
image = color.rgb2gray(im)
image_rows = image.shape[0]
image_cols = image.shape[1]
for i in range(0,num_window_per_image):
x_min = random.randrange(0,image_rows - rows)
y_min = random.randrange(0,image_cols - cols)
x_max = x_min + rows
y_max = y_min + cols
image_hog = image[x_min:x_max , y_min:y_max]
my_feature, _ = hog(image_hog, orientations=9, pixels_per_cell=(8, 8),cells_per_block=(2, 2), visualise=True)
features.append(my_feature)
return features
评论列表
文章目录