How to realize Intelligent Video Surveillance by OpenCV
This article is about how OpenCV can achieve intelligent video surveillance. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
It was troublesome to find a complete implementation code on the Internet when I was doing the design before. After I finished it, I would like to share it with you
Because the code is relatively simple, there is no separate code written in different files, there is a need to integrate their own ha
Working with environments Visual Studio 2010 and OpenCV 2.4.9
#include #include #include using namespace std;using namespace cv; int videoplay();void on_Trackbar (int ,void*);char* str_gettime();int bSums(Mat src); char g_str[17];int g_nNum = 0;//Image name int g_nDelay = 0;int g_npic = 0;Mat g_filpdstMat;int g_pointnum = 1000;//Set pixel threshold to generate image int g_pixel = 0;//Pixels int main(){ VideoCapture (0); //Video output VideoWriter CvVideoWriter* outavi = NULL; //VideoWriter outavi; //outavi.open ("sre.avi",-1, 5. 0, Size(640, 480), true); outavi = cvCreateVideoWriter("Video.avi", -1, 5.0, cvSize(640, 480), 1); namedWindow("Camera",WINDOW_AUTOSIZE); namedWindow("Move Trajectory," WINDOW_AUTOSIZE); IplImage * cpframe = NULL; Mat tempframe, currentframe, preframe, cpframe; Mat frame,jpg; int framenum = 0; //Read a frame while (1) { if(! capture.isOpened()) { cout frame;//read camera and pass each frame to frame.copyTo(cpframe);//assign frame to cpframe without affecting frame tempframe = frame;//assign frame to tempframe without affecting frame flip (tempframe,g_filpdstMat,1);//Flip the image horizontally pcpframe = &IplImage(cpframe);//To free the window, convert Mat to IplImage using//cpframe=cvarrToMat (pcpframe); //ipl conversion matrix pBinary = &IplImage(Img) //7 frames capture once input video, frequent capture does not work if (framenum % 7 == 0) { //Video Write cvWriteFrame (outtavi, pcpframe); } //Determine the number of frames. If it is the first frame, use this frame as the comparison frame.//If it is greater than or equal to the second frame, perform frame difference processing framenum++; if (framenum == 1) { cvtColor (g_filpdstMat, preframe, CV_BGR2GRAY); } if (framenum >= 2) { cvtColor (g_filpdstMat, currentframe, CV_BGR2GRAY); //grayscale absdiff (currentframe,preframe,currentframe);//frame difference threshold (currentframe, currentframe, 30, 255.0, CV_THRESH_BINARY);(currentframe, currentframe,Mat());//corrosion dilute (currentframe, currentframe,Mat());//expand g_pixel = bSums(currentframe);//call bSums function to calculate white pixel and assign it to g_pixel //output the current pixel value after a small delay to prevent the data from being too fast to see g_nDelay++; if(g_nDelay > 5) { cout