OpenCV
4.1.0
Open Source Computer Vision
|
Build samples of "dnn_objectect" module. Refer to OpenCV build tutorials for details. Enable BUILD_EXAMPLES=ON
CMake option and build these targets (Linux):
Download the weights file and model definition file from opencv_extra/dnn_objdetect
```bash example_dnn_objdetect_obj_detect <model-definition-file> <model-weights-file> <test-image> ```
All the following examples were run on a laptop with Intel(R) Core(TM)2 i3-4005U CPU @ 1.70GHz
(without GPU).
The model is incredibly fast taking just 0.172091
seconds on an average to predict multiple bounding boxes.
```bash <bin_path>/example_dnn_objdetect_obj_detect SqueezeDet_deploy.prototxt SqueezeDet.caffemodel tutorials/images/aeroplane.jpg
Class: aeroplane Probability: 0.845181
```
```bash <bin_path>/example_dnn_objdetect_obj_detect SqueezeDet_deploy.prototxt SqueezeDet.caffemodel tutorials/images/bus.jpg
Class: bus Probability: 0.701829
```
```bash <bin_path>/example_dnn_objdetect_obj_detect SqueezeDet_deploy.prototxt SqueezeDet.caffemodel tutorials/images/cat.jpg
Class: cat Probability: 0.703465
```
```bash <bin_path>/example_dnn_objdetect_obj_detect SqueezeDet_deploy.prototxt SqueezeDet.caffemodel tutorials/images/persons_mutli.jpg
Class: person Probability: 0.737349
Class: person Probability: 0.720328
```
Go ahead and run the model with other images !
By default this model thresholds the detections at confidence of 0.53
. While filtering there are number of bounding boxes which are predicted, you can manually control what gets thresholded by passing the value of optional arguement threshold
like:
```bash <bin_path>/example_dnn_objdetect_obj_detect <model-definition-file> <model-weights-file> <test-image> <threshold> ```
Changing the threshold to say 0.0
, produces the following:
That doesn't seem to be that helpful !
```bash example_dnn_objdetect_image_classification <model-definition-file> <model-weights-file> <test-image> ```
The size of the model being 4.9MB, just takes a time of 0.136401 seconds to classify the image.
Running the model on examples produces the following results:
```bash <bin_path>/example_dnn_objdetect_image_classification SqueezeNet_deploy.prototxt SqueezeNet.caffemodel tutorials/images/aeroplane.jpg Best class Index: 404 Time taken: 0.137722 Probability: 77.1757 ```
Looking at synset_words.txt, the predicted class belongs to airliner
```bash <bin_path>/example_dnn_objdetect_image_classification SqueezeNet_deploy.prototxt SqueezeNet.caffemodel tutorials/images/cat.jpg Best class Index: 285 Time taken: 0.136401 Probability: 40.7111 ```
This belongs to the class: Egyptian cat
```bash <bin_path>/example_dnn_objdetect_image_classification SqueezeNet_deploy.prototxt SqueezeNet.caffemodel tutorials/images/space_shuttle.jpg Best class Index: 812 Time taken: 0.137792 Probability: 15.8467 ```
This belongs to the class: space shuttle