# Algorithm for finding bounding boxes when using Dnn.readNetFromModelOptimizer

**URL:** <https://forum.opencv.org/t/algorithm-for-finding-bounding-boxes-when-using-dnn-readnetfrommodeloptimizer/1169>\
**Category:** Uncategorized\
**Tags:** dnn\
**Created:** [January 28, 2021, 7:40am UTC](https://forum.opencv.org/t/algorithm-for-finding-bounding-boxes-when-using-dnn-readnetfrommodeloptimizer/1169 "2021-01-28T07:40:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wureka](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/wureka/32/767_2.png) [@wureka](https://forum.opencv.org/u/wureka)\
**Post date:** [January 28, 2021, 7:40am UTC](https://forum.opencv.org/t/algorithm-for-finding-bounding-boxes-when-using-dnn-readnetfrommodeloptimizer/1169/1 "2021-01-28T07:40:49Z")

</div>

my code is as below:

```
import numpy as np
import argparse
import imutils
import time
import cv2

print(cv2. __version__ )

rootPath = "E:\var\intel\vehicle-detection-0200\FP16\"
modelName = "vehicle-detection-0200" # download from intel open model zoo
irXmlFile = rootPath + modelName+".xml"
irBinFile = rootPath + modelName+".bin"
imagefile = "./vid03_023860.jpg"
COLORS = np.random.uniform(0, 255, size=(80, 3))

net = cv2.dnn.readNetFromModelOptimizer(irXmlFile, irBinFile)
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)

frame = cv2.imread(imagefile)

out_blob = cv2.dnn.blobFromImage(frame, size=(672, 384))
net.setInput(out_blob)
res = net.forward()
classid_str = "classid"
probability_str = "probability"
label_str = "label"
number_top = 5 
print("before, out size:", res.shape)
out = res.reshape(-1, 7)
print("after, out size:", out.shape)
count =-1
print("shape H-0:", frame.shape[0])
print("shape W-1:", frame.shape[1])
for detection in out:
    count += 1
    confidence = float(detection[2])
    if confidence < 0.6:
        break

    xmin = int(detection[3] * frame.shape[1])
    ymin = int(detection[4] * frame.shape[0])
    xmax = int(detection[5] * frame.shape[1])
    ymax = int(detection[6] * frame.shape[0])
    print(count, ".confidence=", confidence, "[lx,ty,rxby]=", xmin, ymin, xmax, ymax)
    if confidence > 0.5:
        #cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))
        cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color=COLORS[count])

cv2.imshow('OpenVINO face detection', frame)
key = cv2.waitKey(0)

```

If I change the model (IR files) to below model (obtaining from openvino)

```
 squeezenet1.1.bin
 squeezenet1.1.xml

```

Then the code can not find any bounding boxes, even the above two different model can be read with

```
 cv2.dnn.readNetFromModelOptimizer(irXmlFile, irBinFile)

```

I wonder the algorithm for finding bounding boxes differs from the type of nural network, right ?

If I am correct, where can I find the algorithm for finding bounding boxes of every neural network ?

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [January 28, 2021, 2:48pm UTC](https://forum.opencv.org/t/algorithm-for-finding-bounding-boxes-when-using-dnn-readnetfrommodeloptimizer/1169/2 "2021-01-28T14:48:22Z")

</div>

I think you have to read paper.  
Which model is it?

---

<div class="post-metadata">

**Author:** ![Supra](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/supra/32/91_2.png) [@Supra](https://forum.opencv.org/u/Supra)\
**Post date:** [January 31, 2021, 6:32pm UTC](https://forum.opencv.org/t/algorithm-for-finding-bounding-boxes-when-using-dnn-readnetfrommodeloptimizer/1169/3 "2021-01-31T18:32:01Z")

</div>

> [@wureka](#):
>
> ```auto
> if confidence < 0.6:
> break
> 
> ```

What happen if you comment out this?

```auto
#if confidence < 0.6:
        #break
```
