问题
I'm using EmguCV wrapper for OpenCV and I'm rectifing this shape:

with help of this code:
public Image<Bgr,byte> Rectify()
{
try
{
Image<Bgr, byte> warped_Image = new Image<Bgr, byte>(input_Image.Width, input_Image.Height);
MCvScalar s = new MCvScalar(0, 0, 0);
PointF[] dsts = new PointF[4];
dsts[0] = new PointF(0, 0);
dsts[2] = new PointF(0, input_Image.Height);
dsts[3] = new PointF(input_Image.Width, input_Image.Height);
dsts[1] = new PointF(input_Image.Width, 0);
HomographyMatrix mywarpmat = CameraCalibration.GetPerspectiveTransform(pnts, dsts);
Image<Bgr, byte> warped_Image2 = warped_Image.WarpPerspective(mywarpmat, Emgu.CV.CvEnum.INTER.CV_INTER_NN, Emgu.CV.CvEnum.WARP.CV_WARP_FILL_OUTLIERS, new Bgr(0, 0, 0));
CvInvoke.cvWarpPerspective(input_Image, warped_Image2, mywarpmat, (int)Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR, s);
Image<Bgr, byte> fixedImg = new Image<Bgr, byte>((int)warped_Image2.Width, (int)(warped_Image2.Width / aspectRatio));
CvInvoke.cvResize(warped_Image2.Ptr, fixedImg.Ptr, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
return fixedImg;
}
I get this result(rectified shape):

I know the corners coordinates both of the images (before and after rectification). Before the rectification I knew coordinates of the upper white line that inside the shape. Any idea how can i get the coordinates of this white line after rectification?
Thank you in advance!
回答1:
Having homography matrix it's quite easy. As you know an homography matrix maps straight line into straight line, so you can simply project the endpoints of your input image line Here's some vanilla pseudocode :
PointF[] pts = new PointF[] {
new PointF(startingLinePoint.x, startingLinePoint.y),
new PointF(endingLinePoint.x, endingLinePoint.y)
};
mywarpmat.ProjectPoints(pts);
Pts will contained the starting and ending point of the line you are searching in the projected then you have to simply define line passing through them.
回答2:
You already have the homography matrix, so to get the points on the line, just transform the points from the first image (before rectification) using the homography. This will give you the coordinates in the rectified image.
For more details, check the mathematical definition of homography. Basically, you need to find points on the line (or the two end-points of the line), and express them in homogeneous coordinates, similar to the way p_a is defined in the article. You then transform these points using the homography and normalise by the Z coordinates to obtain image coordinates of the transformed points. This has been defined as p_b in the article.
Hope this helps.
来源:https://stackoverflow.com/questions/16589713/how-to-get-coordinates-of-pixel-after-shape-was-rectified