Ask Your Question
0

Every thing works fine except for: CommandLineParser has no member named ‘about’,print message,has,check

asked 2016-09-01 07:53:57 -0600

M_HA gravatar image

updated 2016-09-01 09:12:23 -0600

        #include <iostream>
        #include <opencv2/opencv.hpp>
        #include <opencv2/core/core.hpp>
        #include <opencv/cv.h> /// include most of core headers
        #include <opencv/highgui.h> // include GUI-related headers

        using namespace cv;
        using namespace std;


        // OpenCV command line parser functions
        // Keys accecpted by command line parser

        const char* keys =
                {
                        "{help h usage ? | | print this message}"
                                "{@video | | Video file, if not defined try to use webcamera}"
                };
        int main(int ac, const char** av)
        {

            CommandLineParser parser(ac,av,keys);
            parser.about("Chapter 2. v1.0.0");
            //If requires help show
            if (parser.has("help"))
            {
                parser.printMessage();
                return 0;
            }
            String videoFile= parser.get<String>(0);
        // Check if params are correctly parsed in his variables
            if (!parser.check())
            {
                parser.printErrors();
                return 0;
            }
            cv::VideoCapture cap;
            const std::string kWinName1 = "Exercise 1 - Original Image";
            const std::string kWinName2 = "Exercise 1 - Thresholded Image";

            std::cout << "Startup (Press ESC to quit)" << std::endl;
            namedWindow( kWinName1, CV_WINDOW_AUTOSIZE);
            cv::namedWindow( kWinName2, CV_WINDOW_NORMAL);
            initVideoStream(cap);

            int slider_value = 100;
            cv::createTrackbar( "Threshold", "Exercise 1 - Thresholded Image", &slider_value, 255, trackbarHandler, &slider_value);

            Mat img_bgr;
            cv::Mat img_gray;
            cv::Mat img_filtered;

            while (1) {

                cap >> img_bgr;

                if(img_bgr.empty()){
                    printf("Could not query frame. Trying to reinitialize.\n");
                    initVideoStream(cap);
                    cv::waitKey(1000); /// Wait for one sec.
                    continue;
                }
                cv::cvtColor( img_bgr, img_gray, CV_BGR2GRAY );

                //threshold( img_gray, img_filtered, slider_value, 255, CV_THRESH_BINARY);
               adaptiveThreshold(img_gray, img_filtered, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, 33, 8);

                cv::imshow(kWinName1, img_bgr);
                cv::imshow(kWinName2, img_filtered);

                char key = (char) cv::waitKey (0);
                if (key == 27) break;
            }

            cv::destroyWindow (kWinName1);
            cv::destroyWindow (kWinName2);
            std::cout << "Finished\n";
        }



Error Output:
    /usr/local/clion-2016.1.3/bin/cmake/bin/cmake
--build /home/mh/.CLion2016.1/system/cmake/generated/augmented_1-aa43292c/aa43292c/Debug
--target augmented_1 -- -j 4
    Scanning dependencies of target augmented_1
    [ 50%] Building CXX object CMakeFiles/augmented_1.dir/main.cpp.o
    /home/mh/ClionProjects/augmented_1/main.cpp: In function ‘int main(int, const char**)’:
    /home/mh/ClionProjects/augmented_1/main.cpp:40:12: error: ‘class cv::CommandLineParser’ has no member named ‘about’
         parser.about("Chapter 2. v1.0.0");
                ^
    In file included from /usr/local/include/opencv2/opencv.hpp:49:0,
                     from /home/mh/ClionProjects/augmented_1/main.cpp:3:
    /usr/local/include/opencv2/core/core.hpp:4807:10: error: ‘bool cv::CommandLineParser::has(const string&)’ is protected
         bool has(const std::string& keys);
              ^
    /home/mh/ClionProjects/augmented_1/main.cpp:42:26: error: within this context
         if (parser.has("help"))
                              ^
    /home/mh/ClionProjects/augmented_1/main.cpp:44:16: error: ‘class cv::CommandLineParser’ has no member named ‘printMessage’
             parser.printMessage();
                    ^
    /home/mh/ClionProjects/augmented_1/main.cpp:49:17: error: ‘class cv::CommandLineParser’ has no member named ‘check’
         if (!parser.check())
                     ^
    /home/mh/ClionProjects/augmented_1/main.cpp:51:16: error: ‘class cv::CommandLineParser’ has no member named ‘printErrors’
             parser.printErrors();
                    ^
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2016-09-02 02:02:14 -0600

berak gravatar image

updated 2016-09-02 02:04:23 -0600

indeed, if you're using opencv2.4 you can't use any of those functions, all it has is get() and printParams(). (see header )

(but it seems, you took the code from some opencv3 sample, while you're working with opencv2.4. not everything is compatible, unfortunately)

(sidenote, please avoid to include the old c-api headers, like cv.h highgui.h)

edit flag offensive delete link more

Comments

Thank you. Which one do you recommend to work with 3 or 2.4.13

M_HA gravatar imageM_HA ( 2016-09-02 02:23:19 -0600 )edit
1

i'd say: unless you've legacy code to maintain, - opencv3 (but that's an opinion piece!)

berak gravatar imageberak ( 2016-09-02 02:29:12 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-01 07:53:57 -0600

Seen: 2,090 times

Last updated: Sep 02 '16