gpt4 book ai didi

OpenCV cvRemap 裁剪图像

转载 作者:太空宇宙 更新时间:2023-11-03 20:58:29 25 4
gpt4 key购买 nike

所以我是 OpenCV (2.1) 的新手,所以请记住这一点。

因此,我设法校准了我正在使用的廉价网络摄像头(带有广角附件),使用棋盘校准方法产生固有系数和畸变系数。

然后我可以毫不费力地反馈这些值并生成图像映射,然后我将其应用于视频源以更正传入的图像。

但是我遇到了一个问题。我知道当它扭曲/校正图像时,它会创建几个倾斜的部分,然后格式化图像以裁剪掉任何黑色区域。那么我的问题是我可以查看完整的扭曲图像,包括一些有黑色区域的区域吗?下面是一个带有倾斜部分的黑色区域的示例,如果我的术语不正确,我试图传达:

更好地传达我正在谈论的区域的图像可以是 found here !此图像是在 post 中发现的.

目前: cvRemap() 基本上返回上面链接图像中的黄色框,但我想查看整个图像,因为我希望从中获取相关数据。

我尝试过的方法:对图像贴图应用比例转换,使完整图像(包括拉伸(stretch)部分)适合框架

        CvMat *intrinsic = (CvMat*)cvLoad( "Intrinsics.xml" );
CvMat *distortion = (CvMat*)cvLoad( "Distortion.xml" );

cvInitUndistortMap( intrinsic, distortion, mapx, mapy );

cvConvertScale(mapx, mapx, 1.25, -shift_x); // Some sort of scale conversion
cvConvertScale(mapy, mapy, 1.25, -shift_y); // applied to the image map

cvRemap(distorted,undistorted,mapx,mapy);

当我认为我已经正确对齐 x/y 偏移(猜测/检查)时,cvConvertScale 以某种方式扭曲了图像映射,使校正变得无用。这里可能涉及一些数学,我没有正确理解/理解。

有没有人有任何其他建议来解决这个问题,或者我可能做错了什么?我也曾尝试编写自己的代码来解决失真问题,但只能说 OpenCV 已经知道如何做好。

最佳答案

凭内存,需要用InitUndistortRectifyMap(cameraMatrix,distCoeffs,R,newCameraMatrix,map1,map2) ,其中InitUndistortMap是一个简化版。

cvInitUndistortMap( intrinsic, distort, map1, map2 )

相当于:

cvInitUndistortRectifyMap( intrinsic, distort, Identity matrix, intrinsic, 
map1, map2 )

新参数是RnewCameraMatrixR 指定要执行的附加转换(例如旋转)(只需将其设置为单位矩阵)。

您感兴趣的参数是newCameraMatrix。在 InitUndistortMap 中,这与原始相机矩阵相同,但您可以使用它来获得您所说的缩放效果。

你用 GetOptimalNewCameraMatrix(cameraMat, distCoeffs, imageSize, alpha,...) 得到新的相机矩阵.您基本上输入 intrinsicdistort、原始图像大小和参数 alpha(以及用于保存结果矩阵的容器,请参阅文档).参数 alpha 将实现您想要的。

我引用文档:

The function computes the optimal new camera matrix based on the free scaling parameter. By varying this parameter the user may retrieve only sensible pixels alpha=0, keep all the original image pixels if there is valuable information in the corners alpha=1, or get something in between. When alpha>0, the undistortion result will likely have some black pixels corresponding to “virtual” pixels outside of the captured distorted image. The original camera matrix, distortion coefficients, the computed new camera matrix and the newImageSize should be passed to InitUndistortRectifyMap to produce the maps for Remap.

所以对于极端的例子,所有的黑色位都显示你想要 alpha=1

总结:

  • alpha=1调用cvGetOptimalNewCameraMatrix得到newCameraMatrix
  • 使用 cvInitUndistortRectifymapR 是单位矩阵,newCameraMatrix 设置为您刚刚计算的值
  • 将新 map 输入 cvRemap

关于OpenCV cvRemap 裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8837478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com