您的位置:首页 > 运维架构

// OpenCV 计算图像的平均梯度

2014-03-31 20:24 357 查看
// OpenCV 计算图像的平均梯度

double calcAvG(const cv::Mat& img)

{

if(img.channels()!=1)

{

std::cout<<"输入必须是单通道图像!"<<std::endl;

return 0.0;

}

img.convertTo(img,CV_64FC1);

double tmp = 0;

int rows = img.rows-1;

int cols = img.cols-1;

for(int i=0;i<rows;i++)

{

for(int j=0;j<cols;j++)

{

double dx = img.at<double>(i,j+1)-img.at<double>(i,j);

double dy = img.at<double>(i+1,j)-img.at<double>(i,j);

double ds = std::sqrt((dx*dx+dy*dy)/2);

tmp = tmp+ds;

}

}

double imageAvG = tmp/(rows*cols);

return imageAvG;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: