zoukankan      html  css  js  c++  java
  • Opencv二值图像的分布直方图

    Mat img;
    int color[111111];
    int main()
    {
        VideoCapture video(0);
        if (!video.isOpened())
        {
            return -1;
        }
        Mat img;
        Mat img1, img2, img3;
        Mat grayimg1, grayimg2, grayimg3;
        Mat binaryimg;
        video >> img;
        cvtColor(img, grayimg1, CV_BGR2GRAY);
        while (1)
        {
            video >> img;
    
            
            cvtColor(img, grayimg2, CV_BGR2GRAY);
            absdiff(grayimg2, grayimg1, grayimg3);
            medianBlur(binaryimg, binaryimg, 3);
            threshold(grayimg3, binaryimg, 40, 250, CV_THRESH_BINARY_INV);
            
            imshow("gray", grayimg3);
            imshow("binary", binaryimg);
            //----------------------------------------------
            int nRow = binaryimg.rows;
            int nCol = binaryimg.cols;
            //imshow("img", binaryimg);
            memset(color, 0, sizeof(color));
            for (int i = 0; i < nRow; i++)
            {
                uchar *data = binaryimg.ptr<uchar>(i);
                for (int j = 0; j < nCol; j++)
                {
                    if (*data == 0)
                        color[j]++;
                    *data++;
                }
            }
            
            int high = 450;
            Mat histimg(high, nCol, CV_8UC3);
    
            
            for (int j = 0; j < nCol; j += 2)
            {
                if (color[j] < 260)
                    color[j] = 0;
                //else
                    //color[j] = 400;
                line(histimg, Point(j, high - color[j]), Point(j, high), Scalar(0, 0, 250), 3);
            }
    
            
            for (int j = 0; j<nCol; j++)
            {
                
            }
            imshow("Hist", histimg);
            //--------------------------------------------------------
            if(waitKey(40) > 0)
            {
                break;
            }
        }
        waitKey(100);
        return 0;
    }
  • 相关阅读:
    在阿里云centos7.6上部署vue.js2.6前端应用
    gRPC
    Docker
    ES6、ES7、ES8、ES9、ES10
    HTTPS工作原理 HTTP协议数据结构分析 HTTP和HTTPS协议的不同之处
    SpringBean的工作原理
    Nginx负载均衡高可用---架构
    集群的负载策略
    redis 和 memcached的区别
    Django的基础教程
  • 原文地址:https://www.cnblogs.com/mypsq/p/5054326.html
Copyright © 2011-2022 走看看