如何用delphi查找图片的方向 [英] how to find orientation of a picture with delphi

查看:147
本文介绍了如何用delphi查找图片的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到玉米图片的方向(如下例所示),它们与左右方向的角度不同。我需要将它们倒转(与它们的法线成90度角)(当它们看起来像水滴时)
有什么办法可以轻松实现吗?





解决方案

在OP中,我给你的印象是菜鸟,所以我坚持简单的做法:


  1. 计算图像的边界框



    足够简单地遍历所有像素并记住非背景像素的 x,y 的最小值,最大值


  2. 计算关键尺寸





    只需通过边界框投射几行即可计算出红点位置。所以选择起点,我选择高度的 25%,50%,75%。首先从左开始,然后在第一个非背景像素上停止。然后从右开始,在第一个非背景像素处停止。


  3. 轴对齐位置



    开始旋转图像,并记住/停止红点对称的位置,使它们与左侧和右侧的距离几乎相等。此外,边界框在轴对齐的位置上具有最大的高度和最小的宽度,因此您还可以利用...


  4. 确定位置



    如果我将距离称为 l0,l1,l2,r0,r1,r2 ,您有4个选择




    • l 表示从左开始的 r 表示从右起

    • 0 是上(蓝色)行, 1 中间, 2 底部



    然后您想要的位置是(l0 == r0)> =(l1 == r1)> =(l2 == r2)并且在 y 轴,然后沿 x 轴旋转 90 度,直到找到匹配或确定方向直接从距离开始旋转一次...


[Notes]



您将需要访问图像像素,因此我强烈建议使用 VCL Graphics :: TBitmap >。在此处 C语言中的gfx ,特别是 GDI位图部分,以及此在高空照片上寻找地平线可能会有所帮助。



我使用 C ++ VCL ,因此您必须转换为 Pascal ,但是 VCL 的内容是相同的...


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?

解决方案

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

这篇关于如何用delphi查找图片的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆