def test_02_trainingse_nont(self): images = glob.glob('train_imgs/non-vehicles/*/*.png') (clf, scaler) = class_train.load() counter = 0 for i in images: img = cnst.img_read_f(i) test_img = cv2.resize(img, (64, 64)) features = single_img_features(test_img, color_space=cnst.color_space, spatial_size=cnst.spatial_size, hist_bins=cnst.hist_bins, orient=cnst.orient, pix_per_cell=cnst.pix_per_cell, cell_per_block=cnst.cell_per_block, hog_channel=cnst.hog_channel, spatial_feat=cnst.spatial_feat, hist_feat=cnst.hist_feat, hog_feat=cnst.hog_feat) test_features = scaler.transform(np.array(features).reshape(1, -1)) #test_features = features prediction = clf.predict(test_features) if (prediction > 0.0): print("Prediction " + str(prediction) + " for " + i) counter = counter + 1 print((len(images) - counter) / len(images))
def test_01_multi(self): (svc, X_scaler) = class_train.load() image = cnst.img_read_f('test_images/test6.jpg') draw_image = np.copy(image) (hw, di) = hot_windows.multi_hot_wins(image, draw_image, svc, X_scaler, cnst.sizes) print(hw) mpimg.imsave("unit_test/test6_multi.jpg", di)
def test_01_ev(self): (svc, X_scaler) = class_train.load() image = cnst.img_read_f('test_images/test6.jpg') for s in sizes: draw_image = np.copy(image) (hw, di) = hot_windows.hot_wins(image, draw_image, svc, X_scaler, xy_window=(s, s)) print(hw) mpimg.imsave("unit_test/test6_" + str(s) + ".jpg", di)
def extract_features(imgs, color_space='RGB', spatial_size=(32, 32), hist_bins=32, orient=9, pix_per_cell=8, cell_per_block=2, hog_channel=0, spatial_feat=True, hist_feat=True, hog_feat=True): # Create a list to append feature vectors to features = [] # Iterate through the list of images for file in imgs: # Read in each one by one image = cnst.img_read_f(file) f = single_img_features(image, color_space, spatial_size, hist_bins, orient, pix_per_cell, cell_per_block, hog_channel, spatial_feat, hist_feat, hog_feat) features.append(f) # Return list of feature vectors return features
def test_01_trainingset(self): images = glob.glob('train_imgs/vehicles/GTI_Far/image0000.png') (clf, scaler) = class_train.load() for i in images: img = cnst.img_read_f(i) test_img = cv2.resize(img, (64, 64)) features = single_img_features(test_img, color_space=cnst.color_space, spatial_size=cnst.spatial_size, hist_bins=cnst.hist_bins, orient=cnst.orient, pix_per_cell=cnst.pix_per_cell, cell_per_block=cnst.cell_per_block, hog_channel=cnst.hog_channel, spatial_feat=cnst.spatial_feat, hist_feat=cnst.hist_feat, hog_feat=cnst.hog_feat) print(features.shape) print(features) print(len(features)) test_features = scaler.transform(np.array(features).reshape(1, -1)) #test_features = features prediction = clf.predict(test_features) print(str(prediction) + " : " + i)