matlab中C = conv2(H1, H2, A, 'same');
这条语句用c++如何实现呢?
求大侠们帮帮忙!!!

解决方案 »

  1.   

    http://download.csdn.net/source/731440
      

  2.   

    我在网上看到过这个代码,如果图像太大,效率会很低,不知用opencv的cvFilter2D函数是否与用conv2得到的结果一致呢?
      

  3.   

    cvFilter2D好象不是做卷积的.
    效率问题需要优化.可以参考INTEL IPP库,看是否有类似的实现.
    也可考虑用GPU优化,参考nvida的CUDA.
      

  4.   

    调用opencv函数:enum ConvolutionType {   
    /* Return the full convolution, including border */
      CONVOLUTION_FULL, /* Return only the part that corresponds to the original image */
      CONVOLUTION_SAME,/* Return only the submatrix containing elements that were not influenced by the border       
    */
      CONVOLUTION_VALID
    };void conv2(const Mat &img, const Mat& kernel, ConvolutionType type, Mat& dest) {
      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);  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);
      }
    }