我需要用Pascal/Delphi/Lazarus编写的逆透视变换.见下图:

我想我需要遍历目标像素,然后计算源图像中的相应位置(以避免舍入错误等问题).
function redraw_3d_to_2d(sourcebitmap:tbitmap, sourceaspect:extended, point_a, point_b, point_c, point_d:tpoint, megapixelcount:integer):tbitmap;
var
destinationbitmap:tbitmap;
x,y,sx,sy:integer;
begin
destinationbitmap:=tbitmap.create;
destinationbitmap.width=megapixelcount*sourceaspect*???; // I dont how to calculate this
destinationbitmap.height=megapixelcount*sourceaspect*???; // I dont how to calculate this
for x:=0 to destinationbitmap.width-1 do
for y:=0 to destinationbitmap.height-1 do
begin
sx:=??;
sy:=??;
destinationbitmap.canvas.pixels[x,y]=sourcebitmap.canvas.pixels[sx,sy];
end;
result:=destinationbitmap;
end;
Run Code Online (Sandbox Code Playgroud)
我需要真正的公式......所以OpenGL解决方案并不理想......
我正在开发一个OpenCV程序来查找从相机到具有已知宽高比的矩形的距离.从正面视图中查找到矩形的距离可以正常工作:
实际距离非常接近于此计算的距离:
wtarget · pimage
d = c ——————————————————————————
2 · ptarget · tan(?fov / 2)
其中w target是目标的实际宽度(以英寸为单位),p image是整个图像的像素宽度,p target是检测到的四边形的最大宽度(以像素为单位)的长度,θfov是FOV我们的摄像头.然后将其乘以某个常数c.
从非正向的透视图中查看目标矩形时会发生此问题:
这两个方向之间的实际距离差异很小,但检测到的距离相差近2英尺.
我想知道的是如何一致地计算距离,考虑到不同的透视角度.我已经尝试过getPerspectiveTransform,但这需要我知道目标的最终比例 - 我只知道纵横比.
我有一个图像是一个包含像这样的盒装区域的背景:
我知道那个形状的角落的确切位置,我想在其中放置另一个图像.(所以它似乎在盒子里面).
我知道HTML5画布的drawImage方法,但似乎只支持x,y,width,height参数而不是精确坐标.我如何在一组特定坐标上将图像绘制到画布上,理想情况下,浏览器本身可以处理拉伸图像.