Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `
- using namespace std;
- using namespace cv;
- struct button {
- uint8_t btn;
- int btn_state;
- };
- typedef struct button BUTTON;
- struct seaid_project {
- uint8_t ledGreen = RPI_V2_GPIO_P1_37;
- uint8_t ledRed = RPI_V2_GPIO_P1_31;
- uint8_t ledYellow = RPI_V2_GPIO_P1_35;
- uint8_t ledReader = RPI_V2_GPIO_P1_33;
- BUTTON btnShutdown;
- BUTTON btnReboot;
- BUTTON btnShutdown;
- BUTTON btnReboot;
- SEAID *seaid;
- seaid->btnShutdown.btn = RPI_V2_GPIO_P1_16;
- seaid->btnReboot.btn = RPI_V2_GPIO_P1_18;
- pthread_t t_btnShutdown, t_btnReboot, t_captureImage;
- int ret;
- bcm2835_gpio_write(seaid->ledGreen, HIGH);
- bcm2835_gpio_write(seaid->ledYellow, LOW);
- bcm2835_gpio_write(seaid->ledRed, LOW);
- bcm2835_gpio_write(seaid->ledReader, LOW);
- // Inicializa mutex
- if (pthread_mutex_init(&lockMutex, NULL) != 0) {
- error(seaid->ledRed, "Erro ao inicializar mutex.n");
- }
- // Iniciliza biblioteca bcm2835
- if (!bcm2835_init()) {
- error(seaid->ledRed, "Erro ao inicializar biblioteca bcm2835.n");
- }
- // Seleciona pinos de saída para LEDs
- bcm2835_gpio_fsel(seaid->ledGreen, BCM2835_GPIO_FSEL_OUTP);
- bcm2835_gpio_fsel(seaid->ledRed, BCM2835_GPIO_FSEL_OUTP);
- bcm2835_gpio_fsel(seaid->ledYellow, BCM2835_GPIO_FSEL_OUTP);
- bcm2835_gpio_fsel(seaid->ledReader, BCM2835_GPIO_FSEL_OUTP);
- // Seleciona pinos de entrada para push buttons
- // Desabilita resistores de pull up/down nesses pinos
- bcm2835_gpio_fsel(seaid->btnShutdown.btn, BCM2835_GPIO_FSEL_INPT);
- bcm2835_gpio_fsel(seaid->btnShutdown.btn, BCM2835_GPIO_PUD_OFF);
- bcm2835_gpio_fsel(seaid->btnReboot.btn, BCM2835_GPIO_FSEL_INPT);
- bcm2835_gpio_fsel(seaid->btnReboot.btn, BCM2835_GPIO_PUD_OFF);
- //Cria thread para OpenCV
- ret = pthread_create(&t_captureImage, NULL, captureImage, &seaid);
- if (ret != 0) {
- error(seaid->ledRed, "Erro thread "t_captureImage"");
- }
- // Cria thread para ler estado dos botões
- ret = pthread_create(&t_btnShutdown, NULL, inputRead, &seaid->btnShutdown);
- if (ret != 0) {
- error(seaid->ledRed, "Erro thread "t_btnShutdown"");
- }
- ret = pthread_create(&t_btnReboot, NULL, inputRead, &seaid->btnReboot);
- if (ret != 0) {
- error(seaid->ledRed, "Erro thread "t_btnReboot"");
- }
- // Aguarda as threads terminarem
- pthread_join(t_captureImage, NULL);
- pthread_join(t_btnShutdown, NULL);
- pthread_join(t_btnReboot, NULL);
- // Finaliza biblioteca bcm2835
- bcm2835_close();
- //Destrói o mutex
- pthread_mutex_destroy(&lockMutex);
- return 0;
- //Loop infinito
- while (1) {
- // Trava o mutex antes de acessar variável led_state
- pthread_mutex_lock(&lockMutex);
- // Atualiza estado do LED - liga ou desliga
- if (seaid->btnShutdown.btn_state)
- bcm2835_gpio_write(seaid->ledRed, HIGH);
- else
- bcm2835_gpio_write(seaid->ledRed, LOW);
- // Libera o mutex
- pthread_mutex_unlock(&lockMutex);
- // Pequeno delay
- bcm2835_delay(50);
- }
- pthread_exit(NULL);
- //Loop infinito
- while (1) {
- // Trava o mutex antes de acessar variável led_state
- pthread_mutex_lock(&lockMutex);
- // Atualiza estado do botão na variável
- button->btn_state = bcm2835_gpio_lev(button->btn);
- // Libera o mutex
- pthread_mutex_unlock(&lockMutex);
- // Pequeno delay
- bcm2835_delay(50);
- }
- pthread_exit(NULL);
- SEAID *seaid = (SEAID *)p;
- std::vector<Rect> digitais;
- bcm2835_gpio_write(seaid->ledReader, HIGH);
- VideoCapture cap(0);
- Mat frame;
- cap >> frame;
- if (frame.empty()) {
- error(seaid->ledRed, "Erro ao capturar a imagem");
- }
- try {
- if (hasFingerprint(frame)) {
- try {
- startCapture(*seaid);
- }
- catch (...) {
- error(seaid->ledRed, "Erro captura das digitais do voluntário");
- }
- pthread_mutex_unlock(&lockMutex);
- bcm2835_gpio_write(seaid->ledReader, LOW);
- }
- else {
- pthread_mutex_unlock(&lockMutex);
- bcm2835_gpio_write(seaid->ledReader, LOW);
- }
- }catch(...) {
- error(seaid->ledRed, "Erro na detecção da imagem");
- }
- pthread_exit(NULL);
- CascadeClassifier fingerPrintCascade;
- fingerPrintCascade.load("Training/data/cascade.xml");
- try {
- fingerPrintCascade.detectMultiScale(frame, fingerprints, 1.1, 0, 0 | CASCADE_SCALE_IMAGE, Size(30, 30));
- }
- catch (...) {
- }
- if (!fingerprints.empty()) {
- hasImage = true;
- }
- return hasImage;
Add Comment
Please, Sign In to add comment