Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have this image: Original image

And I want to find isosceles right triangles like this: Triangle found

How can I do it? Thanks for your help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
166 views
Welcome To Ask or Share your Answers For Others

1 Answer

You could try to blur your image, convert in to gray scale and apply differnet threshold to your image. Next step is to find and arrange your contours and maybe filter them out with limiting sizes.

import cv2
import numpy as np

img = cv2.imread('triangle.png')
blur = cv2.GaussianBlur(img,(5,5),0)
values = [30, 40, 50, 60, 70, 80, 90]
gray_image = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
for i in values:
    ret, threshold = cv2.threshold(gray_image,i,255,cv2.THRESH_BINARY)
    im, contours, hierarchy = cv2.findContours(threshold,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
    area = sorted(contours, key=cv2.contourArea, reverse=True)
    for j in range(1, len(area)):
        contour = area[j]
        size = cv2.contourArea(contour)
        if 10 < float(size) < 140000:
            cv2.drawContours(img, [contour], -1, (0,255,0), 2)
cv2.imshow('img', img)

Result:

enter image description here

Note:

Transformation to different color space and applying different threshold could improve the resut.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...