基于OpenCV的LBP算法(OpenCV1.0版本)
来源:互联网 发布:简谱制作软件app 编辑:程序博客网 时间:2024/05/22 03:13
#include <opencv2/opencv.hpp>#include <iostream>#include <cassert>using namespace std;using namespace cv;//基于旧版本的opencv的LBP算法opencv1.0 // 3 x 3 矩阵如下所示// [ 1, 2, 3]// [ 8, ij,4]// [ 7, 6, 5]void LBP(IplImage *src, IplImage *dst){// 进行处理的原图像为单通道图像assert(src != NULL && src->nChannels == 1);int tmp[8] = { 0 };int rows = src->height - 1;int cols = src->width - 1;for (int i = 1; i < rows; ++i){for (int j = 1; j < cols; ++j){int sum = 0;double val = cvGetReal2D(src, i, j);double tempVal = 0.0;tempVal = cvGetReal2D(src, i - 1, j - 1);// 左上角tempVal > val ? tmp[0] = 255 : tmp[0] = 0;tempVal = cvGetReal2D(src, i, j - 1);// 正上方tempVal > val ? tmp[1] = 255 : tmp[1] = 0;tempVal = cvGetReal2D(src, i + 1, j - 1);// 右上角tempVal > val ? tmp[2] = 255 : tmp[2] = 0;tempVal = cvGetReal2D(src, i + 1, j);// 右侧tempVal > val ? tmp[3] = 255 : tmp[3] = 0;tempVal = cvGetReal2D(src, i + 1, j + 1);// 右下角tempVal > val ? tmp[4] = 255 : tmp[4] = 0;tempVal = cvGetReal2D(src, i, j + 1);// 正下方tempVal > val ? tmp[5] = 255 : tmp[5] = 0;tempVal = cvGetReal2D(src, i - 1, j + 1);// 左下角tempVal > val ? tmp[6] = 255 : tmp[6] = 0;tempVal = cvGetReal2D(src, i - 1, j);// 左侧tempVal > val ? tmp[7] = 255 : tmp[7] = 0;// 计算 LBP 编码for (int k = 0; k < 8; ++k){sum += tmp[k] * pow(2, k);}cvSetReal2D(dst, i, j, sum);}}}// 圆形 LBP 算子void ELBP(IplImage* src, IplImage* dst, int radius, int neighbors){// 处理的图像为单通道图像assert(src->nChannels == 1);for (int i = 0; i < neighbors; ++i){// 正弦弧度double sRadian = sin(2.0 * CV_PI * i / static_cast<double>(neighbors));// 余弦弧度double cRadian = cos(2.0 * CV_PI * i / static_cast<double>(neighbors));// 采样点的计算double x = static_cast<double>(-radius * sRadian);double y = static_cast<double>(radius * cRadian);// 下取整的值int fx = static_cast<int>(floor(x));int fy = static_cast<int>(floor(y));// 上取整的值int cx = static_cast<int>(ceil(x));int cy = static_cast<int>(ceil(y));// 小数部分double tx = x - fx;double ty = y - fy;// 设置插值权重double w1 = (1 - tx) * (1 - ty);double w2 = tx * (1 - ty);double w3 = (1 - tx) * ty;double w4 = tx * ty;// 循环处理图像数据for (int rows = radius; rows < src->height - radius; ++rows){for (int cols = radius; cols < src->width - radius; ++cols){// 计算插值double t1 = w1 * cvGetReal2D(src, rows + fy, cols + fx);double t2 = w2 * cvGetReal2D(src, rows + fy, cols + cx);double t3 = w3 * cvGetReal2D(src, rows + cy, cols + fx);double t4 = w4 * cvGetReal2D(src, rows + cy, cols + cx);double t = t1 + t2 + t3 + t4;double val = cvGetReal2D(src, rows, cols);double epsilon = std::numeric_limits<double>::epsilon();uchar c = ((t > val) || abs(t - val) < epsilon);uchar tmp = c * pow(2, i);double v = cvGetReal2D(dst, rows - radius, cols - radius);v += tmp;cvSetReal2D(dst, rows - radius, cols - radius, v);}}}}
0 0
- 基于OpenCV的LBP算法(OpenCV1.0版本)
- 基于Opencv的LBP+SVM分类实例
- OpenCV1.0下移植OpenCV高版本函数
- Opencv 兼容OPENCV1.0
- 基于LBP的背景建模算法
- 基于LBP的背景建模算法
- 基于LBP的背景建模算法
- opencv:求一幅图片的LBP纹理图(c++版本)
- 基于 OpenCV 的 LBP + SVM 人脸识别
- 【OpenCV】OpenCV1.0图像直方图
- 【opencv】LBP(局部二进制模式)算法的实现
- OpenCV1.0版本中cvaux.lib无法找到的问题
- opencv1.0版本摄像头驱动不兼容问题的解决方法
- 基于LBP算子的人脸识别算法
- 基于LBP的Face Verification(人脸验证)算法
- LBP算法的研究
- opencv lbp人脸检测算法
- 基于OpenCV1.1的图像拼接
- Linux进程间通信的方式
- laravel框架简单文件上传
- golang驱动kafka
- leetcode 347. Top K Frequent Elements
- netty权威指南之九 自定义协议
- 基于OpenCV的LBP算法(OpenCV1.0版本)
- jquery
- ssh连接远程主机执行脚本的环境变量问题
- H.266:帧内角度预测
- 剑指Offer——中国银行面试知识储备+面试内容(Offer-2已收割)
- 了解Binder机制(极简主义解释风格)
- 错题库
- hdu 2058 The sum problem
- 统计进入公园的人总数