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;
    }
  • 相关阅读:
    Android-View动画
    Android-RemoteView-桌面小部件
    系统的Drawable(四)-LayerListDrawable
    Android-Drawable(三)
    系统的Drawable(二)-Selector
    系统的Drawable(一)
    Android View事件分发-从源码分析
    打游戏要存进度-备忘录模式
    Java 内部类.md
    docker 常用 命令
  • 原文地址:https://www.cnblogs.com/x1957/p/3536677.html
Copyright © 2011-2022 走看看