<commit_before>#include "stdafx.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
#include <opencv2/opencv.hpp>
#include "Utils.hpp"

using namespace cv;
using namespace std;


int main(int argc, char** argv) {
	// open the webcam
	VideoCapture cam(0);
	if (!cam.isOpened()) {
		cerr << "Camera failed to open" << endl;
		return -1;
	}

	// get dims of video capture
	int camHeight = static_cast<int>(cam.get(CV_CAP_PROP_FRAME_HEIGHT));
	int camWidth = static_cast<int>(cam.get(CV_CAP_PROP_FRAME_WIDTH));

	cout << camHeight << "x" << camWidth << endl;

	// create window that shows the unchanged webcam output
	namedWindow("UnchangedOutput", CV_WINDOW_AUTOSIZE);
	//create window that shows skin detection
	namedWindow("SkinDetection", WINDOW_AUTOSIZE);
	// create window that show pixel diffs per frame
	//namedWindow("FrameDiff", WINDOW_AUTOSIZE);
	// create window that show motion energy history
	//namedWindow("MotionHistory", WINDOW_AUTOSIZE);

#if 0
	// initialize motion history vector
	vector<Mat> motionHist;
	Mat fMH1, fMH2, fMH3;
	fMH1 = Mat::zeros(camHeight, camWidth, CV_8UC1);
	fMH2 = fMH1.clone();
	fMH3 = fMH1.clone();
	motionHist.push_back(fMH1);
	motionHist.push_back(fMH2);
	motionHist.push_back(fMH3);
#endif

	// read a single frame now to have a frame to compare
	Mat prevFrame;
	if (!cam.read(prevFrame)) {
		cerr << "Cannot read a frame from video stream" << endl;
		return -1;
	}

	// initialize background subtraction algorithm
	BackgroundSubtractorMOG2 bgsub;
	bgsub.set("nmixtures", 3);
	bgsub.set("detectShadows", false);

	// loop frame by frame
	while (1) {
		Mat curFrame;
		if (!cam.read(curFrame)) {
			cerr << "Cannot read a frame from video stream" << endl;
			break;
		}
		// create a zero array of same size as video capture
		Mat dstFrame = Mat::zeros(curFrame.rows, curFrame.cols, CV_8UC1); 

		// display this frame without any changes
		//imshow("UnchangedOutput", curFrame);

		// display video with skin tones colored white
		//mySkinDetect(curFrame, dstFrame);
		imshow("UnchangedOutput", curFrame);
		//Mat hull = drawHull(dstFrame);

		bgsub.operator() (curFrame, dstFrame);

		erode(dstFrame, dstFrame, Mat());
		dilate(dstFrame, dstFrame, Mat());

		imshow("SkinDetection", dstFrame);

		// highlights pixels in this frame that are different from last frame
		//myFrameDifferencing(prevFrame, curFrame, dstFrame);
		//imshow("FrameDiff", dstFrame);

		/*
		// delete the oldest frame and add the newest frame
		motionHist.erase(motionHist.begin());<commit_msg>commit<commit_after>#include "stdafx.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
#include <opencv2/opencv.hpp>
#include "Utils.hpp"

using namespace cv;
using namespace std;


int main(int argc, char** argv) {
	// open the webcam
	VideoCapture cam(0);
	if (!cam.isOpened()) {
		cerr << "Camera failed to open" << endl;
		return -1;
	}

	// get dims of video capture
	int camHeight = static_cast<int>(cam.get(CV_CAP_PROP_FRAME_HEIGHT));
	int camWidth = static_cast<int>(cam.get(CV_CAP_PROP_FRAME_WIDTH));

	cout << camHeight << "x" << camWidth << endl;

	// create window that shows the unchanged webcam output
	namedWindow("UnchangedOutput", CV_WINDOW_AUTOSIZE);
	//create window that shows skin detection
	namedWindow("SkinDetection", WINDOW_AUTOSIZE);
	// create window that show pixel diffs per frame
	//namedWindow("FrameDiff", WINDOW_AUTOSIZE);
	// create window that show motion energy history
	//namedWindow("MotionHistory", WINDOW_AUTOSIZE);

#if 0
	// initialize motion history vector
	vector<Mat> motionHist;
	Mat fMH1, fMH2, fMH3;
	fMH1 = Mat::zeros(camHeight, camWidth, CV_8UC1);
	fMH2 = fMH1.clone();
	fMH3 = fMH1.clone();
	motionHist.push_back(fMH1);
	motionHist.push_back(fMH2);
	motionHist.push_back(fMH3);
#endif

	// read a single frame now to have a frame to compare
	Mat prevFrame;
	if (!cam.read(prevFrame)) {
		cerr << "Cannot read a frame from video stream" << endl;
		return -1;
	}

	// initialize background subtraction algorithm
	BackgroundSubtractorMOG2 bgsub;
	bgsub.set("nmixtures", 3);
	bgsub.set("detectShadows", false);

	// loop frame by frame
	while (1) {
		Mat curFrame;
		if (!cam.read(curFrame)) {
			cerr << "Cannot read a frame from video stream" << endl;
			break;
		}
		// create a zero array of same size as video capture
		Mat dstFrame = Mat::zeros(curFrame.rows, curFrame.cols, CV_8UC1); 
		Mat newFrame = Mat::zeros(curFrame.rows, curFrame.cols, CV_8UC1);
		// display this frame without any changes
		//imshow("UnchangedOutput", curFrame);

		// display video with skin tones colored white
		//mySkinDetect(curFrame, dstFrame);
		imshow("UnchangedOutput", curFrame);
		//Mat hull = drawHull(dstFrame);

		// highlights pixels in this frame that are different from last frame
		myFrameDifferencing(prevFrame, curFrame, dstFrame);
		imshow("FrameDiff", dstFrame);
		bgsub.operator() (dstFrame, newFrame);
		imshow("Background Subtractor", newFrame);
		erode(newFrame, newFrame, Mat());
		dilate(newFrame, newFrame, Mat());
		imshow("Erode dilate", newFrame);
		/*
		// delete the oldest frame and add the newest frame
		motionHist.erase(motionHist.begin());
{'fraction_non_alphanumeric': 0.12596302003081664, 'fraction_numerical': 0.010015408320493066, 'mean_word_length': 4.536247334754798, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1915117', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1758, 'n_words': 498}