# How do I find the contours of a letter

**URL:** https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125
**Category:** Python
**Tags:** findcontours, ximgproc
**Created:** [November 27, 2022, 9:38pm UTC](https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125 "2022-11-27T21:38:50Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![stonechen](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@stonechen](https://forum.opencv.org/u/stonechen)
#### Post date: [November 27, 2022, 9:38pm UTC](https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125/1 "2022-11-27T21:38:50Z")

</div>

I used the findcontours method but it does not work as expected. What I want is the sketched version of the letter “v” from the original image.

This is the original image of letter “v”

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

After using findcontours, codes attached below, it gave me an image that is not exactly what I want. I am a new user so can only upload one image. Pls see replies below.

```auto
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
ret, binary = cv.threshold(gray, 0, 255, cv.THRESH_BINARY_INV | cv.THRESH_OTSU)
thinned = cv.ximgproc.thinning(binary)
contours, hireachy = cv.findContours(thinned, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
contours = extractContours(contours)

def extractContours(contours):
    contours = contours[0].tolist()
    x = []
    y = []
    newContours = []
    for i in contours:
        newContours.append(i[0])
    for i in newContours:
        x.append(i[0])
        y.append(i[1])
    return np.asfortranarray([x, y])

```

---

<div class="post-metadata">

### Author: ![stonechen](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@stonechen](https://forum.opencv.org/u/stonechen)
#### Post date: [November 27, 2022, 9:41pm UTC](https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125/2 "2022-11-27T21:41:15Z")

</div>

The above codes output this image below in the variable “contours”  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/1/19fbea5d1d1c1bdef03d2aaf2043c755337df7e5.png)

Apparently, this looks like a “Y” more. This is the first issue.  
The second issue is that, this output image, or “contours” variable in the codes above, actually stores points in a “round trip” way. By that I mean “contours” has points in the way like " (1,1) (3,3) (5,5) (7,7) (9,9) (8,8) (6,6) (4,4) (2,2) (0,0).

---

<div class="post-metadata">

### Author: ![stonechen](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@stonechen](https://forum.opencv.org/u/stonechen)
#### Post date: [November 27, 2022, 9:42pm UTC](https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125/3 "2022-11-27T21:42:34Z")

</div>

To give another illustration of “round trip”, below I extract each segment from “contours”, and I got these images below. As you can see, contours store points of “v” twice. But there are no duplicated points. (The reason why the blue segments are a little bit off is because I use Bézier curve so it looks a bit off.)  
So I need some help to get what I want, that is a sketched version of a letter, for which the points can be stored in a “one way” trip in stead of a “round way” trip. . I am new user to opencv. Thanks for help!  
 ![img058-047-001](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/b/bd3cfa322c9775b4622b9c6d38d34921aa7e21fc.png)

---

<div class="post-metadata">

### Author: ![stonechen](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@stonechen](https://forum.opencv.org/u/stonechen)
#### Post date: [November 27, 2022, 9:43pm UTC](https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125/4 "2022-11-27T21:43:04Z")

</div>

![img058-047-002](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/0/0e6688a7713cf30b2d214374cafbf562a7407ba2.png)

---

<div class="post-metadata">

### Author: ![stonechen](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@stonechen](https://forum.opencv.org/u/stonechen)
#### Post date: [November 27, 2022, 9:43pm UTC](https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125/5 "2022-11-27T21:43:36Z")

</div>

![img058-047-003](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/6/63ef19ba82735e69cb072917f0a206bb051f7f08.png)

---

<div class="post-metadata">

### Author: ![stonechen](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@stonechen](https://forum.opencv.org/u/stonechen)
#### Post date: [November 27, 2022, 9:44pm UTC](https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125/6 "2022-11-27T21:44:07Z")

</div>

![img058-047-004](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/3/37255900d974915cd462ab373ff4b31c718d8f15.png)

---

<div class="post-metadata">

### Author: ![stonechen](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@stonechen](https://forum.opencv.org/u/stonechen)
#### Post date: [November 27, 2022, 9:44pm UTC](https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125/7 "2022-11-27T21:44:37Z")

</div>

![img058-047-005](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/d/d7ad7a3d914a23649cc42c732123ffd1e2dbd6ca.png)

---

<div class="post-metadata">

### Author: ![stonechen](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@stonechen](https://forum.opencv.org/u/stonechen)
#### Post date: [November 27, 2022, 9:45pm UTC](https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125/8 "2022-11-27T21:45:07Z")

</div>

![img058-047-006](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/2/286c7ea4da0fc15888db4c18e931edb7770cb25f.png)

---

<div class="post-metadata">

### Author: ![stonechen](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@stonechen](https://forum.opencv.org/u/stonechen)
#### Post date: [November 27, 2022, 9:45pm UTC](https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125/9 "2022-11-27T21:45:37Z")

</div>

![img058-047-007](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/2/265c9cba2915d7971b354ad1ea5f27a9d9b0c1da.png)

---

<div class="post-metadata">

### Author: ![stonechen](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@stonechen](https://forum.opencv.org/u/stonechen)
#### Post date: [November 27, 2022, 9:46pm UTC](https://forum.opencv.org/t/how-do-i-find-the-contours-of-a-letter/11125/10 "2022-11-27T21:46:07Z")

</div>

![img058-047-008](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/3/37c35663f349ef5451319b5733bbc0594525599a.png)
