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;
    }
  • 相关阅读:
    Dingo/api 学习笔记
    Composer install 报错
    bootstrap4 调整元素之间距离
    css font-family常用的黑体宋体等字体中英文对照
    mac 开关机
    lodash.memoize
    Evevt Loop 事件循环
    mac 安装 XX-Net-3.12.11
    mac端口占用
    npm 安装/删除/发布/更新/撤销 发布包
  • 原文地址:https://www.cnblogs.com/mypsq/p/5054326.html
Copyright © 2011-2022 走看看