opencv检测图片模糊度算法
来源:互联网 发布:招商网站留言数据提取 编辑:程序博客网 时间:2024/05/29 15:06
/*检测模糊度 返回值为模糊度,值越大越模糊,越小越清晰,范围在0到几十,10以下相对较清晰,一般为5。 调用时可在外部设定一个阀值,具体阈值根据实际情况决定,返回值超过阀值当作是模糊图片。 算法所耗时间在1毫秒内*/int VideoBlurDetect(const cv::Mat &srcimg){cv::Mat img;cv::cvtColor(srcimg, img, CV_BGR2GRAY); // 将输入的图片转为灰度图,使用灰度图检测模糊度//图片每行字节数及高 int width = img.cols;int height = img.rows;ushort* sobelTable = new ushort[width*height];memset(sobelTable, 0, width*height*sizeof(ushort));int i, j, mul;//指向图像首地址 uchar* udata = img.data;for (i = 1, mul = i*width; i < height - 1; i++, mul += width)for (j = 1; j < width - 1; j++)sobelTable[mul + j] = abs(udata[mul + j - width - 1] + 2 * udata[mul + j - 1] + udata[mul + j - 1 + width] - \udata[mul + j + 1 - width] - 2 * udata[mul + j + 1] - udata[mul + j + width + 1]);for (i = 1, mul = i*width; i < height - 1; i++, mul += width)for (j = 1; j < width - 1; j++)if (sobelTable[mul + j] < 50 || sobelTable[mul + j] <= sobelTable[mul + j - 1] || \sobelTable[mul + j] <= sobelTable[mul + j + 1]) sobelTable[mul + j] = 0;int totLen = 0;int totCount = 1;uchar suddenThre = 50;uchar sameThre = 3;//遍历图片 for (i = 1, mul = i*width; i < height - 1; i++, mul += width){for (j = 1; j < width - 1; j++){if (sobelTable[mul + j]){int count = 0;uchar tmpThre = 5;uchar max = udata[mul + j] > udata[mul + j - 1] ? 0 : 1;for (int t = j; t > 0; t--){count++;if (abs(udata[mul + t] - udata[mul + t - 1]) > suddenThre)break;if (max && udata[mul + t] > udata[mul + t - 1])break;if (!max && udata[mul + t] < udata[mul + t - 1])break;int tmp = 0;for (int s = t; s > 0; s--){if (abs(udata[mul + t] - udata[mul + s]) < sameThre){tmp++;if (tmp > tmpThre) break;}else break;}if (tmp > tmpThre) break;}max = udata[mul + j] > udata[mul + j + 1] ? 0 : 1;for (int t = j; t < width; t++){count++;if (abs(udata[mul + t] - udata[mul + t + 1]) > suddenThre)break;if (max && udata[mul + t] > udata[mul + t + 1])break;if (!max && udata[mul + t] < udata[mul + t + 1])break;int tmp = 0;for (int s = t; s < width; s++){if (abs(udata[mul + t] - udata[mul + s]) < sameThre){tmp++;if (tmp > tmpThre) break;}else break;}if (tmp > tmpThre) break;}count--;totCount++;totLen += count;}}}//模糊度float result = (float)totLen / totCount;delete[] sobelTable;sobelTable = NULL;return result;}
阅读全文
0 0
- opencv检测图片模糊度算法
- 【OpenCV】图像模糊检测
- IOS 图片模糊算法
- 【python 图像检测】图像模糊检测算法
- 基于OpenCV的图像模糊与否检测
- Atitit 图像清晰度 模糊度 检测 识别 评价算法 原理
- OPENCV svm检测算法
- 模糊算法增强图片对比度
- opencv Canny图片边缘检测
- canny opencv边缘检测算法
- opencv目标检测算法资源
- opencv 边缘检测 Contours 算法
- opencv学习之三:高斯模糊以及canny检测
- 用 Opencv 和 Python 对狗狗做模糊检测
- 基于神经模糊算法的边缘检测算法
- Atitit 图像清晰度 模糊度 检测 识别 评价算法 源码实现attilax总结
- opencv 图片中的 人脸检测
- OpenCV学习笔记_图片边缘检测
- std::unique_ptr和std::shared_ptr的用法
- 继承
- 关于sdnu1095和擂台法的运用
- 深入理解移动端像素知识与Viewport知识
- mapreduce自定义排序
- opencv检测图片模糊度算法
- 分页插件PageHelper
- 【bzoj2064】分裂
- 打开android 系统的相机,拍照并且图片返回
- 对决策树的一些理解
- Android studio加速编译
- java程序员从笨鸟到菜鸟之(二十一)正则表达式
- sql不走索引的情况合集
- ABP官方文档(四十五)【集成Hangfire】