# Detect boundary for an object

**URL:** <https://forum.opencv.org/t/detect-boundary-for-an-object/7736>\
**Category:** Python\
**Created:** [February 27, 2022, 2:15pm UTC](https://forum.opencv.org/t/detect-boundary-for-an-object/7736 "2022-02-27T14:15:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Faizan-Mazher](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@Faizan-Mazher](https://forum.opencv.org/u/Faizan-Mazher)\
**Post date:** [February 27, 2022, 2:15pm UTC](https://forum.opencv.org/t/detect-boundary-for-an-object/7736/1 "2022-02-27T14:15:50Z")

</div>

Hi, I am writing a script which will measure a length of antler from an image. So far, I have written an script which detect antler edges but with gaps in it. By gaps, I mean there are missing pieces in boundry of antler.

I have written a script which resizes the image, applies Gaussian filter, eroson, canny filter, and dilation.

This is the result image,

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/0/06494478a5481138250b7af14684a351811e46cc.png)

Script and original image is attached in this post. What I want to do is to detect edg of antler and draw its boundry line so I can calculate its length.

Original script

```auto
import cv2 as cv
import matplotlib.pyplot as plt
import numpy as np
import imutils

img = cv.imread("images/BFA Elk/IMG_0176.jpeg")
img = imutils.resize(img, width=400)

cv.imshow("Original image", img)

copy_img = np.copy(img)
copy_img = cv.cvtColor(copy_img, cv.COLOR_BGR2RGB)

gray = cv.cvtColor(copy_img, cv.COLOR_RGB2GRAY)

gray_blur = cv.GaussianBlur(gray,(11,11),0)

cv.imshow('Gaussian Blur', gray_blur)
# cv.waitKey()

kernel = np.ones((5,5), np.uint8)
img_erosion = cv.erode(gray_blur, kernel, iterations=1)
cv.imshow('After erode', img_erosion)

lower = 60
upper = 120
adges = cv.Canny(img_erosion, lower,upper)

cv.imshow('Canny edge', adges)

# plt.imshow(adges, cmap='gray')

kernel2 = np.ones((5,5), np.uint8)
img_dilation = cv.dilate(adges, kernel2, iterations=1)

cv.imshow('Dilated image', img_dilation)

kernel = np.ones((5,5), np.uint8)
img_erosion = cv.erode(gray_blur, kernel, iterations=1)
cv.imshow('After erode', img_erosion)
cv.waitKey()

```

---

<div class="post-metadata">

**Author:** ![Faizan-Mazher](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@Faizan-Mazher](https://forum.opencv.org/u/Faizan-Mazher)\
**Post date:** [February 27, 2022, 2:16pm UTC](https://forum.opencv.org/t/detect-boundary-for-an-object/7736/2 "2022-02-27T14:16:25Z")

</div>

Original image

 ![IMG_0176](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/2/2f3ca5f06028a81f894685066048df44d7e939e8.jpeg)

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [February 27, 2022, 2:30pm UTC](https://forum.opencv.org/t/detect-boundary-for-an-object/7736/3 "2022-02-27T14:30:16Z")

</div>

maybe you can use another, darker background ?
