2

OpenCV を使用して、いくつかのポリゴンでインペインティングを行っています (紙に描かれています。例を参照してください)。

いくつかの伝説の仕様:

  • 緑色のフレームは、シーンの「境界」を描画するためにあります。参照用です。
  • 青いボールがシーンに浮かんでおり、ボールがポリゴンに当たると、ボールがオブジェクトを押しつぶしているかのように、適切なマスキングでシーンが再レンダリングされます。

inpaintedScene参照用のコードを次にtransformedScene示しoutputFrameますcv::Mat

 cv::Mat mask_image(outputFrame.size(), CV_8U, BLACK_COLOR);
 std::vector<cv::Point*> destroyedPolygons = //some sub-polygons that has been hit by the ball
 std::vector<int> destroyedPolygonsPointCount = //points count for each destroyed polygon
 for (int i = 0; i < destroyedPolygons.size(); i++)
 {
    const cv::Point* ppt[1] = { destroyedPolygons[i] };
    int npt[] = { destroyedPolygonsPointCount[i] };
    cv::fillPoly(mask_image, ppt, npt, 1, WHITE_COLOR);
 }

 // now that the mask is prepared, copy the points from the inpainted to the scene
 inpaintedScene.copyTo(transformedScene, mask_image);

 // here I have two options:
 //option 1
 outputFrame += transformedScene;

 //option 2
 transformedScene.copyTo(outputFrame, transformedScene);

これらは、どれも私にとって良くない結果です:

オプション 1 の結果 (+=):

ここに画像の説明を入力

破壊されたポリゴンを透明にするので、これは私にとっては良くありません。

オプション 2 (copyTo) の結果:

ここに画像の説明を入力

ご覧のとおり、ポリゴンの破壊された部分は、(ポリゴンが別の色であっても) 黒色の「縁取り」または「枠」になっているため、これも良くありません。これを解決するにはどうすればよいでしょうか?

4

1 に答える 1

1

それを見つけた!

「最近傍」補間を追加warpPerspectiveしました:transformedScene

cv::warpPerspective(transformedScene, transformedScene, warpImageMat, outputFrame.size(), CV_INTER_NN);

warpImageMatの型はどこですかcv::Mat

OpenCVの機能について詳しくはこちらwarpPerspective

乾杯!

于 2014-05-27T19:15:17.347 に答える