# Some blob pixels outside the min area rectangle

**URL:** https://forums.openmv.io/t/some-blob-pixels-outside-the-min-area-rectangle/2197
**Category:** OpenMV Boards
**Created:** [February 18, 2021, 4:22pm UTC](https://forums.openmv.io/t/some-blob-pixels-outside-the-min-area-rectangle/2197 "2021-02-18T16:22:52Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ronOM](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@ronOM](https://forums.openmv.io/u/ronOM)
#### Post date: [February 18, 2021, 4:22pm UTC](https://forums.openmv.io/t/some-blob-pixels-outside-the-min-area-rectangle/2197/1 "2021-02-18T16:22:52Z")

</div>

Hello,  
Don’t know if it is running as it should. I have blob pixels out of the min area rectangle. For me all pixels should be enclosed in the rectangle. And I’m don’t really understand the meaning of

> Unlike blob.corners() the min area rectangle corners do not necessarily lie on the blob.

in the blob.min\_corners() function description.  
Image with a rectangle defined by min\_corners():  
 ![MinAreaRectangle.png](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/3/3d57cfb0ce2221e71d11e1f3c992689d2ea51ad2.png)  
Code:

```python
import image, time

imgs = image.Image("/stream-c1.pgm",copy_to_fb=True)

imgs.binary([(30,255)])
imgs.open(4)
blob = imgs.find_blobs([(128,255)], merge=True)[0]

imgs.flush()
time.sleep_ms(1000)
imgs.draw_edges(blob.min_corners(), color=(128,128,128))
imgs.flush()
time.sleep_ms(1000)

```

Test image in joined stream-c1.zip

I don’t have that behavior with OpenCV with the following code:

```python
import numpy as np
import cv2

img = cv2.imread('stream-c1.pgm',0)

ret, img_thresh = cv2.threshold(img,30,255,cv2.THRESH_BINARY)

kernelsize = 9
kernel = np.ones((kernelsize,kernelsize),np.uint8)
img_open = cv2.morphologyEx(img_thresh, cv2.MORPH_OPEN, kernel)

cnts,hierarchy = cv2.findContours(img_open, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnt = cnts[0]
rect = cv2.minAreaRect(cnt)
print(rect)
box = np.int0(cv2.boxPoints(rect))

img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
img_open = cv2.cvtColor(img_open, cv2.COLOR_GRAY2BGR)
img = cv2.drawContours(img, [box], 0, (128,255,128), 1)
img_open = cv2.drawContours(img_open, [box], 0, (128,255,128), 1)
img = cv2.drawContours(img, cnts, -1, (255,128,128), 1)

cv2.imshow('img',img)
cv2.imshow('img_bin',img_open)
cv2.waitKey(0)
cv2.destroyAllWindows()

```

[stream-c1.zip](https://forums.openmv.io/uploads/short-url/kUldaSkElOpfPh0Gk5bY99GsRID.zip) (13.3 KB)

---

<div class="post-metadata">

### Author: ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)
#### Post date: [February 18, 2021, 6:39pm UTC](https://forums.openmv.io/t/some-blob-pixels-outside-the-min-area-rectangle/2197/2 "2021-02-18T18:39:10Z")

</div>

Hi, the way out minRect code works is not as complete as OpenCV’s one. We just collect a list of 20 points on the blob as we are tracking it. So, the minRect doesn’t reflect all the points. In particular, out method doesn’t work well on shapes that don’t have great features.

We may upgrade our support to be as good as OpenCV’s in the future. This requires storing the complete edge contour however.
