Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The best way is to separate the image into just the star portion. That is, an image that is white where the star is, and black everywhere else. If you can do that, then finding the center is extremely simple. The function moments() will help you find the x and y location.

You only need the first and zeroth order moments. To get the x location, I believe it's m10/m00, and y is m01/m00. It could be the other way around, I always have to check myself.

So for your sample images, the second one is actually easier than the first. You convert to a gray image, threshold with OTSU and use the morphological OPEN to remove small specks. Then you use moments and it's done.

The first image is harder, you need to use some intelligence to get the star separate from the banner and stand. You might be able to do it with the Hough transform to find all the straight lines and find the ones that make a star. That would probably miss the corners where the banner is though. Using findCountours is another way you could separate the star from the base.