コード例 #1
0
ファイル: faceDetector.cpp プロジェクト: dgurungmisc/opencv-1
void FaceDetector::process(cv::Mat frame)
{
    cv::Mat grey_image;
    cv::cvtColor(frame, grey_image, CV_BGR2GRAY);
    cv::equalizeHist(grey_image, grey_image);

    std::vector<cv::Rect> faces;
    // Calculate the camera size and set the size to 1/8 of screen height
    faceCascade.detectMultiScale(grey_image, faces, 1.1, 2,  0|CV_HAAR_SCALE_IMAGE,
                                 cv::Size(frame.cols/4, frame.rows/4)); // Minimum size of obj
    //-- Draw rectangles around faces
    for( size_t i = 0; i < faces.size(); i++)
    {
        cv::rectangle(frame, faces[i], cv::Scalar( 255, 0, 255 ));
        /*
        cv::Point center( faces[i].x + faces[i].width*0.5,
                  faces[i].y + faces[i].height*0.5);

        ellipse( frame, center,
             cv::Size( faces[i].width*0.5, faces[i].height*0.5 ),
             0, 0, 360, cv::Scalar( 255, 0, 255 ), 4, 8, 0);

        cv::Mat faceROI = frameGray( faces[i] );
        std::vector<cv::Rect> eyes;

        //-- In each face, detect eyes
        eyeCascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, cv::Size(30, 30) );

        for( size_t j = 0; j < eyes.size(); j++)
        {
            cv::Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5,
                      faces[i].y + eyes[j].y + eyes[j].height*0.5 );
            int radius = cvRound( (eyes[j].width + eyes[j].height) *0.25);
            circle( frame, center, radius, cv::Scalar( 255, 0, 0 ), 4, 8, 0);
        }
        */

    }
    const QImage image((const unsigned char*)frame.data, frame.cols, frame.rows, frame.step,
                       QImage::Format_RGB888, &matDeleter, new cv::Mat(frame));
    image.rgbSwapped();
    Q_ASSERT(image.constBits() == frame.data);
    emit image_signal(image);
}
コード例 #2
0
ファイル: viewerwindow.cpp プロジェクト: Getshi/SOA
ViewerWindow::ViewerWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ViewerWindow)
{
    //Create GUI
    ui->setupUi(this);

    //Create Network Socket
    tcpSocket = new QTcpSocket();
    connected_to_server = false;

    //Create capturebuffer and connect its image_signal to on_frame slot
    captureBuffer = new CaptureBuffer;
    connect(captureBuffer,SIGNAL(image_signal(QImage)), this, SLOT(on_frame(QImage)));

    //Read previously selected camera from settings
    QSettings settings("GS", "viewer");
    selected_camera = settings.value("Selected Camera", QByteArray()).toByteArray();
    if (selected_camera == QByteArray()) //no device was selected
    {
        selected_camera = QCamera::availableDevices()[0];
    }
    camera = NULL;

    //Create empty movie and connect buttons to slots
    movie_ = new QMovie();
    //ui->label->setMovie(movie_);
    connect(ui->playButton, SIGNAL(clicked()), this, SLOT(pauseUnpauseMovie()));
    connect(ui->stopButton, SIGNAL(clicked()), movie_, SLOT(stop()));

    //Read and set autostart from settings
    autostart = settings.value("Auto-Iniciar", true).toBool();
    ui->autoInit->setChecked(autostart);
    if (autostart) ui->playButton->setText("Pausar");
    else ui->playButton->setText("Iniciar");
}