Ask Your Question
0

How to detect red object shape?(square shaped object red in color)

asked 2018-03-23 02:35:56 -0600

Santhosh1 gravatar image

updated 2018-03-23 06:38:20 -0600

I want to detect the the object here below that is similar to a square but with rounded edges?

image description

I can use morphological transform Gradient to find the contour with the largest area but some times even the other objects in the picture might be as BIG as the square object with rounded edges

Does anyone else have any other solution?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2018-03-23 05:39:56 -0600

Santhosh1 gravatar image

I played around with a few more colorspaces in OpenCV

LAB and YUV gave a nice shape of the square object(the square object was actually red in color)

Here's the result, both the LAB and YUV results were same.

image description

Performed pixel wise operation using numpy.where in axis=2 and remove all the color pixels outside the interested square shaped object to [0,0,0] or black

This is the final result.

image description

Hope it helps someone

edit flag offensive delete link more

Comments

2

O_O ow wait :D so you start with a question on shapes, then move yourself to color segmentation. We could have told you that from the start if we had the original image ^_^ nevertheless, good you solved it!

StevenPuttemans gravatar imageStevenPuttemans ( 2018-03-23 06:01:53 -0600 )edit
1

Something like poker with 5 aces

LBerger gravatar imageLBerger ( 2018-03-23 06:45:17 -0600 )edit
1

I hadn't tried all the colourspaces before I posted this question ๐Ÿ˜…

Santhosh1 gravatar imageSanthosh1 ( 2018-03-23 08:05:35 -0600 )edit
1

answered 2018-03-23 05:35:03 -0600

I would go for shape analysis in the following way

  • For each contour calculate HuMoments
  • Then learn a very simple classifier (NaiveBayes, linear SVM, ...) that seperates rectangles from other shapes
edit flag offensive delete link more
0

answered 2018-03-23 03:35:49 -0600

VxW gravatar image

Hi, you can try to calculate the thinnes ratio: T = 4*Pi ( Area/Perimeter^2)

this measure has a maximum of 1, which corresponds to a circle, otherwise is more an rectangle. You can also find some other contour properties in OpenCV docu

edit flag offensive delete link more

Comments

Thank You @VxW for the response was a new thing I learnt ๐Ÿ‘

Santhosh1 gravatar imageSanthosh1 ( 2018-03-23 08:27:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-23 02:35:56 -0600

Seen: 979 times

Last updated: Mar 23 '18