Ask Your Question
0

QT 'emit': undeclared identifier error after <face.hpp> included

asked 2016-06-05 15:50:12 -0600

htmlboss gravatar image

I'm using OpenCV with QT and trying to implement facial recognition but as soon as I include <face.hpp> from the "contrib" branch, QT complains about error: C2065: 'emit': undeclared identifier. I've tried including "qobjectdefs.h" and #define emit at the top of the appropriate header file, but it does not work. Code:

Header

    #ifndef FACEDETECTOR_H
    #define FACEDETECTOR_H

    #include <QObject>
    #include <QBasicTimer>
    #include <QTimerEvent>
    #include <QDir>
    #include <QDebug>
    #include <QImage>
    #include <QString>
    #include <QResource>
    #include <QVector>
//This causes the error as soon as I uncomment it
    #include <opencv2/face.hpp>
    #include <opencv2/opencv.hpp>

    class FaceDetector : public QObject {
        Q_OBJECT

    public:
        FaceDetector(QObject *parent=0) : QObject(parent), processAll_(true) {}
        void setProcessAll(bool all);
        ~FaceDetector();

    signals:
        void image_signal(const QImage&);

    public slots:
        void processFrame(const cv::Mat& frame);
        void facecascade_filename(QString filename);

    private:
        QString facecascade_filename_;
        QString eyecascade_filename_;
        QBasicTimer timer_;
        QVector<cv::Mat> m_CSVimages;
        QVector<int> m_CSVlabels;
        cv::Mat frame_;
        bool processAll_;
        cv::CascadeClassifier faceCascade;
        cv::CascadeClassifier eyeCascade;

//I need face.hpp for this:
        //cv::Ptr<cv::face::FaceRecognizer> m_faceModel;

        void process(cv::Mat frame);
        void loadFiles(const cv::String& faceCascadeFilename, const cv::String& eyesCascadeFilename);
        static void loadCSV(const cv::String& filePath, QVector<cv::Mat>& images, QVector<int>& labels, char separator = ';');
        void queue(const cv::Mat & frame);
        void timerEvent(QTimerEvent* ev);
        static void matDeleter(void* mat);
    };

    #endif // FACEDETECTOR_H

Implementation Other functions omitted for brevity

    #include "faceDetector.h"

    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, 8,  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::cvtColor(frame, frame, cv::COLOR_BGR2RGB);
        const QImage image(static_cast<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);

//This is the error location
        emit image_signal(image);
    }
edit retag flag offensive close merge delete

Comments

there were recent changes to the face recognition code, the emit function is no more there.

try to update both opencv / opencv_contrib to latest, and rebuild, hopefully the problem is gone then.

berak gravatar imageberak ( 2016-06-06 00:11:32 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-08 13:04:52 -0600

htmlboss gravatar image

I turns out I needed to replace emit keyword with the actual macro Q_EMIT.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-06-05 15:50:12 -0600

Seen: 1,101 times

Last updated: Jun 08 '16