OpenCV - Error in highgui.hpp

2019-08-25 03:55发布

问题:

i am trying to detect lane using a web cam. i could compile it in the beginning and test it but after changing the machine which i used to work on. it isnt working any more. Gives me some error back.

the following is the code

int run() {

    bool pause = false`;`
    VideoCapture cam(0);
    //VideoCapture cam("clip.mp4");
    if(!cam.isOpened())
    {
        cout<<"\n Error Opening Device"<<endl;
        return 0;
    }
    width=cam.get(CV_CAP_PROP_FRAME_WIDTH);
    height=cam.get(CV_CAP_PROP_FRAME_HEIGHT);
    init();
    while(1)
    {
        cam >> frame;
        frameclone=frame.clone();
        drawElement(frame);
        imshow("Live Feed",frame);
        cvtColor(frameclone,bw,CV_RGB2GRAY);
        blur( bw, bw, Size(5,5) );
        Canny( bw, canny,0,75,3);
        imshow("canny",canny);
        regionofinterest();
        cvtColor(canny,canny,CV_GRAY2BGR);
        imshow("debug",canny);
        //houghT();
        imshow("ROI",frame);
        switch(waitKey(18))
        {
            case 113:
                cout<<"Exiting"<<endl;
                return -1;
                break;
            case 033:
                cout<<"Exiting"<<endl;
                return -1;
                break;
            case 112:
                pause=!pause;
                cout<<"Code Paused"<<endl;
                if(pause==true)
                {
                    switch(waitKey())
                        case 112:
                            pause=!pause;
                            cout<<"Code Resumed"<<endl;
                            break;
                }
        }
    }
}

I have also Include the

#include "opencv2/opencv.hpp"
#include "opencv2/photo/photo.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "iostream"
#include "stdio.h"

But still it gives me the following error:-

/home/ashik/Desktop/Project/detectlane/detectlane.cpp: In member function ‘void Detect::init()’:

/home/ashik/Desktop/Project/detectlane/detectlane.cpp:35:23: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
   namedWindow("debug",CV_WINDOW_AUTOSIZE);
                       ^

/home/ashik/Desktop/Project/detectlane/detectlane.cpp:36:23: error: ‘CV_WINDOW_NORMAL’ was not declared in this scope
   namedWindow("canny",CV_WINDOW_NORMAL);
                       ^

/home/ashik/Desktop/Project/detectlane/detectlane.cpp: In member function ‘int Detect::run()’:


/home/ashik/Desktop/Project/detectlane/detectlane.cpp:89:17: error: 
‘CV_CAP_PROP_FRAME_WIDTH’ was not declared in this scope
   width=cam.get(CV_CAP_PROP_FRAME_WIDTH);
                 ^
/home/ashik/Desktop/Project/detectlane/detectlane.cpp:90:18: error: ‘CV_CAP_PROP_FRAME_HEIGHT’ was not declared in this scope
   height=cam.get(CV_CAP_PROP_FRAME_HEIGHT);
                  ^

/home/ashik/Desktop/Project/detectlane/detectlane.cpp:98:27: error: ‘CV_RGB2GRAY’ was not declared in this scope
    cvtColor(frameclone,bw,CV_RGB2GRAY);
                           ^

/home/ashik/Desktop/Project/detectlane/detectlane.cpp:103:25: error: ‘CV_GRAY2BGR’ was not declared in this scope
    cvtColor(canny,canny,CV_GRAY2BGR);
                         ^

make[2]: *** [CMakeFiles/detectlane.dir/detectlane.cpp.o] Error 1
make[1]: *** [CMakeFiles/detectlane.dir/all] Error 2
make: *** [all] Error 2

i used cmake and opencv 3.0.0 alpha

回答1:

I encountered the same problem. Try including

#include <highgui.h>