Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- https://docs.opencv.org/3.0-beta/modules/videoio/doc/reading_and_writing_video.html
- */
- #include "stdafx.h"
- /*
- https://docs.opencv.org/4.0.0/dd/de7/group__videoio.html
- */
- #include <opencv2/opencv.hpp>
- #include <iostream>
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/imgproc/imgproc.hpp"
- #include <time.h>
- using namespace cv;
- using namespace std;
- double alpha; /**< Simple contrast control */
- int beta; /**< Simple brightness control */
- Mat3b getMean(const vector<Mat3b>& images);
- int main()
- {
- VideoCapture cap(0);
- if (!cap.isOpened()) {
- return -1;
- }
- Size videoSize = Size((int)cap.get(CAP_PROP_FRAME_WIDTH), (int)cap.get(CAP_PROP_FRAME_HEIGHT));
- namedWindow("Recording", WINDOW_NORMAL);
- time_t ori;
- ori = time(NULL);
- Mat mean_10sec;
- Mat diffFrame;
- Mat blurFrame;
- Mat threFrame;
- vector<Mat3b> images;
- while (true) {
- time_t cur;
- cur = time(NULL);
- Mat frame;
- cap >> frame;
- int key = waitKey(1);
- if (!frame.empty()) {
- images.push_back(frame);
- cout << "size: " << images.size() << endl;
- if (cur - ori == 1) {
- Mat3b meanImage_10sec = getMean(images);
- mean_10sec = meanImage_10sec;
- imshow("10sec mean", mean_10sec);
- }
- if (cur - ori > 1) {
- //absdiff(frame, mean_10sec, diffFrame);
- diffFrame = mean_10sec - frame;
- imshow("Diff", diffFrame);
- medianBlur(diffFrame, blurFrame, 5);
- imshow("Blur", blurFrame);
- cvtColor(blurFrame, blurFrame, COLOR_BGR2GRAY);
- threshold(blurFrame, threFrame, 150, 255, THRESH_OTSU);
- imshow("thre", threFrame);
- }
- if (key == 27) {
- cout << "close" << endl;
- break;
- }
- imshow("Recording", frame);
- }
- }
- return 0;
- }
- Mat3b getMean(const vector<Mat3b>& images)
- {
- if (images.empty()) return Mat3b();
- // Create a 0 initialized image to use as accumulator
- Mat m(images[0].rows, images[0].cols, CV_64FC3);
- m.setTo(Scalar(0, 0, 0, 0));
- // Use a temp image to hold the conversion of each input image to CV_64FC3
- // This will be allocated just the first time, since all your images have
- // the same size.
- Mat temp;
- for (int i = 0; i < images.size(); ++i)
- {
- // Convert the input images to CV_64FC3 ...
- images[i].convertTo(temp, CV_64FC3);
- // ... so you can accumulate
- m += temp;
- }
- // Convert back to CV_8UC3 type, applying the division to get the actual mean
- m.convertTo(m, CV_8U, 1. / images.size());
- return m;
- }
- //y2fkvhk8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement