Ask Your Question
0

CvCapture* capture = cvCreateCameraCapture(0); is not working for me... c++ w10

asked 2016-08-03 13:39:59 -0600

Tharindu J gravatar image

updated 2016-08-06 12:21:58 -0600

berak gravatar image

but VideoCapture cap(0); is working for me..it opens the camera.. please anyone give solution..

#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <stdarg.h>

using namespace cv;
using namespace std;
int main( int argc, char** argv ) {
cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCaptureFromCAM(0);
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "Example2", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
}

above shows the code...but when cv: :videocapture used cvQueryFrame gets error as there are no pointer in use...how to solve this..?

edit retag flag offensive close merge delete

Comments

please try to use cv::VideoCapture , not the (deprecated c-api version)

berak gravatar imageberak ( 2016-08-03 13:52:30 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-08-06 12:31:25 -0600

berak gravatar image

updated 2016-08-06 12:33:50 -0600

you should probably stop trying with any outdated opencv1.0 c - based ideas, but use opencv2 style c++:

#include "opencv2/opencv.hpp"
using namespace cv;

int main(int argc, char **argv)
{
    Mat frame;
    VideoCapture cap;
    if (argc>1) cap.open(argv[1]); // some vid passed as cmdline arg
    else cap.open(0);              // by default use webcam
    while(cap.isOpened() && cap.read(frame))
    {
        //
        // process frame as you wish..
        //
        imshow("ocv",frame);
        if (waitKey(10)==27) break;
    }
}
edit flag offensive delete link more

Comments

ok...I'm using some old refference i guess so..do u know good book/site to reffer opencv c++ for beginers?

Tharindu J gravatar imageTharindu J ( 2016-08-06 12:56:03 -0600 )edit

yae, that's most likely the problem.

which opencv version do you use ?

berak gravatar imageberak ( 2016-08-06 12:58:58 -0600 )edit
Tharindu J gravatar imageTharindu J ( 2016-08-06 13:01:01 -0600 )edit

current docs are at http://docs.opencv.org/master/

have a look, at the "tutorials" section.

berak gravatar imageberak ( 2016-08-06 13:03:09 -0600 )edit

if you want my 2ct on "the book" - if you're unlucky to get version1.0 - it's still a great book, when it's about explaining things, you're just no more allowed to use the opencv1.0 example code in there.

berak gravatar imageberak ( 2016-08-06 13:10:10 -0600 )edit

ok..it is kind of dissapointment for me because that book has explained everything A-Z simply..

Tharindu J gravatar imageTharindu J ( 2016-08-06 13:21:28 -0600 )edit
berak gravatar imageberak ( 2016-08-06 23:34:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-08-03 13:39:59 -0600

Seen: 7,885 times

Last updated: Aug 06 '16