Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCI HW Assignment 1- Al-ameen Mawji and Bishoy Roufael #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Practical Assignment 1
**Dealine**: 27.09.2021

Please put your name here:
**Name:** .......

**Name: Al-ameen Mawji (Worked with Bishoy Roufael)**
## Problem 1.1
### Calculate Frames-per-Second (FPS) (Points 30)
1. Fork the current repository
Expand Down
50 changes: 50 additions & 0 deletions src/cascade.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

int main()
{
// Load Face cascade (.xml file)
CascadeClassifier face_cascade;
face_cascade.load("haarcascade_frontalface_alt.xml");
if (!face_cascade.load("haarcascade_frontalface_alt.xml"))
{
cerr << "Error Loading XML file" << endl;
return 0;
}

VideoCapture capture(0);
if (!capture.isOpened())
throw "Error when reading file";
namedWindow("window", 1);
for (;;)
{
Mat image;
capture >> image;
if (image.empty())
break;

/*
Detect Faces
*/
std::vector<Rect> faces;
face_cascade.detectMultiScale(image, faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30));

for (int i = 0; i < faces.size(); i++)
{
Point center(faces[i].x + faces[i].width * 0.5, faces[i].y + faces[i].height * 0.5);
ellipse(image, center, Size(faces[i].width * 0.5, faces[i].height * 0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
}

imshow("Detected Face using cascade", image);
waitKey(1);
}

return 0;
}
42 changes: 39 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
#include "types.h"
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <numeric>

using namespace cv;


template <typename T>
T average(std::vector<T> const& v) {
if (v.empty()) {
return 0;
}
return std::accumulate(v.begin(), v.end(), 0.0) / v.size();
}

int main() {
VideoCapture camera;
if (!camera.open(0)) {
printf("Can't find a camera\n");
return 1;
};

// Main loop
Mat img;
for(;;) {
std::vector<long> fpsCont;

long frameCounter = 0;

std::time_t timeBegin = std::time(0);
int tick = 0;

for (;;) {
camera >> img;
imshow("Camera", img);

int key = waitKey(5);

frameCounter++;
fpsCont.push_back(frameCounter);

std::time_t timeNow = std::time(0) - timeBegin;
if (timeNow - tick >= 1)
{
tick+=2;
std::cout << "Average Frames per second: " << average(fpsCont) << std::endl;
frameCounter = 0;
fpsCont.clear();
}


if (key == 27 || key == 'q') break;
}
camera.release();
Expand Down