pyCarDisplay.detection package¶
Subpackages¶
Submodules¶
pyCarDisplay.detection.depth_detection_api module¶
This is the depth detection module.
We borrowed this code from the MiDaS GitHub repository, authored by intel-isl. We then modified the code to work with the pyCarDisplay library. This code obtains an image and turns it into a colorized heat map based on the depth of objects within the environment. Original functionality is preserved, but functionality is wrapped within a class with new additions.
- Reference:
“MiDaS,” Pytorch.org. [Online]. Available: https://pytorch.org/hub/intelisl_midas_v2/. [Accessed: 27-Mar-2021].
Original license from MiDaS code is below.
MIT License
Copyright (c) 2019 Intel ISL (Intel Intelligent Systems Lab)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
class
pyCarDisplay.detection.depth_detection_api.DepthDetection(verbose: bool, model_path: str, model_type='large', optimize=True, model=None, device='cpu', transform=None, dpi=100, alpha=0.6, pixel_sizes=[1242, 375])[source]¶ Bases:
objectInitialize the depth detection class.
- verbosebool
Print out information regarding API activity.
- model_pathstr
The path to the pretrained model file.
- model_typestr, optional
The type of model to use to detect depth. The default is "large".
- optimizebool, optional
Optimize the depth detection. The default is True.
- modelNone, optional
If passed in, this is the predefined model. The default is None.
- devicestr, optional
Use CUDA device if available. The default is "cpu".
- transformNone, optional
Placeholder for the transform class variable. The default is None.
- dpiint, optional
Dots per inch. The default is 100.
- alphadouble, optional
The alpha variable. The default is 0.6.
- pixel_sizeslist, optional
The sizes of the pixels. The default is [1242, 375].
None.
-
convert_to_heat_map(prediction, original_image)[source]¶ - predictionImage
The depth predicitons of the objects withi the enviroment.
- original_imageImage
The original image.
- np.array()
A numpy array of the color values of each of the pixels in the image.
-
run(verbose: bool, pil_image: <module 'PIL.Image' from '/opt/anaconda3/envs/pyCarDisplay/lib/python3.8/site-packages/Pillow-8.1.2-py3.8-macosx-10.9-x86_64.egg/PIL/Image.py'>, optimize=True)[source]¶ - verbosebool
Print out information regarding API activitty.
- pil_imageImage
The image to be evaluated.
- optimizebool, optional
Optimize the depth detection. The default is True.
- predictionImage
An enhanced image with the colorized depth predictions of the objects within the environment.
pyCarDisplay.detection.object_detection_api module¶
This is the object detection module.
This code is borrowed from sgrvinod's GitHub repository named a-PyTorch-Tutorial-to-Object-Detection, and modified to work with pyCarDisplay. It preserves the original functionality, but is wrapped around a class.
- Reference:
Vinodababu, S. (n.d.). A-PyTorch-Tutorial-to-Object-Detection. https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Object-Detection
Original license from a-PyTorch-Tutorial-to-Object-Detection is below.
MIT License
Copyright (c) 2019 Sagar Vinodababu
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
class
pyCarDisplay.detection.object_detection_api.ObjectDetection(model_path: str, verbose: bool, img_resize_size=(300, 300), norm_mean=[0.485, 0.456, 0.406], norm_std=[0.229, 0.224, 0.225], device='cpu')[source]¶ Bases:
objectInitilize the object detection class.
- model_pathstr
Path to the pre-trained PyTorch model.
- verbosebool
Verbosity flag.
- img_resize_sizetuple, optional
Image size during prediction. The default is (300, 300).
- norm_meanlist, optional
Model hyper-parameter. The default is [0.485, 0.456, 0.406].
- norm_stdlist, optional
Model hyper-parameter. The default is [0.229, 0.224, 0.225].
- devicestr, optional
If 'gpu', model uses a CUDA device. The default is "cpu".
None.
-
detect(original_image: <module 'PIL.Image' from '/opt/anaconda3/envs/pyCarDisplay/lib/python3.8/site-packages/Pillow-8.1.2-py3.8-macosx-10.9-x86_64.egg/PIL/Image.py'>, suppress=None, min_score=0.2, max_overlap=0.5, top_k=200)[source]¶ Predicts the objects in the image using the pre-trained model.
- original_imageImage
PIL image to be used for object detection.
- suppressTYPE, optional
DESCRIPTION. The default is None.
- min_scorefloat, optional
Minimum threshold for object to be classified. The default is 0.2.
- max_overlapfloat, optional
Minimum threshold for object to be classified. The default is 0.5.
- top_kint, optional
How many objects to attempt to classify. The default is 200.
- dict
Returns a dictionary in the following format: {"annotated_image": annotated_image, "box_info": box_info, "detected": True} box_info is in the following format: box_info = {"text_size": text_sizes,"box_location": box_locations}, where the values are a list of coordinates for the detection boxes.