[英]Determine coordinates of rotated rectangle
I'm creating an utility application that should detect and report the coordinates of the corners of a transparent rectangle (alpha=0) within an image. 我正在创建一个实用程序应用程序,它应该检测并报告图像中透明矩形(alpha = 0)的角的坐标。
So far, I've set up a system with Javascript + Canvas that displays the image and starts a floodfill-like operation when I click inside the transparent rectangle in the image. 到目前为止,我已经建立了一个使用Javascript + Canvas的系统,当我在图像中的透明矩形内部单击时,该系统显示图像并启动类似泛滥填充的操作。 It correctly determines the bounding box of the floodfill operation and as such can provide me the correct coordinates.
它正确地确定了填充操作的边界框,因此可以为我提供正确的坐标。
Here's my implementation so-far: http://www.scriptorama.nl/image/ (works in recent Firefox / Safari ). 这是我迄今为止的实现: http : //www.scriptorama.nl/image/ (适用于最近的Firefox / Safari)。
However, the bounding box approach breaks down then the transparent rectangle is rotated (CW or CCW) as the resulting bounding box no longer properly represents the proper width and height. 但是,边界框方法会中断,然后旋转透明矩形(CW或CCW),因为生成的边界框不再正确表示正确的宽度和高度。 I've tried to come up with a few alternatives to detect to corners, but have not been able to think up a proper solution.
我试图想出几个替代方案来探测角落,但是还没有能够想出一个合适的解决方案。
So, does anyone have any suggestions on how I might approach this so I can properly detect the coordinates of 4 corners of the rotated rectangle? 那么,有没有人对我如何处理这个有任何建议,所以我可以正确检测旋转矩形的4个角的坐标?
I think you can do this with a simple extension to your existing solution: walk along each of the 4 edges of the bounding box, looking for transparent pixels: 我认为你可以通过对现有解决方案的简单扩展来做到这一点:沿着边界框的4个边缘走,寻找透明像素:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.