I have a distorted image on which I use Cv2.Undistort()
which straightens it out. After this I find some points in the image. I need to get the location of those points in the distorted image.
I have tried Cv2.ProjectPoints()
but failed to get appropriate coordinates. They were outside the bounds of the image.
This is how I went about doing this:
List<float> arr = new List<float>();
foreach (var i in points)
{
arr.Add(i.X);
arr.Add(i.Y);
arr.Add(0);
}
Mat pointArr = new Mat(3, points.Count, MatType.CV_32FC1, arr.ToArray());
float[] rotArr = { 1, 0, 0,
0, 1, 0,
0, 0, 1};
float[] transArr = { 0, 0, 0 };
Mat rot = new Mat(3, 1, MatType.CV_32F, rotArr);
Mat trans = new Mat(3, 1, MatType.CV_32F, transArr);
Cv2.ProjectPoints(pointArr, rot, trans, camMatrix, dist, outputPoints);
List<Point2f> point2Fs = new List<Point2f>();
var lngt = outputPoints.Rows * outputPoints.Cols * outputPoints.Channels();
var matarr = new List<float>();
for (int i = 0; i < outputPoints.Rows; i++)
{
point2Fs.Add(new Point2f(outputPoints.ExtractChannel(0).At<float>(0, i), outputPoints.ExtractChannel(1).At<float>(0, i)));
}
points - the points in the undistorted image I want to find in the original
Any suggestions?
Thanks!