I have attached the image I am talking about. I want to get the perspective transformation so I can get the card in its canonical form. It does not work and I get a bad output.
This is my code. The points I got from point and they are correct (checked with the function circle() )
void main(){
cv::Mat begin = cv::imread("\cards.jpg");
cv::Mat output;
cv::Point2f Poly2[4] = {
cv::Point2f(222,93),
cv::Point2f(430,134),
cv::Point2f(368,426),
cv::Point2f(162,378),
};
cv::Point2f Points[4] = {
cv::Point2f(0,0),
cv::Point2f(300,0),
cv::Point2f(0,600), //The picture I want to transform to.
cv::Point2f(600,300),
};
for (int i = 0; i < 4; i++) {
cv::circle(begin, cv::Point2d(Poly2[i].x, Poly2[i].y), 2, cv::Scalar(244, 233, 44), 3, 8, 0);
}
cv::Mat Matrix = cv::getPerspectiveTransform( Points,Poly2);
cv::warpPerspective(begin, output, Matrix, cv::Size(300, 600));
cv::imshow("begin", begin);
cv::imshow("Output", output);
cv::waitKey(0);
}
I hope you guys can help me.