2

画像の一部を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のせいだと思います。画像をそのままフィットさせる方法と、オーバーレイ画像の代わりに黒い斑点が表示される理由を教えてください。

4

2 に答える 2

0

これを行う1つの方法は、写真を白いポリゴンサイズに拡大縮小してから、関心領域を設定する取得した画像にコピーすることです(ROIを説明するリンクは次のとおりです)。コードは次のようになります。

resize(pic, resizedImage, resizedImage.size(), 0, 0, interpolation); //resizedImage should have the points size
cvSetImageROI(image, cvRect(the points coordinates));
cvCopy(resizedImage,image);
cvResetImageROI(image);

それがお役に立てば幸いです。

よろしく、ダニエル

于 2012-04-04T01:52:11.450 に答える
0

cvWarpPerspectiveリンク)はあなたが探しているものだと思います。

だからする代わりに

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

試す

cvWarpPerspective(yourimage, image, M, image.size(), INTER_CUBIC, BORDER_TRANSPARENT);

Mあなたが得るマトリックスはどこにありますかcvGetPerspectiveMatrix

于 2012-04-04T17:34:14.143 に答える