zoukankan      html  css  js  c++  java
  • LBP简单实现

    Local Binary Pattern

    确实够简单。。。先写个代码在这儿,空了再弄

    #include <opencv2/opencv.hpp>
    #include <iostream>
    #include <vector>
    
    using namespace std;
    using namespace cv;
    void LBP(const Mat& src , Mat& dst) {
        int rows =src.rows;
        int cols = src.cols;
        
        auto expand = [&](int x , int y) {
            int dx[] = {-1,-1,-1,0,1,1,1,0};
            int dy[] = {-1,0,1,1,1,0,-1,-1};
            vector<pair<int,int> > result(8);
            for(int i = 0 ; i < 8 ; ++i) 
                result[i] = make_pair(x+dx[i] , y+dy[i]);
            return result;
        };
        auto judge = [&](int x1 , int y1 , int x2 , int y2) {
            return src.at<unsigned char> (x1 , y1) >= src.at<unsigned char>(x2, y2) ? 1 : 0;
        };
        
        //split the block
        //parallelism
        for(int i = 1 ; i < rows - 1 ; ++i) {
            for(int j = 1 ; j < cols - 1 ; ++j) {
                auto near = expand(i , j);
                int lbp = 0;
                int pos = 0;
                for(auto& location : near) {
                    lbp += judge(location.first , location.second , i , j) * (1<<pos);
                    ++pos;
                }
                dst.at<unsigned char>(i-1 , j-1) = lbp;
            }
        }
    }
    int main() {
        Mat imgr = imread("lenna.png", CV_LOAD_IMAGE_COLOR);
        Mat img;
        cvtColor(imgr,img,CV_RGB2GRAY);
        Mat out(img);
        LBP(img , out);
        imwrite("image_lbp.png", out);
        return 0;
    }
  • 相关阅读:
    jmeter的基本功能使用详解
    服务器资源监控插件(jmeter)
    前端技术之--CSS
    前端技术之--HTML
    TCP/IP基础知识
    TCP/IP、Http的区别
    关于性能调优
    如何修改Docker已运行实例的端口映射
    Mysql 主从同步配置
    Presto的基本概念
  • 原文地址:https://www.cnblogs.com/x1957/p/3536677.html
Copyright © 2011-2022 走看看