Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Adding Canny lines to project
Browse files Browse the repository at this point in the history
  • Loading branch information
riigess committed Aug 26, 2023
1 parent f6e0aaf commit 28ff4f5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 29 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Facial-Recognition
A C++ application that can detect faces using cmake as a build system.

## Remodeling
This project is currently being updated to sport more OpenCV features. To use v1.1, please append `--face-detection` when calling the executable.
13 changes: 11 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
#!/bin/zsh
cmake CMakeLists.txt -S src -B build
#!/bin/bash
rm -rf build
mkdir build
cmake CMakeLists.txt -S src -B build
if [ -f build/FaceDetction]; then
build/FaceDetection $1
else
cd build
make
./FaceDetection $1
fi
21 changes: 10 additions & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
cmake_minimum_required(VERSION 3.21)
project(FaceDetection LANGUAGES CXX)

find_package(OpenCV REQUIRED)
set(CMAKE_C_COMPILER "/usr/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")

# set( TARGET ${PROJECT_NAME} )
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
project(FaceDetection LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
# set(OpenCV_DIR /opt/homebrew/Cellar/opencv/4.8.0_1/include/opencv4)
set(FACE_DETECTION_CONFIGURATION "${PROJECT_SOURCE_DIR}/../assets/deploy.prototxt")
set(FACE_DETECTION_WEIGHTS "${PROJECT_SOURCE_DIR}/../assets/res10_300x300_ssd_iter_140000_fp16.caffemodel")
# set( SOURCE_PATH "${PROJECT_SOURCE_DIR}/src")
# set( INCLUDE_PATH "${PROJECT_SOURCE_DIR}/include")

# file( GLOB_RECURSE HS "${INCLUDE_PATH}/*.h")
# file( GLOB_RECURSE CPPS "${SOURCE_PATH}/*.cpp")
set(CMAKE_CXX_STANDARD 20)

add_executable(${PROJECT_NAME} main.cpp)

find_package(OpenCV REQUIRED)

# include_directories("/opt/homebrew/Cellar/opencv/4.8.0_1/include/opencv4")

target_include_directories(${PROJECT_NAME} PUBLIC "include/")

target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
# target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wshadow -Wconversion -Wsign-conversion -Wunused-parameter -Wno-long-long -pedantic)

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
target_compile_definitions(${PROJECT_NAME} PRIVATE FACE_DETECTION_CONFIGURATION="${FACE_DETECTION_CONFIGURATION}")
target_compile_definitions(${PROJECT_NAME} PRIVATE FACE_DETECTION_WEIGHTS="${FACE_DETECTION_WEIGHTS}")
62 changes: 46 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../include/main.hpp"
#include <iostream>

FaceDetector::FaceDetector() :
confidence_threshold_(0.5),
Expand Down Expand Up @@ -42,28 +43,57 @@ std::vector<cv::Rect> FaceDetector::detect_face_rectangles(const cv::Mat &frame)
return faces;
}

int main() {
int main(int argc, char **argv) {
std::cout << "You have entered " << argc << " arguments:" << std::endl;
bool isFaceDetection = false;
bool isShowLines = false;
for(int i = 0; i < argc; i++) {
std::cout << "\t" << argv[i] << std::endl;
if(strcmp(argv[i], "--face-detection") == 0) {
isFaceDetection = true;
}
if(strcmp(argv[i], "--show-lines") == 0) {
isShowLines = true;
}
}

cv::VideoCapture vCap;
if(!vCap.open(0)) {
return 0;
}
FaceDetector face_detector;
//Create Mat to hold the frame and display it (in an infinite loop)
cv::Mat frame;
while(true) {
vCap >> frame;

auto rectangles = face_detector.detect_face_rectangles(frame);
cv::Scalar color(0,105,205);
int frame_thickness = 4;
for(const auto & r : rectangles) {
cv::rectangle(frame, r, color, frame_thickness);
if(isFaceDetection) {
FaceDetector face_detector;
//Create Mat to hold the frame and display it (in an infinite loop)
cv::Mat frame;
while(true) {
vCap >> frame;

auto rectangles = face_detector.detect_face_rectangles(frame);
cv::Scalar color(0,105,205);
int frame_thickness = 4;
for(const auto & r : rectangles) {
cv::rectangle(frame, r, color, frame_thickness);
}
cv::imshow("Image", frame);
const int esc_key = 27;
if(cv::waitKey(10) == esc_key) {
break;
}
}
imshow("Image", frame);
const int esc_key = 27;
if(cv::waitKey(10) == esc_key) {
break;
} else if(isShowLines) {
cv::Mat frame, edges;
cv::namedWindow("edges", cv::WINDOW_AUTOSIZE);

for(;;) {
vCap >> frame;
cv::cvtColor(frame, edges, cv::COLOR_BGR2GRAY);
cv::GaussianBlur(edges, edges, cv::Size(7,7), 1.5, 1.5);
cv::Canny(edges, edges, 0, 30, 3);
cv::imshow("edges", edges);
if(cv::waitKey(30) >= 0) break;
}
} else {
std::cout << "No options selected. Please add an option and try again." << std::endl;
}
cv::destroyAllWindows();
vCap.release();
Expand Down

0 comments on commit 28ff4f5

Please sign in to comment.