如何正确使用 cvResize/resize?

发布于 2024-10-14 05:06:53 字数 897 浏览 4 评论 0 原文

我无法将 6x6 图像调整为 120x120。看起来调整大小后的图像稍微移动了 1 个像素。 cvResizecv::resize 会发生这种情况。我的代码如下所示:

warpPerspective(greyImg, warpedImg, homography, Size(6, 6));
Mat bigWarpedImg = Mat(120,120,CV_8UC1);
resize(warpedImg, bigWarpedImg, Size(0,0), 20, 20, INTER_NEAREST);

warpedImg 如下所示(我用 gimp 调整了它的大小以使其更易于识别):http://picasaweb.google.com/103165673068768416583/Opencv#5565090881969794706

bigWarpedImg 看起来像这样: http://picasaweb.google.com/103165673068768416583/Opencv#5565090880773608210

如您所见,在bigWarpedImg中左边框和上边框太小,而右边框和下边框太粗。它看起来像是 OpenCV 中的一个错误。这是一个还是我错误地使用了这个功能?

I have trouble resizing a 6x6 image to 120x120. It looks like the resized image is somewhat shifted by 1 pixel. This happens with the cvResize and with cv::resize. My code looks like this:

warpPerspective(greyImg, warpedImg, homography, Size(6, 6));
Mat bigWarpedImg = Mat(120,120,CV_8UC1);
resize(warpedImg, bigWarpedImg, Size(0,0), 20, 20, INTER_NEAREST);

warpedImg looks like this (I resized it with gimp to make it easier to recognize): http://picasaweb.google.com/103165673068768416583/Opencv#5565090881969794706

bigWarpedImg looks like this: http://picasaweb.google.com/103165673068768416583/Opencv#5565090880773608210

As you can see, in bigWarpedImg the left and upper border is to small whereas the right and bottom border is too thick. It looks like a bug in OpenCV. Is this one or do I use this function incorrectly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森罗 2024-10-21 05:06:53
Mat bigWarpedImg = Mat(120,120,CV_8UC1);

此行是不必要的 - resize 将分配目标 Mat 以使其适合,因此 Mat bigWarpedImg 就可以了。

不确定调整大小 - 我总是使用

resize(warpedImg, bigWarpedImg, Size(120,120), 0, 0, INTER_NEAREST);

resize 的形式,但从未注意到这种行为。我想说这是一个错误,但从文档来看它不应该这样。

Mat bigWarpedImg = Mat(120,120,CV_8UC1);

this line is unneccessary - resize will allocate the target Mat to make it fit, so Mat bigWarpedImg would be fine.

Not sure about the resizing - I always use the

resize(warpedImg, bigWarpedImg, Size(120,120), 0, 0, INTER_NEAREST);

form of resize and never noticed such behaviour. I'd say it's a bug though, from the documentation it shouldn't act like that.

紫﹏色ふ单纯 2024-10-21 05:06:53

这可能是因为您使用的是最近插值。尝试更好的(我认为是双三次的)。

It could be because you're using nearest interpolation. Try the better ones (I think bicubic).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文