Ask Your Question

buds's profile - activity

2015-04-06 07:56:26 -0600 asked a question how to detect the facial profile ?

hello guys, i've been using opencv and visual studio to try a face detection program and it works. My question is, whether the front and side faces (facial profile) can be detected simultaneously (at one time in one program)? i already called the lbpcascade_profileface.xml, and then i used the haarcascade_profileface.xml but the program doesn't run properly. and sometimes even the frontal face is undetectable

2015-03-31 13:10:58 -0600 commented question face detection (how to make a condition to tell that there is no face detected?)

thank you sir, i really appreciate your help. i am sorry for the inconvenience sir, my bad. thanks again @boaz001

2015-03-31 10:01:40 -0600 asked a question face detection (how to make a condition to tell that there is no face detected?)

hello, my name is budi. i am a newbie in image processing, recently i've been trying to learn about opencv and visual studio. i have already succeed to detect the face then draw the rectangle,circle, and ellipse (should change the code first) around the face that i've detected thanks to the example in some DIY website. my question is, how to make a condition to tell that there is no face detected? how do i write the code ? i already succeed to make a condition if there is at least one face detected with a code like this. 'if (faces.size() > 0) { bla bla bla}'

or maybe how to detect the circle that encircling the face ?

please help me

here is the code i use :

#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/ocl/ocl.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/opencv_modules.hpp>
#include <opencv2/videostab/deblurring.hpp>

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include <sstream>
#include <string>

using namespace std;
using namespace cv;


const static Scalar colors[] =  { CV_RGB(0,0,255),
                              CV_RGB(0,128,255),
                              CV_RGB(0,255,255),
                              CV_RGB(0,255,0),
                              CV_RGB(255,128,0),
                              CV_RGB(255,255,0),
                              CV_RGB(255,0,0),
                              CV_RGB(255,0,255)
                            } ;



void Draw(Mat& img, vector<Rect>& faces, double scale);


int main(int argc, const char** argv)
{
    // Setup serial port connection and needed variables.
     HANDLE hSerial = CreateFile(L"COM8", GENERIC_READ | GENERIC_WRITE, 0, 0,     OPEN_EXISTING,        FILE_ATTRIBUTE_NORMAL, 0);

if (hSerial !=INVALID_HANDLE_VALUE)
{
    printf("Port opened! \n");

    DCB dcbSerialParams;
    GetCommState(hSerial,&dcbSerialParams);

    dcbSerialParams.BaudRate = CBR_9600;
    dcbSerialParams.ByteSize = 8;
    dcbSerialParams.Parity = NOPARITY;
    dcbSerialParams.StopBits = ONESTOPBIT;

    //CvMemStorage* p_strStorage;

    char incomingData[256] = "";            // don't forget to pre-allocate memory
//printf("%s\n",incomingData);
int dataLength = 256;
int readResult = 0;

    SetCommState(hSerial, &dcbSerialParams);
    }
else
{
    if (GetLastError() == ERROR_FILE_NOT_FOUND)
    {
        printf("Serial port doesn't exist! \n");
    }

    printf("Error while setting up serial port! \n");
}
char outputChars[] ="c" ;
DWORD btsIO;

 //void Draw(Mat& img, vector<Rect>& faces, double scale);

 Mat frame, frameCopy, image;



//int i;                                // loop counter
//char charCheckForEscKey;          // char for checking key press (Esc exits program)



//create the cascade classifier object used for the face detection
CascadeClassifier face_cascade;
//use the haarcascade_frontalface_alt.xml library
face_cascade.load("haarcascade_frontalface_alt.xml");

//setup video capture device and link it to the first capture device
VideoCapture captureDevice;
captureDevice.open(0);

if(captureDevice.open(0) == NULL) 
{                                       // if capture was not successful . . .
    printf("error: capture error \n");  // error message to standard out . . .
    getchar();                              // getchar() to pause for user see message . . .
    return(-1);
}


//setup image files used in the capture process
Mat captureFrame;
Mat grayscaleFrame;

//create a window to present the results
namedWindow("FaceDetection", 1);


//int servoPosition = 90;
//int servoOrientation = 0;
//int servoPosition1=90;
//int servoOrientation1=0;
//create a loop to capture and find faces
while(true)
{
    //p_imgOriginal = captureFrame;
    //capture a new image frame
    captureDevice>>captureFrame;

//convert captured image to gray scale and equalize
cvtColor(captureFrame, grayscaleFrame, CV_BGR2GRAY);
imshow("Grayscale", grayscaleFrame);
equalizeHist(grayscaleFrame, grayscaleFrame);

//p_strStorage = cvCreateMemStorage(0);

//create ...
(more)