2

私はOpenCVが初めてなので、寛大にしてください。正方形/長方形を認識してトリミングする Android アプリケーションを実行しています。正方形/長方形を探す関数は、見つかったオブジェクトを vector> squares に配置します。vector> squares に格納されているポイントのデータに従って画像をトリミングする方法と、画像を回転させる角度を計算する方法を知りたいだけです。助けてくれてありがとう

4

3 に答える 3

2

この投稿はOpenCV QA: Extract a RotatedRect areaから引用しています。

画像の回転と傾き補正に関するFelix Abecassisによる素晴らしい記事があります。これは、RotatedRect でデータを抽出する方法も示しています。

基本的に、 cv::warpAffinecv::getRectSubPixを使用してアフィン変換の回転行列を取得し、回転した画像をトリミングするには、 cv::getRotationMatrix2Dのみが必要です。私のアプリケーションの関連行は次のとおりです。

// This is the RotatedRect, I got it from a contour for example...
RotatedRect rect = ...;
// matrices we'll use
Mat M, rotated, cropped;
// get angle and size from the bounding box
float angle = rect.angle;
Size rect_size = rect.size;
// thanks to http://felix.abecassis.me/2011/10/opencv-rotation-deskewing/
if (rect.angle < -45.) {
    angle += 90.0;
    swap(rect_size.width, rect_size.height);
}
// get the rotation matrix
M = getRotationMatrix2D(rect.center, angle, 1.0);
// perform the affine transformation on your image in src,
// the result is the rotated image in rotated. I am doing
// cubic interpolation here
warpAffine(src, rotated, M, src.size(), INTER_CUBIC);
// crop the resulting image, which is then given in cropped
getRectSubPix(rotated, rect_size, rect.center, cropped);
于 2012-12-01T17:46:40.463 に答える
1

便利な投稿がたくさんあります。より良い検索ができると思います。

作物:

回転:

角度を計算する:

于 2012-12-01T11:12:22.813 に答える