针对MATLAB(imfilter)翻译C语言(opencv)遇到的问题

//在做项目的过程中把MATLAB翻译成c语言过程中发现使用cvfilter2D和Imfilter结果不同,但是Opencv2.0可以使用filter2D,据网上说结果一样,但是自己懒得移植整个工程,于是只能自己写了:

#include

#include

#include
#include
 
//Function Matlab filter
CvMat* imfilter2(CvMat* src_image,CvMat filter,CvMat* dst_image)
{
int R=src_image->rows;
int C=src_image->cols;
int start_row = int(19/2) ;//R-height
int start_col = int(19/2) ;

CvMat* Mid_Mat = cvCreateMat(R+2*start_row,C+2*start_col,CV_32FC1) ;//CvMat *mat3 = cvCreateMat( R,C, CV_32FC1  ); 
cvZero(Mid_Mat);


for (int i = 0; i < R; i++)
{
for (int j = 0; j < C; j++)
{

CV_MAT_ELEM(*Mid_Mat,float,i+start_row,j+start_col) = CV_MAT_ELEM(*src_image,float,i,j);//C

你可能感兴趣的:(Opencv)