Skip to content
Snippets Groups Projects
Commit 2120328f authored by Noah Eigenfeld's avatar Noah Eigenfeld
Browse files

Added create new user functionality

parent 0a7cafdd
Branches master
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
#include <string>
#include <fstream>
#include <sstream>
#include <sys/stat.h>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
......@@ -102,6 +103,61 @@ void read_users() {
}
}
void new_user() {
//read imagess to update num_subdirectories
read_images();
string name;
string users_pathname = "./users.txt";
string directory = "./myfaces/";
string new_subdirectory = to_string(num_subdirectories);
int status = mkdir((directory.append(new_subdirectory)).c_str(), 0777);
cout << "Enter the name of the new user:" << endl;
getline(cin, name);
std::ofstream file_output;
file_output.open (users_pathname, std::ofstream::app);
file_output << name << endl;
file_output.close();
cout << "Taking pictures. Hold still..." << endl;
waitKey(1000);
Mat frame;
for (int i = 0; i < 10; i++) {
VideoCapture videoCapture(0);
videoCapture.retrieve(frame);
bool success = videoCapture.read(frame);
if (!success) {
cout << "Could not read from video file" << endl;
} else {
//Get webcam image dimensions
picture_width = frame.cols;
picture_height = frame.rows;
face_x = picture_width/3;
face_y = picture_height/5;
face_width = picture_width/3;
face_height = 3 * face_y;
Rect face_dims(face_x, face_y, face_width, face_height);
face = frame(face_dims);
string image_pathname = "./myfaces/" + to_string(num_subdirectories) + "/" + to_string(i) + ".png";
bool maybe = imwrite(image_pathname, face);
cout << "Saving image, success: " << maybe << endl;
waitKey(100);
}
}
cout << "Pictures taken! User added." << endl;
}
int main() {
//Starting the video
VideoCapture videoCapture(0);
......@@ -144,7 +200,8 @@ int main() {
//show some instructional text
Mat frame_with_text = frame.clone();
putText(frame_with_text, "Press Spacebar to take a picture", Point2f(110,100), FONT_HERSHEY_SIMPLEX, 2.0, Scalar(255,0,0,0), 3);
putText(frame_with_text, "Press Spacebar to take a picture", Point2f(110,50), FONT_HERSHEY_SIMPLEX, 2.0, Scalar(255,0,0,0), 3);
putText(frame_with_text, "Press 'n' to enter a new user", Point2f(140,130), FONT_HERSHEY_SIMPLEX, 2.0, Scalar(255,0,0,0), 3);
putText(frame_with_text, "Press ESC to close the application", Point2f(90,700), FONT_HERSHEY_SIMPLEX, 2.0, Scalar(0,0,255,255), 3);
//Draw a rectangle where the picture will be taken
......@@ -166,6 +223,10 @@ int main() {
cout << "ESC pressed. Program closing..." << endl;
break;
}
else if (key == 'n') { //n pressed: create new user
new_user();
}
else if (key == ' ') { //spacebar pressed: take a picture
picture = frame;
......
myfaces/0/0.png 100644 → 100755
File mode changed from 100644 to 100755
myfaces/0/1.png 100644 → 100755
File mode changed from 100644 to 100755
myfaces/0/2.png 100644 → 100755
File mode changed from 100644 to 100755
myfaces/0/3.png 100644 → 100755
File mode changed from 100644 to 100755
myfaces/0/4.png 100644 → 100755
File mode changed from 100644 to 100755
myfaces/0/5.png 100644 → 100755
File mode changed from 100644 to 100755
myfaces/0/6.png 100644 → 100755
File mode changed from 100644 to 100755
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