Skip to content
Snippets Groups Projects
Commit 1a3a3a14 authored by jhaut's avatar jhaut
Browse files

Merge branch 'take-a-picture-from-a-webcam' into 'master'

Added ability to take a picture from a webcam

Right now I just have a main method in FacialRec that is doing this.

Current functionality:
* When run, starts a video feed from the webcam
* If user presses spacebar, takes a picture and displays it
  * If user presses ESC or spacebar, return to video feed
* If user presses ESC, exit application

We might want to divide some of this into classes. Let me know what you think.

See merge request !1
parents 8fec6f09 cddb9bdd
No related branches found
No related tags found
No related merge requests found
cmake_minimum_required(VERSION 2.8)
project(FaceRecognition)
find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(FaceRecognition FacialRec.cpp)
target_link_libraries(FaceRecognition ${OpenCV_LIBS})
//This is our project //This is our project
//Change made by Jon //Change made by Jon
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
using namespace cv;
Mat picture;
char key;
class FacialRec { 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;
} else if (key == ' ') { //spacebar pressed: take a picture
picture = frame;
key = -1;
while (true) {
imshow("Webcam", picture);
key = waitKey(30);
if (key == 27 || key == 32) {
cout << "ESC or SPACE pressed. Returning to video..." << endl;
break;
}
}
}
}
return 0;
} }
Current functionality:
-When run, starts a video feed from the webcam
-If user presses spacebar, takes a picture and displays it
--If user presses ESC or spacebar, return to video feed
-If user presses ESC, exit application
Compiling the project from command line:
(FOR MAC)
>>cd <path/to/application/folder>
>>/Applications/CMake.app/Contents/bin/cmake .
>>make
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment