Bornfree
Bornfree

Reputation: 878

detect triangle in bitmap

Working on an android app, I have a bitmap obtained by applying edge detection on some image. Black background bitmap with white lines as edges.

I need to identify the first closed boundary moving outward from the centre and check if it is a triangle.

How do I do that? Even a methodology if not code sample would be of much help.

Upvotes: 0

Views: 779

Answers (1)

pawelzieba
pawelzieba

Reputation: 16082

This is modified Hough transform, a little optimized for this problem.
Assuming that you applied edge detection and edge is white pixel.

  1. Find boundary. Move from center to outside and find first white pixel. Repeat for as many direction as you want.
  2. Find lines. Route line through pixels that are neighbours (take two pixels or find equation to route line through more than two pixels) and check how many white pixels are under the line. The more pixel under line, the better line it is. Take into account intersection with another lines and count white pixels till the intersection.
  3. Identify triangle. If boundary is builded from 3 good lines then it is a triangle.

It's only idea, I'll hope that help.

Upvotes: 2

Related Questions