• 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;
    }
  • 相关阅读:
    Python函数式编程(一):高级函数
    Python高级特性:列表生成式
    Python高级特性:迭代
    Python高级特性:切片
    Python学习笔记
    关于相机拍照获取图片onActivityResult返回data 为null的问题
    191019
    状语和状语从句
    191018
    191017
  • 原文地址:https://www.cnblogs.com/mypsq/p/5054326.html
Copyright © 2020-2023  润新知