0

opencvを使って画像ワープをしたいです。画像の 4 つのコーナー ((ex) 4000x4000) を検出し、opencv を使用getPerspectiveTransformして変換行列を取得しました。ここで、画像の中心で画像をゆがめたいと思います。だから私は使用しwarpPerspectiveました。入力したソース画像のサイズは 450x450 で、画像全体に対して計算した変換行列を使用します。

しかし、画面には何も表示されません。どんな助けでも大歓迎です。

サンプルコードとサンプル画像はこちら。

ソース画像です。 ソース画像です。

この画像が検出されました この画像が検出されました

これは、画像から必要なワーピング領域です。(コードの src_crop)

ここに画像の説明を入力

これが結果です。

ここに画像の説明を入力

        source[0] = Point2f(lt.x, lt.y);
        source[1] = Point2f(rt.x, rt.y);
        source[2] = Point2f(rb.x, rb.y);
        source[3] = Point2f(lb.x, lb.y);

        dst[0] = Point2f(6, 10);
        dst[1] = Point2f(3899, 7);
        dst[2] = Point2f(3901, 3899);
        dst[3] = Point2f(9, 3902);

        Mat transformMatrix ;
        transformMatrix = getPerspectiveTransform(source, dst);



        Mat dstFrame ;
        warpPerspective(src_crop, dstFrame, transformMatrix, Size(450, 450));
4

1 に答える 1

1

メソッドに間違った値を使用しているため、変換は失敗します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 つのコーナー ポイントがある限り、この方法は機能します。中央の四角い角のポイントを手動で検索して挿入することで、それを試すこともできます。

于 2017-04-05T12:46:41.677 に答える