how to find orientation of a picture with delphi

左心房为你撑大大i 提交于 2019-12-13 01:49:24

问题


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?


回答1:


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




回答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

    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...



来源:https://stackoverflow.com/questions/28403979/how-to-find-orientation-of-a-picture-with-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!