{"id":22555385,"url":"https://github.com/dakedroid/deteccion-vehiculos-python-tensorflow","last_synced_at":"2025-03-28T10:46:24.488Z","repository":{"id":266356160,"uuid":"898120411","full_name":"dakedroid/deteccion-vehiculos-python-tensorflow","owner":"dakedroid","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-03T20:52:31.000Z","size":78757,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T11:28:51.243Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dakedroid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-03T20:31:09.000Z","updated_at":"2024-12-03T20:52:34.000Z","dependencies_parsed_at":"2024-12-03T21:42:52.313Z","dependency_job_id":null,"html_url":"https://github.com/dakedroid/deteccion-vehiculos-python-tensorflow","commit_stats":null,"previous_names":["dakedroid/deteccion-vehiculos-python-tensorflow"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakedroid%2Fdeteccion-vehiculos-python-tensorflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakedroid%2Fdeteccion-vehiculos-python-tensorflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakedroid%2Fdeteccion-vehiculos-python-tensorflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakedroid%2Fdeteccion-vehiculos-python-tensorflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dakedroid","download_url":"https://codeload.github.com/dakedroid/deteccion-vehiculos-python-tensorflow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246015453,"owners_count":20709988,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-07T19:07:42.933Z","updated_at":"2025-03-28T10:46:24.461Z","avatar_url":"https://github.com/dakedroid.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vehicle Detection\n\n\nThe goals / steps of this project are the following:\n\n* Perform a Histogram of Oriented Gradients (HOG) feature extraction on a labeled training set of images and train a classifier Linear SVM classifier\n* Optionally, you can also apply a color transform and append binned color features, as well as histograms of color, to your HOG feature vector. \n* Note: for those first two steps don't forget to normalize your features and randomize a selection for training and testing.\n* Implement a sliding-window technique and use your trained classifier to search for vehicles in images.\n* Run your pipeline on a video stream (start with the test_video.mp4 and later implement on full project_video.mp4) and create a heat map of recurring detections frame by frame to reject outliers and follow detected vehicles.\n* Estimate a bounding box for vehicles detected.\n\n### Dataset\n\nIn this project I use two datasets. Here are links to the labeled data for [vehicle](https://s3.amazonaws.com/udacity-sdc/Vehicle_Tracking/vehicles.zip) and [non-vehicle](https://s3.amazonaws.com/udacity-sdc/Vehicle_Tracking/non-vehicles.zip) examples to train your classifier. These example images come from a combination of the [GTI vehicle image database](http://www.gti.ssr.upm.es/data/Vehicle_database.html), the [KITTI vision benchmark suite](http://www.cvlibs.net/datasets/kitti/), and examples extracted from the project video itself.\n\nNumber of vehicle images: 8792\nNumber of non-vehicle images: 8968\n\nBelow, there are a few examples from these datasets. \n\n\u003cimg src=\"./output_images/Vehicles_example.png\"\u003e\u003c/br\u003e\u003c/br\u003e\n\u003cimg src=\"./output_images/NonVehicles_example.png\"\u003e\u003c/br\u003e\u003c/br\u003e\n\n### Histogram of Oriented Gradients (HOG)\n\nThe code for this step is contained in lines 108 through 215 of the file called `VehicleDetection.py`.   \n\nI then explored different color spaces and different `skimage.hog()` parameters (`orientations`, `pixels_per_cell`, and `cells_per_block`).  I grabbed random images from each of the two classes and displayed them to get a feel for what the `skimage.hog()` output looks like.\n\nHere is an example using the `RGB` color space and HOG parameters of `orientations=8`, `pixels_per_cell=(8, 8)` and `cells_per_block=(2, 2)`:\n\n\u003cimg src=\"./output_images/HOG_visualization.png\"\u003e\u003c/br\u003e\u003c/br\u003e\n\n\n#### HOG parameters.\n\nI tried various combinations of parameters. After a few iterations of training SVM classifier I decided to set the following HOG parameters.\n\ncolor_space = 'YCrCb' # Can be RGB, HSV, LUV, HLS, YUV, YCrCb\u003c/br\u003e\norient = 8  # HOG orientations\u003c/br\u003e\npix_per_cell = 8 # HOG pixels per cell\u003c/br\u003e\ncell_per_block = 1 # HOG cells per block\u003c/br\u003e\nhog_channel = 'ALL' # Can be 0, 1, 2, or \"ALL\"\u003c/br\u003e\nspatial_size = (16, 16) # Spatial binning dimensions\u003c/br\u003e\nhist_bins = 64    # Number of histogram bins\u003c/br\u003e\nspatial_feat = True # Spatial features on or off\u003c/br\u003e\nhist_feat = True # Histogram features on or off\u003c/br\u003e\nhog_feat = True # HOG features on or off\u003c/br\u003e\n\n#### SVM classifier\n\nI trained a linear SVM in lines 485 through 538 of the file called `VehicleDetection.py`. As noted above (HOG parameters) except HOG features, also spatial color features and color histogram features are taken to the SVM classifier.\n\nI used SVM classifier from sklearn library with linear kernel and default parameters. Also I used StandardScaler for feature normalization along resulting dataset. The final obtained accuracy was 0.9887. \n\n#### Sliding Window Search\n\nThe code for this part is located in lines 625 through 730 of the file called `VehicleDetection.py`. For different y positions I defined different windows scales as below:\n\nystart = 370\u003c/br\u003e\nystop = 500\u003c/br\u003e\nscale = 1.0\u003c/br\u003e\n    \u003c/br\u003e\nystart = 400\u003c/br\u003e\nystop = 600\u003c/br\u003e\nscale = 1.5\u003c/br\u003e\n\u003c/br\u003e\nystart = 400\u003c/br\u003e\nystop = 650\u003c/br\u003e\nscale = 2.0\u003c/br\u003e\n\u003c/br\u003e\nystart = 450\u003c/br\u003e\nystop = 660\u003c/br\u003e\nscale = 2.5\u003c/br\u003e\n\nTypically, there are a several window detections for a car. On the other hand there are only a few detections for false positives. Therefore, to differenciate between these two situations, there is a add_heat function added to a pipeline. It returns bigger intensity for these pixels, which are multiple times classified as car. After applying a threshold, we can decide if the region is a car or not.\n\n#### Final pipeline results\n\nBelow, there is a final result presented. For an exemplary 6 images, all ddetected bounding boxes are showed. The middle image presents a heat map, while the last outputs the final result after thresholding the heatmap.\n\n\u003cimg src=\"./output_images/test1_output.png\"\u003e\u003c/br\u003e\u003c/br\u003e\n\u003cimg src=\"./output_images/test2_output.png\"\u003e\u003c/br\u003e\u003c/br\u003e\n\u003cimg src=\"./output_images/test3_output.png\"\u003e\u003c/br\u003e\u003c/br\u003e\n\u003cimg src=\"./output_images/test4_output.png\"\u003e\u003c/br\u003e\u003c/br\u003e\n\u003cimg src=\"./output_images/test5_output.png\"\u003e\u003c/br\u003e\u003c/br\u003e\n\u003cimg src=\"./output_images/test6_output.png\"\u003e\u003c/br\u003e\u003c/br\u003e\n\n### Video Implementation\n\nHere's a [link](./project_video_output.mp4) to the final video after processing with the developed pipeline.\n\nWhen using the developed pipeline I noticed that there are still some false positives detected. But they are present only for 1-2 frames. Therfore, we can filter them out using moveing average of the heat map. Then I perform thresholding and labeling on the averaged heat map. By using this technique also the bounding boxes will be much more stable. To perform this operation `collections.deque` library was used (lines 779 to 802) with the maxlen parameter (number of stored frame) set to 8.\n\n### Discussion\n\nThe pipeline generally works fine. But it is possible to fail when there is a vehicle object which is not similar to any of objects present in vehicles dataset. The final result can be also worse in rainy conditions or during a night. As we can see in the output video, where vehicles occlude, the pipeline returns one big object instead 2 occluding cars.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdakedroid%2Fdeteccion-vehiculos-python-tensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdakedroid%2Fdeteccion-vehiculos-python-tensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdakedroid%2Fdeteccion-vehiculos-python-tensorflow/lists"}