#include"iostream"#include"Queue"#include"Windows.h"#include<opencv2/ml/ml.hpp>#include"opencv2/opencv.hpp"#include"Windows.h"#include"opencv2/core/core.hpp"#include"opencv2/highgui/highgui.hpp"#include"opencv2/imgproc/imgproc.hpp"#include"opencv2/objdetect/objdetect.hpp"#include"opencv2/features2d/features2d.hpp"#include"opencv2/calib3d/calib3d.hpp"#include"opencv2/ml.hpp"#include"opencv/cv.h"#include"opencv/ml.h"#include"opencv/highgui.h"#include"opencv/cvaux.h"#include"opencv/cvwimage.h"#include"opencv/cxcore.h"#include"opencv/cxmisc.h"#include"opencv2/cvconfig.h"#defineMAX 30using namespaceCV;using namespacestd;intcolor[10000];int main (int argc, char *argv[]) {
Cv::mat frame;
Cv::mat back;
Cv::mat Fore;
Cv::videocapture cap ("c:\\c_c++ EX8 code\\video\\myvideo.wmv");
Cv::videocapture Cap (0);
CV::P tr<backgroundsubtractormog2> bg = createBackgroundSubtractorMOG2 ();
Bg->setnmixtures (3);
Bg.bshadowdetection = false;
STD::VECTOR<STD::VECTOR<CV::P oint> > Contours;
Cv::namedwindow ("Frame");
Cv::namedwindow ("Background");
while (1)
{
Cap >> frame;
Bg.operator () (frame, fore);
Bg->apply (frame, fore,0.01);
Cv::erode (fore, Fore, cv::mat ());
CV::d ilate (Fore, Fore, cv::mat ());
Bg->getbackgroundimage (back);
Cv::findcontours (fore, contours, cv_retr_external,cv_chain_approx_none);
CV::d rawcontours (frame, contours,-1, cv::scalar (0, 0, 255), 2);
Threshold (fore, fore, CV_THRESH_BINARY_INV);
//---------------------------------------------------------------
int nrow = fore.rows;
int ncol = Fore.cols;
Imshow ("img", binaryimg);
memset (color, 0, sizeof (color));
for (int i = 0; i < nrow; i++)
{
Uchar *data = fore.ptr<uchar> (i);
for (int j = 0; J < Ncol; J + +)
{
if (*data = = 0)
color[j]++;
*data++;
}
}
int high = 300;
Mat histimg (High, Ncol, CV_8UC3);
for (int j = 0; J < ncol; J + = 2)
{
Line (Histimg, point (J, High-color[j]), point (J, High), Scalar (0, 0, 250), 1);
}
Imshow ("Hist", histimg);
//---------------------------------------------------------------
//---------------------------------------------------------------
Cv::imshow ("Foreground", fore);
Cv::imshow ("Frame", frame);
Cv::imshow ("Background", back);
if (Cv::waitkey (>=) 0)
Break
}
return 0;
}
OPENCV Statistics binary graph black and white pixel number