Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. OpenCV & QT: 'emit' undeclared identifier error

OpenCV & QT: 'emit' undeclared identifier error

Scheduled Pinned Locked Moved Unsolved General and Desktop
opencvemit signalqt5
6 Posts 4 Posters 6.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • htmlbossH Offline
    htmlbossH Offline
    htmlboss
    wrote on last edited by
    #1

    I'm using OpenCV with QT and trying to implement facial recognition but as soon as I include <face.hpp> from the OpenCV "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. Suggestions? 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);
        }
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Try including OpenCV headers before Qt ones.
      If all else fails you can replace emit with Q_EMIT macro.

      htmlbossH 1 Reply Last reply
      3
      • Chris KawaC Chris Kawa

        Try including OpenCV headers before Qt ones.
        If all else fails you can replace emit with Q_EMIT macro.

        htmlbossH Offline
        htmlbossH Offline
        htmlboss
        wrote on last edited by
        #3

        @Chris-Kawa The Q_EMIT macro did the trick. Any ideas why this happened? I thought emit was an empty macro defined in the QT headers.

        Hamed.MasafiH 1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Most probably because of this silly "fix" :/
          As I mentioned earlier - including Qt after OpenCV could possibly fix this.

          1 Reply Last reply
          1
          • htmlbossH htmlboss

            @Chris-Kawa The Q_EMIT macro did the trick. Any ideas why this happened? I thought emit was an empty macro defined in the QT headers.

            Hamed.MasafiH Offline
            Hamed.MasafiH Offline
            Hamed.Masafi
            wrote on last edited by Hamed.Masafi
            #5

            @htmlboss said:

            @Chris-Kawa The Q_EMIT macro did the trick. Any ideas why this happened? I thought emit was an empty macro defined in the QT headers.

            Emiting a signal is just calling it. The emit keyword is not a compiler token. It's just a empty macro for auto completion reason. If you don't like it, don't use emit keyword in anywhere.
            Flowing three lines are equal

            //Line 1
            emit signal();
            
            //Line 2
            Q_EMIT signal();
            
            //Line 3
            signal();  // !!!
            

            Remote object sharing (OO RPC)
            http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

            Advanced, Powerful and easy to use ORM for Qt5
            https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Just a quick note, taking a look at fixing this "fix", I just saw that the latest version of the contrib repository doesn't contain the offending code anymore.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved