Skip to content

Commit

Permalink
Revert "feat: connecting the face detection and recognition "
Browse files Browse the repository at this point in the history
This reverts commit 358a203.
  • Loading branch information
KamelMoohamed committed May 17, 2023
1 parent 358a203 commit d734f8f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
6 changes: 3 additions & 3 deletions CV/faces_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void faces_detection::detect_faces(cv::Mat& inputImage, cv::Mat& outputImage, bo
{
// Load the cascade classifier
cv::CascadeClassifier face_cascade;
face_cascade.load("C:\\Users\\kamel\\OneDrive\\Documents\\GitKraken\\Cv-Toolbox\\models\\haarcascade_frontalface_default.xml");
face_cascade.load("D:\\Projects\\CV\\Cv-Toolbox\\models\\haarcascade_frontalface_default.xml");

cv::Mat gray;
cvtColor(inputImage, gray, cv::COLOR_BGR2GRAY);
Expand All @@ -32,8 +32,8 @@ void faces_detection::detect_faces(cv::Mat& inputImage, cv::Mat& outputImage, bo


void faces_detection::cropImage(cv::Mat inputImage, cv::Mat& outputImage, cv::Rect faceRect) {
int targetWidth = 100;
int targetHeight = 100;
int targetWidth = 109;
int targetHeight = 109;

int widthDifference = targetWidth - faceRect.width;
int heightDifference = targetHeight - faceRect.height;
Expand Down
41 changes: 15 additions & 26 deletions pages/page11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,17 @@ void page11::on_inputImageLabel_clicked()
{
fileName = QFileDialog::getOpenFileName(this, "Open Image", "", "Image Files (*.png *.jpg *.bmp *.jpeg)");
if (!fileName.isEmpty()) {
// read colored image
img = cv::imread(fileName.toStdString());
QImage qimage(img.data, img.cols, img.rows, QImage::Format_BGR888);
image = QPixmap::fromImage(qimage);
int w = ui->inputImageLabel->width();
int h = ui->inputImageLabel->height();
ui->inputImageLabel->setPixmap(image.scaled(w,h,Qt::KeepAspectRatio));
ui->inputImageLabel->setScaledContents(true);
if(trained)
ui->predict_btn->setEnabled(true);

if(ui->optionsBox->currentIndex() == 0){
QImage qimage(img.data, img.cols, img.rows, QImage::Format_BGR888);
image = QPixmap::fromImage(qimage);

ui->inputImageLabel->setPixmap(image.scaled(w,h,Qt::KeepAspectRatio));
ui->inputImageLabel->setScaledContents(true);
if(trained)
ui->predict_btn->setEnabled(true);
}else{
cv::Mat input(img.size(), img.type());
faces_detection::detect_faces(img, input, false);
QImage qInputImage(input.data, input.cols, input.rows, QImage::Format_BGR888);
QPixmap Input = QPixmap::fromImage(qInputImage);
ui->inputImageLabel->setPixmap(Input.scaled(w, h,Qt::KeepAspectRatio));
}
ui->predict_btn->setEnabled(true);
}
}

Expand Down Expand Up @@ -140,6 +131,8 @@ void page11::on_select_folder_btn_clicked()
ui->train_pca_btn->setEnabled(true);
ui->path_label->setText(folderPath);
}


}


Expand All @@ -165,25 +158,18 @@ void page11::on_train_pca_btn_clicked()

void page11::on_predict_btn_clicked()
{
if(!fileName.isEmpty()){
// Showing the output image label
cv::Mat output(img.size(), img.type());
faces_detection::detect_faces(img, output, true);

// Making Recognition
cv::Mat img_gray;
cv::cvtColor(output, img_gray, cv::IMREAD_GRAYSCALE);

if(!fileName.isEmpty()){
cv::Mat img_gray=cv::imread(fileName.toStdString(),cv::IMREAD_GRAYSCALE);
std::string label=fr->predictPerson(img_gray);
label=personToPathMapper[label];
cv::Mat predictedImg = cv::imread(label,cv::IMREAD_GRAYSCALE);

QImage qimage(predictedImg.data, predictedImg.cols, predictedImg.rows, QImage::Format_Grayscale8);
QPixmap pred_image = QPixmap::fromImage(qimage);
int w = ui->outputImageLabel->width();
int h = ui->outputImageLabel->height();
ui->outputImageLabel->setPixmap(pred_image.scaled(w,h,Qt::KeepAspectRatio));
ui->outputImageLabel->setScaledContents(true);

}
}

Expand Down Expand Up @@ -222,6 +208,8 @@ void page11::on_testUploadBtn_clicked()
fr->generateROC(predictions,testLabels,ROC);
ui->comboBox_2->setEnabled(true);
}


}


Expand All @@ -246,5 +234,6 @@ void page11::on_comboBox_2_currentIndexChanged(int index)
plotter::plotAllROC(ui->widget, ROC, fr->labelToPersonMapper);
}
}
// fr->personToLabelmapper
}

0 comments on commit d734f8f

Please sign in to comment.