Pregunta

I'm new to images processing. Now I have a problem. I'm writing a simple program on C#, that have to define some objects on images through some samples.

For example here's the sample:

sample

Later I have to compare with it objects that I find on a loadable image. Sizes of objects and samples are always equal. Images are binarized. We always know rotation point (it's the image's center). Samples are always normalized, but we never know object's rotation angle relative to the normal.

Here are some objects that I find on the loadable image:

sample1 sample2

The question is how to find angle #1. Sorry for my English and thanks.

¿Fue útil?

Solución

if you are using aforge libraries, you can utilize his extension too, named Accord.Net.

Accord.Net is similar at Aforge, you install it, add the references at your project and you are done.

After that you can use the simply the RawMoments by passing the target image, and after you can use them to compute CentralMoments

At this point you can get the angle of your image with the method of CentralMoments GetOrientation() and you get the angle.

I used it on an hand-gestures recognition project and worked like a charm.

UPDATE: I have just checked that GetOrientation get only the angle but not the direction. So an upside-down image have the same angle of the original. A fix, can be the pixel counting, but this time you will get only 2 (worst case) samples to check and not 360 (worst case) samples.

Update2

If you have a lot of samples, i suggest you to filter them with the size of the rotated image. Example: I get the image, i see that is in a Horizontal position (90°) i rotate it of 90° and now i have the original width and heigth that i can utilize to skip the samples that are not similar, like:

If (Founded.Width != Sample.Width)    //You can add a range too if in case during
 Continue;                            //the rotation are added some pixels

Otros consejos

To recap, you have a sample image and a rotated image of the same source image. You also have two values 0,1 for the pixels.

A simple pseudo-code that can yield moderate success can be implemented using a binary search :

  1. Start with a value for the rotation to be 180 degress - both clockwise and counter-clockwise
  2. Rotate the image to both values.
  3. XOR the original image from the rotated one.
  4. Count the number of 0 pixels and check if it's less than the margin of error you define.
  5. Continue the search with half of the rotation angle.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top