# Mybe bug in OpenCV algorithm for method cv2.erode()

**URL:** https://forum.opencv.org/t/mybe-bug-in-opencv-algorithm-for-method-cv2-erode/20921
**Category:** Python
**Created:** [April 29, 2025, 9:10pm UTC](https://forum.opencv.org/t/mybe-bug-in-opencv-algorithm-for-method-cv2-erode/20921 "2025-04-29T21:10:10Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jamilalidrus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/jamilalidrus/32/3861_2.png) [@jamilalidrus](https://forum.opencv.org/u/jamilalidrus)
#### Post date: [April 29, 2025, 9:10pm UTC](https://forum.opencv.org/t/mybe-bug-in-opencv-algorithm-for-method-cv2-erode/20921/1 "2025-04-29T21:10:10Z")

</div>

Hello Guys i found something anomaly in openCV for method cv2.erode()

i have matrix 4x4 like this

```
[1,0,0,0],
[1,1,1,0],
[1,1,1,0],
[0,1,1,0],

```

with Kernel =  
[0,1,0],  
[1,1,1],  
[0,1,0],

when i am try to calculate using manual method in erotion theory i found result equal  
[[0 0 0 0]  
[0 0 0 0]  
[0 1 0 0]  
[0 0 0 0]]

but when i am using OpenCV cv2.erode with padding 0 using borderType = cv2.BORDER\_CONSTANT and iteration = 1  
the result of openCV equal =  
[[0 0 0 0]  
[1 0 0 0]  
[0 1 0 0]  
[0 0 0 0]]  
its make my value pixel = 1 in (1,0) position but when i am using manual calculation base on algorithm concept its should be = 0 in (1,0) position

can someOne Explain to me why?

---

<div class="post-metadata">

### Author: ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)
#### Post date: [April 29, 2025, 11:23pm UTC](https://forum.opencv.org/t/mybe-bug-in-opencv-algorithm-for-method-cv2-erode/20921/2 "2025-04-29T23:23:13Z")

</div>

[MRE](https://stackoverflow.com/help/minimal-reproducible-example) required.

when asking for BORDER\_CONSTANT, you also have to pass a `borderValue`. the default does not appear to be sensible in this case.
