gpt4 book ai didi

c++ - OpenCv2.2 C++ filter2D

转载 作者:太空狗 更新时间:2023-10-29 21:21:47 25 4
gpt4 key购买 nike

我正在使用 OpenCv2.2 将 matlab 代码传输到 c++,在一个类似于 matlab 的函数 (conv2) 中,我使用来自

#include <opencv2/imgproc/imgproc.hpp>

问题是我收到的错误消息:

OpenCV Error: The function/feature is not implemented (Unsupported combination of source format (=4), and destination format (=4)) in getLinearFilter, file C:\opencv\sources\modules\imgproc\src\filter.cpp, line 3234

terminate called after throwing an instance of 'cv::Exception'

what(): C:\opencv\sources\modules\imgproc\src\filter.cpp:3234: error: (-213) Unsupported combination of source format (=4), and destination format (=4) in function getLinearFilter

第一次遇到这样的错误。所以,我真的不知道这是来 self 的安装还是来自代码。

============================================= =============================================附件:

代码:

void conv2(const Mat &img, const Mat& kernel, ConvolutionType type, Mat& dest)
{
// fonction trouvée sur le site :
// http://blog.timmlinder.com/2011/07/opencv-equivalent-to-matlabs-conv2-function/
// par Timm Linder le 05/07/2011
Mat source = img;
if(CONVOLUTION_FULL == type) {
source = Mat();
const int additionalRows = kernel.rows-1, additionalCols = kernel.cols-1;
copyMakeBorder(img, source, (additionalRows+1)/2, additionalRows/2, (additionalCols+1)/2, additionalCols/2, BORDER_CONSTANT, Scalar(0));
}

Point anchor(kernel.cols - kernel.cols/2 - 1, kernel.rows - kernel.rows/2 - 1);
int borderMode = BORDER_CONSTANT;

filter2D(source, dest, img.depth(), flip(kernel), anchor, 0, borderMode);

//cvFilter2D(source, dest, img.depth(), flip(kernel), anchor, 0, borderMode);

if(CONVOLUTION_VALID == type) {
dest = dest.colRange((kernel.cols-1)/2, dest.cols - kernel.cols/2)
.rowRange((kernel.rows-1)/2, dest.rows - kernel.rows/2);
}
}

在这个博客上找到: http://blog.timmlinder.com/2011/07/opencv-equivalent-to-matlabs-conv2-function/(如果有人有更好的想法来重现可能很有趣的 conv2)

最佳答案

看着filter2d docs , -很明显,您不能使用 int32 Mats (type()==4)。

您必须转换为 CV_8U、CV_16U、CV_32F、CV_64F 之一

(也可以考虑更新你的 opencv。2.2 已经很旧了)

关于c++ - OpenCv2.2 C++ filter2D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21958219/

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