Skip to content

Commit

Permalink
Bug folder
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobiqua committed Dec 26, 2023
1 parent e877d97 commit af1aa9a
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 12 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ project(OpenCV_Learn)

set(CMAKE_CXX_STANDARD 17)

include(CopyFiles.cmake)
copy_files_to_destination()
# include(CopyFiles.cmake)
# copy_files_to_destination()

# Adiciona as flags de compilação
add_compile_options(-Wall -g -MMD)
Expand Down Expand Up @@ -43,6 +43,8 @@ add_executable(OpenCV_Learn main.cpp
gui/OptionsWindow.hpp
util/Config.cpp
util/Config.hpp
util/FolderManagment.cpp
util/FolderManagment.hpp
)

# Vincule o OpenCV ao executável
Expand Down
2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Images]
Folder_path=img
Folder_path=/home/pedro/.visualisador-rostos/img

[Model]
Model_name=haarcascade_frontalface_default.xml
Expand Down
7 changes: 4 additions & 3 deletions gui/OptionsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void OptionsWindow::set_hierarchy(){

void OptionsWindow::draw_widgets() {
Config config;
auto configurations = config.read_config("../config.ini");
auto configurations = config.read_config(FolderManagment::get_config_file());

set_title("Opções");
set_default_size(600, 400);
Expand All @@ -69,7 +69,8 @@ void OptionsWindow::draw_widgets() {
// Combo Model
m_combo_model.set_visible(true);
m_combo_model.set_can_focus(true);
auto files = reader_files::ReaderFilesInFolder::read_files_in_folder("../model");
auto model_folder_path = FolderManagment::get_model_folder();
auto files = reader_files::ReaderFilesInFolder::read_files_in_folder(model_folder_path);
for(auto& file : files){
m_combo_model.append(file);
}
Expand Down Expand Up @@ -131,7 +132,7 @@ void OptionsWindow::on_button_apply_clicked() {
if (show_yes_no_dialog("Você deseja continuar?", *this)) {
std::cout << "Usuário clicou em Sim." << std::endl;
Config config;
std::string nomeArquivo = "../config.ini";
std::string nomeArquivo = FolderManagment::get_config_file();
std::map<std::string, std::map<std::string, std::string>> configuracao = config.read_config(nomeArquivo);

config.edit_config(configuracao, "Images", "Folder_path", folder_selected);
Expand Down
1 change: 1 addition & 0 deletions gui/OptionsWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <iostream>
#include "../util/ReaderFilesInFolder.h"
#include "../util/Config.hpp"
#include "../util/FolderManagment.hpp"

class OptionsWindow : public Gtk::Window {
Gtk::Fixed m_fixed;
Expand Down
32 changes: 32 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <gtkmm.h>
#include "gui/MainWindow.h"
#include "options/ReaderFacesInFolder.h++"
#include "util/Config.hpp"
#include "util/FolderManagment.hpp"
// #include <boost/filesystem.hpp>
// #include <iostream>

#ifdef _WIN32
#define OS_NAME "Windows"
Expand All @@ -13,8 +17,36 @@
#endif

int main(int argc, char* argv[]) {
Config config;
std::map<std::string, std::map<std::string, std::string>> config_att = config.read_config(FolderManagment::get_config_file());
config.edit_config(config_att, "Images", "Folder_path", FolderManagment::get_img_folder());
config.edit_config(config_att, "Model", "Model_name", FolderManagment::get_model_folder() + "/haarcascade_frontalface_default.xml");

// ReaderFacesFolder::ReaderFacesInFolder::read_faces_in_folder(true);
auto app = Gtk::Application::create(argc, argv, "org.pedro.gtkmm");
MainWindow mainWindow;
return app->run(mainWindow);

/*
std::string homeDir = getenv("HOME");
std::cout << homeDir;
if (homeDir.empty()) {
homeDir = getpwuid(getuid())->pw_dir;
}
// Nome da pasta oculta
std::string hiddenFolderName = ".visualisador-rostos";
// Caminho completo para a nova pasta oculta
std::string hiddenFolderPath = homeDir + "/" + hiddenFolderName;
if (!fs::exists(hiddenFolderPath)) {
std::cout << "A pasta oculta não existe: " << hiddenFolderPath << std::endl;
} else {
std::cout << "A pasta oculta já existe em: " << hiddenFolderPath << std::endl;
}
return 0;
*/
}
13 changes: 7 additions & 6 deletions options/ReaderFacesInFolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ namespace ReaderFacesFolder {

bool debugMode = debug_mode;
Config config;
std::string nomeArquivo = "../config.ini";
std::map<std::string, std::map<std::string, std::string>> readConfig = config.read_config(nomeArquivo);
auto config_file = FolderManagment::get_config_file();
// std::string nomeArquivo = "../config.ini";
std::map<std::string, std::map<std::string, std::string>> readConfig = config.read_config(config_file);

// Especifica a largura máxima desejada para a imagem
int maxWidth = 500;
Expand All @@ -28,7 +29,7 @@ namespace ReaderFacesFolder {
folder_img_path = folder_img_path + readConfig["Images"]["Folder_path"];
}

if (readConfig["Model"]["Model_name"] != ""){
if (readConfig["Model"]["Model_name"].empty()){
classifier_path = classifier_path + readConfig["Model"]["Model_name"];
} else {
classifier_path = classifier_path + "haarcascade_frontalface_default.xml";
Expand Down Expand Up @@ -97,13 +98,13 @@ namespace ReaderFacesFolder {
// Especifica a largura máxima desejada para a imagem
// PADRÃO
Config config;
auto configurations = config.read_config("../config.ini");
auto configurations = config.read_config(FolderManagment::get_config_file());
int maxWidth = 500;
int maxHeight = 1200;
bool debugMode = debug_mode;

string classifier_path = "../model/";
if (configurations["Model"]["Model_name"] != ""){
string classifier_path = FolderManagment::get_model_folder() + "/";
if (configurations["Model"]["Model_name"].empty()){
classifier_path = classifier_path + configurations["Model"]["Model_name"];
} else {
classifier_path = classifier_path + "haarcascade_frontalface_default.xml";
Expand Down
1 change: 1 addition & 0 deletions options/ReaderFacesInFolder.h++
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <opencv2/objdetect.hpp>
#include "../util/ReaderFilesInFolder.h"
#include "../util/Config.hpp"
#include "../util/FolderManagment.hpp"

using namespace cv;
using namespace std;
Expand Down
35 changes: 35 additions & 0 deletions util/FolderManagment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by pedro on 25/12/23.
//

#include "FolderManagment.hpp"

std::string FolderManagment::get_model_folder() {
auto home_folder = get_home_folder();
return home_folder + "/model";
}

std::string FolderManagment::get_img_folder() {
auto home_folder = get_home_folder();
return home_folder + "/img";
}

std::string FolderManagment::get_config_file() {
auto home_folder = get_home_folder();
return home_folder + "/config.ini";
}

std::string FolderManagment::get_home_folder() {
std::string homeDir = getenv("HOME");

if (homeDir.empty()) {
homeDir = getpwuid(getuid())->pw_dir;
}

// Nome da pasta oculta
std::string hiddenFolderName = ".visualisador-rostos";

// Caminho completo para a nova pasta oculta
std::string hiddenFolderPath = homeDir + "/" + hiddenFolderName;
return hiddenFolderPath;
}
22 changes: 22 additions & 0 deletions util/FolderManagment.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by pedro on 25/12/23.
//

#ifndef OPENCV_LEARN_FOLDERMANAGMENT_HPP
#define OPENCV_LEARN_FOLDERMANAGMENT_HPP

#include <string>
#include <unistd.h>
#include <pwd.h>


class FolderManagment {
public:
static std::string get_model_folder();
static std::string get_img_folder();
static std::string get_config_file();
static std::string get_home_folder();
};


#endif //OPENCV_LEARN_FOLDERMANAGMENT_HPP

0 comments on commit af1aa9a

Please sign in to comment.