Ask Your Question
0

OpenCV 3.0 Header Confusion

asked 2015-06-11 14:48:30 -0600

updated 2015-06-11 15:55:13 -0600

LBerger gravatar image

I am new to OpenCV and have been trying to figure everything out through tutorials and online documentation but I have run into a bit of an issue, most likely stemming from my imperfect understanding of how Visual studio grabs and uses header files.

My end goal is simply to adjust the exposure time of a video stream so that it will be lighter and I can actually track the objects I want. It has gotten me deeper into trying to understand everything though so here is my issue.

  1. I understand that the old C API headers are obsolete now and that I should be using the C++ API. I also know they are in the same folder for compatibility. My confusion is in whether both old and new headers will be loaded when i set the path to build\include\opencv2 and whether that will cause issues. I have been looking around for the code to change exposure and have found many different functions but none seem to have worked. I tried

set(CV_CAP_PROP_EXPOSURE, 150); cap.set(CV_CAP_PROP_EXPOSURE, 150); cvSetCaptureProperty(cap, CV_CAP_PROP_EXPOSURE, 480);

  1. among others. any help on which is current would be great

My code is below. Sorry for the length of post. I am happy to put in the work but I have run into a wall. I have loaded and moved the headers several times trying to figure out.

  1. Also, if a header is linked in the Solution Explorer does that mean you don't have to "#include<module.hpp>" it?

    //#include < opencv\cv.h>
    //#include < opencv\highgui.h>
    #include < opencv2\opencv.hpp>
    //#include < opencv2\core\cvdef.h>
    
    //#define CV_WRAP
    
    using namespace cv;
    
    using namespace std;
    int main()
    {
    //create matrix to store image
    Mat image;
    //initialize capture
    
    VideoCapture cap;
    cap.open(0);
    
    //create window to show image
    cvNamedWindow("window", WINDOW_NORMAL);
    
    cap.set(CV_CAP_PROP_FRAME_WIDTH, 2048);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1536);
    
    
    while (1){
    
        //copy webcam stream to image
    
        cap >> image;
    
        //print image to screen
        imshow("window", image);
    
        //part I'm struggling with
        set(CV_CAP_PROP_EXPOSURE, 150);
    
        //delay 33ms
        waitKey(33);
    
        //print camera brightness setting
        switch (waitKey(10)){
    
        case 27:
            //'esc' has been pressed (ASCII value for 'esc' is 27)
            //exit program.
            return 0;
        }
    }
     return 0;}
    
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-06-12 06:27:53 -0600

My confusion is in whether both old and new headers will be loaded when i set the path to build\include\opencv2 and whether that will cause issues.

That will not be an issue. Old C-headers are in the /include/opencv/ folder while the new c++ headers are in the /include/opencv2/ folder.

For the exposure setting, the only correct function is cap.set(CV_CAP_PROP_EXPOSURE, 150);. If that doesn't work than that simply means that your camera is using an OpenCV interface that doesn't support setting the exposure of your cam. Only option then is to use the API provided by your camera manufacturer, if it is already possible at all.

Also, if a header is linked in the Solution Explorer does that mean you don't have to "#include<module.hpp>" it?

No, the linker options in the solution explorer simply points where that data is. Your file still needs the correct includes else your compiler will complain about not knowing where to look for the function.

edit flag offensive delete link more

Comments

1

Thank you Steven, that helps alot. I ended up finding and using cap.set(CV_CAP_PROP_SETTINGS,1); and while looking through the options I found that exposure was not an option, which makes sense because it wasn't throwing an error every time, it just wasn't doing anything. Is there a way to make the camera keep the settings set up in its own API/software?

as far as the old headers being in /include/opencv/ though, many of the headers in the opencv2 subfolders that I look through say that they are deprecated. calib3d for example, I suppose it simply loads the new header though. My confusion here is why are certain functions in my code not recognized when I can "peek definition" and they are in a header that I have indeed included.

WasBlindButNowIC++ gravatar imageWasBlindButNowIC++ ( 2015-06-12 07:32:31 -0600 )edit

Afaik a camera always remembers its settings as long as power is available. I do it all the time, using the toolkit of the camera to set it up, then use OpenCV to grab the frames.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-06-12 12:47:52 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-11 14:48:30 -0600

Seen: 796 times

Last updated: Jun 12 '15