Skip to content
Snippets Groups Projects
FacialRec.cpp 1.24 KiB
Newer Older
johni's avatar
johni committed
//This is our project
johni's avatar
johni committed

#include <iostream>

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace std;
using namespace cv;

Mat picture;
char key;

johni's avatar
johni committed
class FacialRec {

};

int main() {
	//Starting the video
	VideoCapture videoCapture(0);

	if (!videoCapture.isOpened()) {
		cout << "Unable to open video file." << endl;
		return 1;
	}

	namedWindow("Webcam", CV_WINDOW_AUTOSIZE);

	while(true) {
		Mat frame;
		videoCapture.retrieve(frame);
		bool success = videoCapture.read(frame);
		if (!success) {
			cout << "Could not read from video file" << endl;
			return 1;
		}

		imshow("Webcam", frame);
		key = waitKey(30);

		if (key == 27) { //escape key pressed: stop program
			cout << "ESC pressed. Program closing..." << endl;
			break;
Noah Eigenfeld's avatar
Noah Eigenfeld committed
		else if (key == ' ') { //spacebar pressed: take a picture
			picture = frame;
			key = -1;

			while (true) {
				imshow("Webcam", picture);
johni's avatar
johni committed

				key = waitKey(30);
johni's avatar
johni committed

				if (key == 27 || key == 32) {
					cout << "ESC or SPACE pressed. Returning to video..." << endl;
					break;
Noah Eigenfeld's avatar
Noah Eigenfeld committed
				} else if (key == 115) {
					bool maybe = imwrite("./testimage.jpg", picture);
					cout << "s was pressed. saving image " << maybe << endl;
johni's avatar
johni committed

johni's avatar
johni committed
}