メソッドに間違った値を使用しているため、変換は失敗しますgetPerspectiveTransform。出力画像を作成する方法と、この画像のデータから宛先コーナーを設定する方法を混同しているようです。
また、配列の右隅(左上、右上、左下、右下)をリンクすることが重要です。これを混同しているようです。
この例では、正しいポイントを接続して空の出力画像に出力する方法を示します。
// Assuming your source image is called 'sourceImage' and you have the corner points you need:
// Create vectors to store the corners
vector<Point2f> originalCorners;
vector<Point2f> destinationCorners;
// Put the Sudoku corners in your originalCorners
originalCorners.clear();
originalCorners.push_back(Point2f(lt.x, lt.y);
originalCorners.push_back(Point2f(rt.x, rt.y);
originalCorners.push_back(Point2f(lb.x, lb.y);
originalCorners.push_back(Point2f(rb.x, rb.y);
// Output image size of 450x450
int ouputImageWidth = 450;
int outputImageHeight = 450;
// Create an empty image (450x450) to output your transformation result in
Mat transformedOutputImage(ouputImageWidth, outputImageHeight, sourceImage.type());
// Now put the corners of the output image so the warp knows where to warp to
destinationCorners.clear();
destinationCorners.push_back(Point2f(0, 0));
destinationCorners.push_back(Point2f(ouputImageWidth, 0));
destinationCorners.push_back(Point2f(0, outputImageHeight));
destinationCorners.push_back(Point2f(ouputImageWidth, outputImageHeight));
// Now we have all corners sorted, so we can create the warp matrix
Mat warpMatrix = getPerspectiveTransform(originalCorners, destinationCorners);
// And now we can warp the Sudoku in the new image
warpPerspective(sourceImage, transformedOutputImage, warpMatrix, Size(ouputImageWidth, ouputImageHeight));
さて、これは、ワープしたい画像の部分のコーナーポイントを知っていることを前提としています. 真ん中の四角のポイントを取得する方法がわからない場合は、これらの優れた回答を参照することをお勧めします。
ただし、4 つのコーナー ポイントがある限り、この方法は機能します。中央の四角い角のポイントを手動で検索して挿入することで、それを試すこともできます。