且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在WPF,vb.net中测量两个对象(图像)之间的距离?

更新时间:2023-02-01 22:19:54

获取鞋面左控件的一点你可以使用 Control.Location [ ^ ]属性。



现在,当你从控件中得到这两点时,你只需要搞清楚每个的中心或边缘(取决于你的计算应该做什么)然后做SQRT(X 2 + Y 2 )并乘以像素到米您有比率。





*如果您打算根据纬度和经度计算两个地理位置之间的距离,请检查关于如何校准的以下Q& A拉特和长期之间的距离 [ ^ ]



干杯,

Edo
To get the upper left point of a control you can use the Control.Location[^] property.

Now, when you get those two points out of your controls, you just need to figure out the center or edge of each one (depending on what your calculation is supposed to do) and then do SQRT(X2 + Y2) and multiply by the pixel to meter ratio you have.


* If you meant to calculate distance between two geo positions based on Latitude and Longitude, check the following Q&A on How to calculate Distance Between Lat And Long[^]

Cheers,
Edo


不是真的,不是 - 不适用于普通图像。



请记住,图像是三维场景的二维表示,所以两个通过第三维度,相隔像素的项目在现实世界中可以相距几英里。为了解决您的问题,即使图像是2D场景(桌子上的一堆物体,例如从上方直接看到),除非图像是包含比例信息(距离桌子和一些参考点),不知道像素和仪表之间的关系。如果您知道其中一个对象(一个参考对象)的大小,那么如果您可以自动识别它,那么您可以这样做,但这是一堆工作都在它自己。



对于随机挑选的通用图像?没机会。
Not really, no - not for "normal" images.

Remember, an image is a two dimensional representation of a three dimensional scene, so two "items" a pixel apart could be several miles apart in the real world via the third dimension. To add to your problems, even if the image is of a 2D scene (a bunch of objects on a table, seen from directly above for example) unless the image is taken with scale information included (distance to table and some reference points) you have no idea of the relationship between a pixel and a metre. If you know the size of one of the objects (a reference object) then if you can automatically identify this, you can do it, but that's a pile of work all on it's own.

For a "generic" image picked at random? No chance.