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