zoukankan      html  css  js  c++  java
  • opencv::BackgroundSubtraction基本原理

    背景消除

    BS算法  
        - 图像分割(GMM – 高斯混合模型)  
        - 机器学习(KNN –K个最近邻) 
    BackgroundSubtractor (父类)
       -  BackgroundSubtractorMOG2 
       -  BackgroundSubtractorKNN
    #include <opencv2/opencv.hpp>
    #include <iostream>
    
    using namespace cv;
    using namespace std;
    
    int main(int argc, char**) {
        VideoCapture capture;
        capture.open("D:/images/video_004.avi");
        if (!capture.isOpened()) {
            printf("could not find the video file...
    ");
            return -1;
        }
        // create windows
        Mat frame;
        Mat bsmaskMOG2, bsmaskKNN;
        namedWindow("input video", CV_WINDOW_AUTOSIZE);
        namedWindow("MOG2", CV_WINDOW_AUTOSIZE);
    
        Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
    
        // MOG2 BS
        Ptr<BackgroundSubtractor> pMOG2 = createBackgroundSubtractorMOG2();
        // KNN  BS
        Ptr<BackgroundSubtractor> pKNN = createBackgroundSubtractorKNN();
    while (capture.read(frame)) { imshow("input video", frame); pMOG2->apply(frame, bsmaskMOG2); morphologyEx(bsmaskMOG2, bsmaskMOG2, MORPH_OPEN, kernel, Point(-1, -1)); imshow("MOG2", bsmaskMOG2); pKNN->apply(frame, bsmaskKNN); morphologyEx(bsmaskKNN, bsmaskKNN, MORPH_OPEN, kernel, Point(-1, -1)); imshow("KNN", bsmaskKNN); char c = waitKey(100); if (c == 27) { break; } } capture.release(); waitKey(0); return 0; }
  • 相关阅读:
    <BackTracking> dfs: 39 40
    <Tree> 110 124
    <Tree.PreOrder> DFS 113, 129
    <Math> 50 367
    <String> 49 87
    Haproxy配置Rabbitmq集群负载均衡
    Rabbitmq镜像集群的搭建
    rabbitmq常用命令
    Linux安装rabbitmq
    Docker自定义网络
  • 原文地址:https://www.cnblogs.com/osbreak/p/11753366.html
Copyright © 2011-2022 走看看