1

I need to find orientation of corn pictures (as examples below) they have different angles to right or left. I need to turn them upside (90 degree angle with their normal) (when they look like a water drop) Is there any way I can do it easily?

enter image description here

enter image description here

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
fatihbarut
  • 19
  • 5
  • That's quite a tricky task. You need to search for a library, or write code yourself. The latter requires a lot of expertise. – David Heffernan Feb 09 '15 at 07:17
  • Good question. Wrong forum. – Stijn Sanders Feb 09 '15 at 07:45
  • As @DavidHeffernan sad this is far from trivial task. There are computer scientists that are spending yeas researching various algorithms for this. Now if all of the pictures have single colored backround you might get away with basic shape recognition algorithm but I don't know of any Pascal implementation for it. In short if the number of pictures you want to edit isn't enormus and implementing of a such feature into your software isn't a muss it might be faster for you to just edit the orientation of thos pictures by yourself. – SilverWarior Feb 09 '15 at 07:49

2 Answers2

2

From the OP I got the impression you a rookie in this so I stick to something simple:

  1. compute bounding box of image

    simple enough go through all pixels and remember min,max of x,y coordinates of non background pixels

  2. compute critical dimensions

    enter image description here

    Just cast few lines through the bounding box computing the red points positions. So select the start points I choose 25%,50%,75% of height. First start from left and stop on first non background pixel. Then start from right and stop on first non background pixel.

  3. axis aligned position

    start rotating the image with some step remember/stop on position where the red dots are symmetric so they are almost the same distance from left and from right. Also the bounding box has maximal height and minimal width in axis aligned position so you can also exploit that instead ...

  4. determine the position

    You got 4 options if I call the distance l0,l1,l2,r0,r1,r2

    • l means from left, r means from right
    • 0 is upper (bluish) line, 1 middle, 2 bottom

    then you wanted position is if (l0==r0)>=(l1==r1)>=(l2==r2) and bounding box is bigger in y axis then in x axis so rotate by 90 degrees until match is found or determine the orientation directly from distances and rotate just once ...

[Notes]

You will need accessing pixels of image so I strongly recommend to use Graphics::TBitmap from VCL. Look here gfx in C specially the section GDI Bitmap and also at this finding horizon on high altitude photo might help a bit.

I use C++ and VCL so you have to translate to Pascal but the VCL stuff is the same...

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Thanks a lot but the problem is not the all corns are symmetric :( – fatihbarut Feb 09 '15 at 18:42
  • then use the bounding box condition while rotating that should work also for asymetric shapes,... then just choose position that is thinner on upper side . – Spektre Feb 09 '15 at 20:02
2

As starting point - find image moments (and Hu moments for complex forms like pear). From the link:

Information about image orientation can be derived by first using the 
second order central moments to construct a covariance matrix.

I suspect that usage of some image processing library like OpenCV could give more reliable results in common case

MBo
  • 77,366
  • 5
  • 53
  • 86