project05.frame module¶
-
class
project05.frame.
Frame
(img=None, imgpath=None, min_row=0, max_row=None, scale=1.0, spatial_cspace='BGR', hist_cspace='BGR', hog_cspace='BGR', spatial_size=32, hist_bins=32, hist_range=(0, 256), hog_orientations=9, hog_pix_per_cell=8, hog_cell_per_block=2, hog_cells_per_step=2, hog_block_norm='L1', hog_channel='ALL', spatial_feat=True, hist_feat=True, hog_feat=True, heat_thresh=2, prev=None, prev_thresh=2)[source]¶ Bases:
object
-
bin_spatial
(img, cspace0='BGR', visualize=False)[source]¶ Compute binned color features
Parameters: - img (numpy.ndarray) – The image for which we are computing features
- cspace0 (str) – The colorspace that
img
is currently in (e.g., ‘BGR’) - visualize (bool) – Also return an image of the spatial color feature
Returns: - numpy.ndarray – The stacked color features
- img (numpy.ndarray (if visualise=True)) – The color features image
-
color_hist
(img, cspace0='BGR', visualize=False)[source]¶ Compute color histogram features
Parameters: - img (numpy.ndarray) – The image for which we are computing features
- cspace0 (str) – The colorspace that
img
is currently in - visualize (bool) – Also return an image of the color histogram feature
Returns: - numpy.ndarray – The concatenated histograms
- hists (list (if visualise=True)) – A list of the histograms
-
draw_bboxes
(bbox_list, color=(0, 0, 255), thickness=6)[source]¶ Draw boxes on the
Frame
object’s imageParameters: - bbox_list (list) – A list of
((x1, y1), (x2, y2))
coordinates for drawing boxes - color (tuple) – The color that the boxes should be drawn
- thickness (int) – Thickness of lines that make up the rectangle
Returns: draw_img – The image with boxes drawn on it
Return type: numpy.ndarray
- bbox_list (list) – A list of
-
extract_features
()[source]¶ Extract HOG, spatial and/or color features from an image
This method is for extracting features from training images
See Frame.bin_spatial, Frame.color_hist, and Frame.get_hog_features
Returns: features – The concatenated features Return type: numpy.ndarray
-
find_cars
(**kwargs)[source]¶ Find cars using the heatmap
See Frame.get_heatmap
Parameters: **kwargs (dict) – Keyword arguments for Frame.get_bboxes / Frame.get_heatmap
-
get_bboxes
(svc=None, X_scaler=None, scales=[1], min_rows=[None], max_rows=[None], cells_per_steps=[None])[source]¶ Extract features from an image, apply the classifier, and generate
self.heatmap
This method is for finding cars on a real world image (i.e., not a cropped training image)
See Frame.bin_spatial, Frame.color_hist, and Frame.get_hog_features
Parameters: - svc (sklearn.svm.classes.LinearSVC) – SVM classifier
- X_scaler (sklearn.preprocessing.data.StandardScaler) – Feature scaler
- scales (list) – The scales (
self.scale
) at which to run the feature extraction and classifier - min_rows (list) – A list of the minimum rows for cropping the image
- max_rows (list) – A list of the maximum rows for cropping the image
- cells_per_steps (list) – A list of the values for
self.hog_cells_per_step
-
get_heatmap
(**kwargs)[source]¶ Extract features from an image, apply the classifier, and generate
self.heatmap
See Frame.get_bboxes
Parameters: - **kwargs (dict) – Keyword arguments for Frame.get_heatmap
- method is for finding cars on a real world image (i.e., not a cropped training image) (This) –
- Frame.bin_spatial, Frame.color_hist, and Frame.get_hog_features (See) –
- svc (sklearn.svm.classes.LinearSVC) – SVM classifier
- X_scaler (sklearn.preprocessing.data.StandardScaler) – Feature scaler
- scales (list) – The scales (
self.scale
) at which to run the feature extraction and classifier - min_rows (list) – A list of the minimum rows for cropping the image
- max_rows (list) – A list of the maximum rows for cropping the image
- cells_per_steps (list) – A list of the values for
self.hog_cells_per_step
-
get_hog_features
(img, cspace0='BGR', visualize=False, feature_vector=False)[source]¶ Extract a Histogram of Oriented Gradients (HOG) for the
Frame
object’s imageParameters: - img (numpy.ndarray) – The image for which we are computing features
- cspace0 (str) – The colorspace that
img
is currently in (e.g., ‘BGR’) - visualize (bool) – Also return an image of the HOG
- feature_vector (bool) – Return the data as a feature vector by calling .ravel() on the result just before returning
Returns: - features (list) – A list of HOG arrays (1 numpy array for each image channel)
- hog_image (list (if visualise=True)) – A list of visualisations of the HOG images (1 numpy array for each image channel)
-
get_windows
()[source]¶ Get a list of all the windows that will be searched for cars
Returns: bbox_list – A list with entries of the form (xy, xy_hog, xy_color)
, where eachxy
term is of the form((x0, y0), (x1, y1))
and specifies a bounding box for the original image, the HOG-processed image, and the patch image used by Frame.color_hist and Frame.bin_spatialReturn type: list
-
img
¶ Return a
Frame
object’s rescaled associated imageReturns: The Frame
object’s rescaled imageReturn type: numpy.ndarray
-
img0
¶ Return a
Frame
object’s original associated imageReturns: The Frame
object’s original imageReturn type: numpy.ndarray
-
-
project05.frame.
convert_color
(img, cspace=None, cspace0='BGR')[source]¶ Convert
img
to colorspacecspace
Parameters: - img (numpy.ndarray) – The image
- cspace (str, None) – The image will be converted to this colorspace (e.g., ‘BGR’)
- cspace0 (str) – The colorspace that
img
is currently in
Returns: The image in the specified colorspace
Return type: numpy.ndarray