我正在尝试从裁剪版本的图像中删除失真。我知道全尺寸图像的x和y映射矩阵(1920X1080)。我尝试这样做的方法是首先创建两个新的映射,其中包含与裁剪矩形对应的全尺寸映射的一部分,然后将它们应用于裁剪的图像。但是,输出只是一个黑色图像:
Matrix<float> matCam1Map1, matCam1Map2;
Matrix<float> matCam1Map1Crp, matCam1Map2Crp;
matCam1Map1 = new Matrix<float>(1080, 1920);
matCam1Map2 = new Matrix<float>(1080, 1920);
CvInvoke.cvInitUndistortMap(itsCam1.IntrinsicMatrix.Ptr, itsCam1.DistortionCoeffs.Ptr, matCam1Map1.Ptr, matCam1Map2.Ptr);
matCam1Map1Crp = new Matrix<float>(rectCam1Crop.Height, rectCam1Crop.Width);
matCam1Map2Crp = new Matrix<float>(rectCam1Crop.Height, rectCam1Crop.Width);
for (int i = 0; i < rectCam1Crop.Height; i++)
{
for (int j = 0; j < rectCam1Crop.Width; j++)
{
matCam1Map1Crp.Data[i, j] = matCam1Map1.Data[rectCam1Crop.Y + i, rectCam1Crop.X + j];
matCam1Map2Crp.Data[i, j] = matCam1Map2.Data[rectCam1Crop.Y + i, rectCam1Crop.X + j];
}
}
Capture capCam1;
Image<Bgr, Byte> imgCam1New = capCam1.QueryFrame().Copy(rectCam1Crop);
Image<Bgr, Byte> imgNoDistortion = new Image<Bgr, byte>(imgCam1New.Size);
CvInvoke.cvRemap(imgCam1New, imgNoDistortion, matCam1Map1Crp, matCam1Map2Crp, 0, new MCvScalar(0));
当我将全尺寸映射应用于完整尺寸图像时,它可以完美地工作,但之后我必须裁剪它。但是,我试图通过首先裁剪它,然后将映射应用于裁剪图像来加快速度。
有谁知道我的代码可能存在什么问题? 感谢