画像の一部をOpencvの画像に置き換えたい
使用しました
cvGetPerspectiveMatrix() with a warpmatrix and using cvAnd() and cvOr()
しかし、それを機能させることができませんでした
これは、現在画像を表示しているコードと、置換画像の白いポリゴンです。写真の白いポリゴンを、拡大縮小して指定された領域に置き換える任意の寸法に置き換えたいと思います。
コードがjavacvにある間、cコードが投稿されていてもjavaに変換できます
grabber.start();
while(isDisp() && (image=grabber.grab())!=null){
if (dst_corners != null) {// corners of the image to be replaced
CvPoint points = new CvPoint((byte) 0,dst_corners,0,dst_corners.length);
cvFillConvexPoly(image,points, 4, CvScalar.WHITE, 1, 0);//white polygon covering the replacement image
}
correspondFrame.showImage(image);
}
これへのポインタは非常に役立ちます。
アップデート:
このコードでwarpmatrixを使用しましたが、オーバーレイ画像に黒い斑点があります
cvSetImageROI(image, cvRect(x1,y1, overlay.width(), overlay.height()));
CvPoint2D32f p = new CvPoint2D32f(4);
CvPoint2D32f q = new CvPoint2D32f(4);
q.position(0).x(0);
q.position(0).y(0);
q.position(1).x((float) overlay.width());
q.position(1).y(0);
q.position(2).x((float) overlay.width());
q.position(2).y((float) overlay.height());
q.position(3).x(0);
q.position(3).y((float) overlay.height());
p.position(0).x((int)Math.round(dst_corners[0]);
p.position(0).y((int)Math.round(dst_corners[1]));
p.position(1).x((int)Math.round(dst_corners[2]));
p.position(1).y((int)Math.round(dst_corners[3]));
p.position(3).x((int)Math.round(dst_corners[4]));
p.position(3).y((int)Math.round(dst_corners[5]));
p.position(2).x((int)Math.round(dst_corners[6]));
p.position(2).y((int)Math.round(dst_corners[7]));
cvGetPerspectiveTransform(q, p, warp_matrix);
cvWarpPerspective(overlay, image, warp_matrix);
オーバーレイ画像に黒い斑点があり、元の画像は4つの頂点を持つポリゴンですが、オーバーレイ画像は長方形として設定されています。これはROIのせいだと思います。画像をそのままフィットさせる方法と、オーバーレイ画像の代わりに黒い斑点が表示される理由を教えてください。