Skip to content

Commit

Permalink
Restructred dir
Browse files Browse the repository at this point in the history
  • Loading branch information
sri0606 committed Dec 27, 2023
1 parent 0d1b593 commit d3bbee5
Show file tree
Hide file tree
Showing 43 changed files with 651 additions and 580 deletions.
99 changes: 8 additions & 91 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,95 +1,12 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required (VERSION 3.5)

project(FaceSpyder VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Multimedia MultimediaWidgets)

set(OpenCV_DIR "C:/Program Files/opencv/build")

find_package(OpenCV CONFIG REQUIRED)

set(PROJECT_SOURCES
main.cpp
)
set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/resources/app_icon.rc")

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(FaceSpyder
MANUAL_FINALIZATION
${PROJECT_SOURCES}
${app_icon_resource_windows}
facerecognitionview.h facerecognitionview.cpp
facedetectionview.h facedetectionview.cpp
observer.h observer.cpp
facerecognition.h facerecognition.cpp
pch.h
item.h item.cpp
image.h image.cpp
video.h video.cpp
imagematching.h imagematching.cpp
itemdetectedview.h itemdetectedview.cpp
spyderwindow.h spyderwindow.cpp
menubutton.h menubutton.cpp
videoplayer.h videoplayer.cpp
facedetectionworker.h facedetectionworker.cpp
loadingwindow.h loadingwindow.cpp
mainwindow.h mainwindow.cpp
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET FaceSpyder APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(FaceSpyder SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(FaceSpyder
${PROJECT_SOURCES}
)
endif()
# Enable Hot Reload for MSVC compilers if supported.
if (POLICY CMP0141)
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()

target_link_libraries(FaceSpyder PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Multimedia Qt${QT_VERSION_MAJOR}::MultimediaWidgets ${OpenCV_LIBS})
project ("FaceSpyder")

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.FaceSpyder)
endif()
set_target_properties(FaceSpyder PROPERTIES
${BUNDLE_ID_OPTION}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_precompile_headers(${PROJECT_NAME} PRIVATE pch.h)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources/
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/resources/)


include(GNUInstallDirs)
install(TARGETS FaceSpyder
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(FaceSpyder)
endif()
# Include sub-projects.
add_subdirectory ("FaceSpyder")
95 changes: 95 additions & 0 deletions FaceSpyder/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
cmake_minimum_required(VERSION 3.5)

project(FaceSpyder VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Multimedia MultimediaWidgets)

set(OpenCV_DIR "C:/Program Files/opencv/build")

find_package(OpenCV CONFIG REQUIRED)

set(PROJECT_SOURCES
main.cpp
)
set(app_icon_resource_windows "${CMAKE_CURRENT_SOURCE_DIR}/resources/app_icon.rc")

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(FaceSpyder
MANUAL_FINALIZATION
${PROJECT_SOURCES}
${app_icon_resource_windows}
facerecognitionview.h facerecognitionview.cpp
facedetectionview.h facedetectionview.cpp
observer.h observer.cpp
facerecognition.h facerecognition.cpp
pch.h
item.h item.cpp
image.h image.cpp
video.h video.cpp
imagematching.h imagematching.cpp
itemdetectedview.h itemdetectedview.cpp
spyderwindow.h spyderwindow.cpp
menubutton.h menubutton.cpp
videoplayer.h videoplayer.cpp
facedetectionworker.h facedetectionworker.cpp
loadingwindow.h loadingwindow.cpp
mainwindow.h mainwindow.cpp
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET FaceSpyder APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(FaceSpyder SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(FaceSpyder
${PROJECT_SOURCES}
)
endif()
endif()

target_link_libraries(FaceSpyder PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Multimedia Qt${QT_VERSION_MAJOR}::MultimediaWidgets ${OpenCV_LIBS})

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.FaceSpyder)
endif()
set_target_properties(FaceSpyder PROPERTIES
${BUNDLE_ID_OPTION}
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_precompile_headers(${PROJECT_NAME} PRIVATE pch.h)

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources/
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/resources/)


include(GNUInstallDirs)
install(TARGETS FaceSpyder
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(FaceSpyder)
endif()
10 changes: 2 additions & 8 deletions authwindow.cpp → FaceSpyder/authwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "pch.h"
#include "authwindow.h"
#include "ui_authwindow.h"
#include <QLayout>
#include <QMessageBox>
#include "pch.h"
#include "ui_authwindow.h"

AuthWindow::AuthWindow(QWidget *parent)
: QWidget(parent)
Expand All @@ -24,10 +24,8 @@ void AuthWindow::on_loginButton_clicked()

// just emit the loggedIn signal
emit loggedIn(mUsername);

}


void AuthWindow::on_signupButton_clicked()
{
//if (mUsername and mPassword{
Expand All @@ -36,23 +34,19 @@ void AuthWindow::on_signupButton_clicked()
emit signedUp(mUsername);
}


void AuthWindow::on_skipButton_clicked()
{
QMessageBox::information(this, "Skipped", "Skipping login/signup");
// Emit a signal to indicate skipping
emit loggedIn("Guest");
}


void AuthWindow::on_usernameLineEdit_returnPressed()
{
mUsername = ui->usernameLineEdit->text();
}


void AuthWindow::on_passwordLineEdit_returnPressed()
{
mPassword = ui->passwordLineEdit->text();
}

File renamed without changes.
File renamed without changes.
54 changes: 33 additions & 21 deletions facedetectionview.cpp → FaceSpyder/facedetectionview.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#include "pch.h"
#include "facedetectionview.h"
#include "imagematching.h"
#include <QFileInfo>
#include <QDir>
#include <QFileInfo>
#include <QMessageBox>
#include <QPixmap>
#include "imagematching.h"
#include "pch.h"

/**
* Constructor
* @param parent
*
*/
FaceDetectionView::FaceDetectionView(QWidget *parent)
: QWidget{parent},Observer{parent}
: QWidget{parent}
, Observer{parent}
{
setAttribute(Qt::WA_StyledBackground);

Expand All @@ -36,13 +37,16 @@ void FaceDetectionView::UpdateObserver()
void FaceDetectionView::addItemDetectedView(cv::Mat faceImage)
{
auto faceBitmap = MatToQPixmap(faceImage);
ItemDetectedView* viewWidget = new ItemDetectedView(this, faceBitmap);
connect(viewWidget, &ItemDetectedView::removeRequested, this, &FaceDetectionView::RemoveDetectedView);
ItemDetectedView *viewWidget = new ItemDetectedView(this, faceBitmap);
connect(viewWidget,
&ItemDetectedView::removeRequested,
this,
&FaceDetectionView::RemoveDetectedView);

//add to grid layout
int minImageWidth = 235;
int minImageHeight = 260;
int totalColumns=3;
int totalColumns = 3;

QPixmap pixmap = viewWidget->GetPixmap();
// Set a fixed size for each widget
Expand All @@ -51,16 +55,17 @@ void FaceDetectionView::addItemDetectedView(cv::Mat faceImage)
viewWidget->SetPixmap(pixmap.scaled(viewWidget->size(), Qt::KeepAspectRatio));
viewWidget->setStyleSheet("color:white;background-color: rgb(16, 7, 20)");
viewWidget->setAttribute(Qt::WA_StyledBackground);
mGridLayout->addWidget(viewWidget,mViewCount/totalColumns,mViewCount%totalColumns);
mGridLayout->addWidget(viewWidget, mViewCount / totalColumns, mViewCount % totalColumns);
mViewCount++;
}

/**
* @brief IsFacesDetected: checks if any faces detected yet
* @return
*/
bool FaceDetectionView::IsFacesDetected(){
return mViewCount!=0;
bool FaceDetectionView::IsFacesDetected()
{
return mViewCount != 0;
}

/**
Expand All @@ -77,14 +82,15 @@ void FaceDetectionView::cleanDetectedViews()
// Check if the item is a widget
if (QWidget *widget = item->widget()) {
// Cast it to your custom widget type
ItemDetectedView *detectedView = qobject_cast<ItemDetectedView*>(widget);
ItemDetectedView *detectedView = qobject_cast<ItemDetectedView *>(widget);

// Check if the cast was successful
if (detectedView) {
if (CompareImagesByHistogram(detectedView->GetPixmap(), faceBitmap) ){//|| CompareImagesByFeatureMatching(*detectedFace, faceBitmap)) {
if (CompareImagesByHistogram(
detectedView->GetPixmap(),
faceBitmap)) { //|| CompareImagesByFeatureMatching(*detectedFace, faceBitmap)) {
return;
}
else {
} else {
continue;
}
}
Expand All @@ -105,10 +111,11 @@ void FaceDetectionView::paintEvent(QPaintEvent *event)
/**
* Save detected faces
*/
void FaceDetectionView::SaveDetectedFaces(const QString& folderPath) {
void FaceDetectionView::SaveDetectedFaces(const QString &folderPath)
{
QImage image;
// Create a subfolder in the selected folder
QString subfolderName = QFileInfo(mFaceRecognition->GetItemPath()).baseName()+"_facespyder";
QString subfolderName = QFileInfo(mFaceRecognition->GetItemPath()).baseName() + "_facespyder";
QString subfolderPath = folderPath + QDir::separator() + subfolderName;

if (!QDir(subfolderPath).exists() && !QDir().mkpath(subfolderPath)) {
Expand All @@ -121,7 +128,7 @@ void FaceDetectionView::SaveDetectedFaces(const QString& folderPath) {
// Check if the item is a widget
if (QWidget *widget = item->widget()) {
// Cast it to your custom widget type
ItemDetectedView *detectedView = qobject_cast<ItemDetectedView*>(widget);
ItemDetectedView *detectedView = qobject_cast<ItemDetectedView *>(widget);

// Check if the cast was successful
if (detectedView) {
Expand All @@ -133,7 +140,10 @@ void FaceDetectionView::SaveDetectedFaces(const QString& folderPath) {

if (!image.save(filePath, "PNG")) {
// Handle the error, e.g., show an error message
QMessageBox::critical(nullptr, "Error", "Failed to save image.", QMessageBox::Ok);
QMessageBox::critical(nullptr,
"Error",
"Failed to save image.",
QMessageBox::Ok);
return;
}
}
Expand All @@ -143,10 +153,11 @@ void FaceDetectionView::SaveDetectedFaces(const QString& folderPath) {
QMessageBox::information(nullptr, "Success", "Images saved successfully.", QMessageBox::Ok);
}

void FaceDetectionView::Clear() {
void FaceDetectionView::Clear()
{
if (mGridLayout != nullptr) {
// Remove all items in the layout
QLayoutItem* item;
QLayoutItem *item;
while ((item = mGridLayout->takeAt(0)) != nullptr) {
if (item->widget()) {
// Delete the widget
Expand All @@ -168,7 +179,8 @@ void FaceDetectionView::Clear() {
UpdateObserver();
}

void FaceDetectionView::RemoveDetectedView(ItemDetectedView* view) {
void FaceDetectionView::RemoveDetectedView(ItemDetectedView *view)
{
if (view) {
mGridLayout->removeWidget(view);
view->deleteLater();
Expand Down
Loading

0 comments on commit d3bbee5

Please sign in to comment.