Ask Your Question
0

OpenCV 3.0 with VS2013

asked 2015-08-06 05:11:11 -0500

Vizier87 gravatar image

Hi guys, here's what I'm trying to achieve: I'd like to start doing some object tracking with a webcam with OpenCV 3.0 powered by VS2013.

After viewing the tutorials, I got to view my webcam quite nicely but with bit of an inconvenience. After loading the program as follows:

#include <opencv2\highgui\highgui.hpp>

//displays video from a webcam
//0 is built-in, 1 is external
//press esc key to close

int main()
{

    cvNamedWindow("Webcam", CV_WINDOW_AUTOSIZE);
    CvCapture* capture = cvCreateCameraCapture(0); //0 = built-in, 1 = external, however in this case it seems having no default webcam, select 0.
    IplImage* frame;
    while (1) {
        frame = cvQueryFrame(capture);
        if (!frame) break;
        cvShowImage("Webcam", frame);
        char c = cvWaitKey(33);
        if (c == 27) break;
    }
    cvReleaseCapture(&capture);
    cvDestroyWindow("Image Processing: The CUFF Blueprint");
    return 0;

}

The whole thing doesn't work in Debug mode so I had to start withou Debugging, which works fine. The prompt in the background shows this:

Failed to load OPENCL at runtime <expected version="" 1.1+&gt;<="" p="">

So there that. Where do I go to smooth things up here? Thanks. Vizier87

edit retag flag offensive close merge delete

Comments

Please, first of all update that old C-API to the new C++ one

LorenaGdL gravatar imageLorenaGdL ( 2015-08-06 06:19:43 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-08-06 06:35:10 -0500

updated 2015-08-07 02:41:25 -0500

So this should be at least

// CHANGED header structure in OpenCV3.0
#include <opencv2\highgui.hpp>
#include <opencv2\videoio.hpp>
#include <opencv2\imgcodecs.hpp>

// ADD this to disable OpenCL explicitly
#include <opencv2/core/ocl.hpp>

// make sure you use the OpenCV namespace
using namespace cv;

int main()
{
    // Disable OpenCL explicitly here
    ocl::setUseOpenCL(false);

    VideoCapture capture(0);
    Mat current_frame;
    while (true) {
        capture >> current_frame;
        if (  current_frame.emty() ) break;
        imshow("Webcam",  current_frame);
        int key = waitKey(33) && 0xFF;
        if (key == 27) break;
    }
    return 0;
}

Try this first and stay away from the arcane C-API...

edit flag offensive delete link more

Comments

1

Whoops. I accidentally answered the question when I actually I wanted to comment on your answer. Sorry dude.

Okay after adding the header you suggested, the "frame" part was unidentified. Was it because my library was not installed properly?

However, when I pasted my old code WITH the new header, it worked out like the old one, still Ctrl+F5 mode only.

I really appreciate the help. Thanks.

Vizier87 gravatar imageVizier87 ( 2015-08-06 22:28:12 -0500 )edit

There was a small typo ... I fixed it, could you accept the answer as solution?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-08-07 02:16:05 -0500 )edit
1

Alright. Sorry I didn't realize that it was current_frame all the time. This time it worked nicely, but I still got the message "Failed to load OPENCL at runtime <expected version=1.1>"

Would be problematic in future?

Vizier87 gravatar imageVizier87 ( 2015-08-07 02:32:44 -0500 )edit

Hmm you can explicitly disable OpenCL at the top of your code. Look at the edited code again.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-08-07 02:40:26 -0500 )edit

Okay thanks. But the comment still persisted. I wonder. But if it ain't gonna be a problem then I'll proceed to the next tutorials. :)

Vizier87 gravatar imageVizier87 ( 2015-08-07 02:49:04 -0500 )edit

Hmm then I am afraid you tried to built OpenCV with OpenCL support but the OpenCL version on your system is not compatible. Normally this should not influence the other tutorials.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-08-07 02:52:15 -0500 )edit
1

I see. Thanks anyway bro!

Vizier87 gravatar imageVizier87 ( 2015-08-07 04:22:28 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-08-06 05:11:11 -0500

Seen: 900 times

Last updated: Aug 07 '15