gpt4 book ai didi

opencv - 在 OpenCV 中将较小的图像覆盖在较大的图像中

转载 作者:太空宇宙 更新时间:2023-11-03 21:54:57 26 4
gpt4 key购买 nike

我想用我在 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 个顶点的多边形,叠加图像也被设置为矩形。我相信这是因为投资返回率。谁能告诉我如何按原样调整图像以及为什么我得到的是黑点而不是叠加图像。

最佳答案

我认为cvWarpPerspective ( link ) 就是您要找的。

所以而不是做

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 得到的矩阵

关于opencv - 在 OpenCV 中将较小的图像覆盖在较大的图像中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9997544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com