# Height of contour at different positions

**URL:** <https://forum.opencv.org/t/height-of-contour-at-different-positions/10882>\
**Category:** Python\
**Tags:** imgproc\
**Created:** [November 9, 2022, 8:00am UTC](https://forum.opencv.org/t/height-of-contour-at-different-positions/10882 "2022-11-09T08:00:12Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![digerid](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/digerid/32/5690_2.png) [@digerid](https://forum.opencv.org/u/digerid)\
**Post date:** [November 11, 2022, 1:57pm UTC](https://forum.opencv.org/t/height-of-contour-at-different-positions/10882/10 "2022-11-11T13:57:32Z")

</div>

Sorry, i dont get it…  
I dont know what to use for labels and `label`. I tried every return of `CCwithstats` but i cant get results. With my try, i get results but work with OpenCv mask i think…  
I mean the results i get make sense. They get bigger at beginning and smaller at end, as the height of the picture i sent. Ill post my code and return of one object, maybe you can help me to understand. Many lines are from internet, i just found out about CCwithstats when u told me. I understand what it does, but dont understand every single parameter. I think this is my problem.  
Code:

```auto
# image
img4k = cv.imread(path_object)
img = cv.resize(img4k, dsize=(1920, 1080)) # img = img4k
imggray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
ret, thresh = cv.threshold(imggray, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)
# CC
analysis = cv.connectedComponentsWithStats(thresh, 4, cv.CV_32S)
(totalLabels, label_ids, values, centroid) = analysis
# Initialize a new image to store all the output components
output = np.zeros(imggray.shape, dtype="uint8")

# Loop through each component
for i in range(1, totalLabels):
    # Area of the component
    area = values[i, cv.CC_STAT_AREA]

    if (area > 25000):
        print('area: ', area)
        componentMask = (label_ids == i).astype("uint8") * 255

        output = cv.bitwise_or(output, componentMask)
        # extract coordinate points
        x = values[i, cv.CC_STAT_LEFT]
        y = values[i, cv.CC_STAT_TOP]
        w = values[i, cv.CC_STAT_WIDTH]
        h = values[i, cv.CC_STAT_HEIGHT]
        # bounding box
        pt1 = (x, y)
        pt2 = (x+ w, y+ h)
        (X, Y) = centroid[i]
        cv.rectangle(img,pt1,pt2, (255, 0, 255), 1)
        cv.putText(img, "w={},h={}".format(w, h), (int(x),int(y)-int(h/1.6)), cv.FONT_HERSHEY_SIMPLEX, 1, (0,0,255), 1)

        mask = output.copy()[y:y+h, x:x+w]
        column_sums = mask.sum(axis=0)
        print('column_sums:', column_sums)
        cv.imshow("mask", mask)
        cv.waitKey(0)

cv.imshow("Image", img)
cv.imshow("Filtered Components", output)
cv.waitKey(0)

```

result:

 ![grafik](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/8/81ae34efcd29b35925dbd305fdd19e52d9f292ed.png)  
2nd component look very similar but even more elements

---

_[View the full topic](https://forum.opencv.org/t/height-of-contour-at-different-positions/10882)._
