Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

since you're just starting with opencv, try to avoid the old c-api, support for that is fading away quickly. try to use proper c++ for this, avoid IplImages and cv*Functions in general:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"

using namespace cv;

int main()
{
    VideoCapture cap(0);
    if ( ! cap.isOpened() )
         return;
    Size size( cap.get(CV_CAP_PROP_FRAME_WIDTH) / 2, 
               cap.get(CV_CAP_PROP_FRAME_HEIGHT) / 2 );
    Mat frame;
    while ( cap.read(frame) )
    {
        imshow("lalala",frame);
        int k = waitKey(10);
        if ( k==27 )
            break;
    }
    return 0;
}

since you're just starting with opencv, try to avoid the old c-api, support for that is fading away quickly. try to use proper c++ for this, avoid IplImages and cv*Functions in general:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"

using namespace cv;

int main()
{
    VideoCapture cap(0);
    if ( ! cap.isOpened() )
         return;
    Size size( cap.get(CV_CAP_PROP_FRAME_WIDTH) / 2, 
               cap.get(CV_CAP_PROP_FRAME_HEIGHT) / 2 );
    Mat frame;
    while ( 1 )
    {
        if ( cap.read(frame) )
     {
            // processing here
            imshow("lalala",frame);
        }
        int k = waitKey(10);
        if ( k==27 )
            break;
    }
    return 0;
}

since you're just starting with opencv, try to avoid the old c-api, support for that is fading away quickly. try to use proper c++ for this, avoid IplImages and cv*Functions in general:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"

using namespace cv;

int main()
{
    VideoCapture cap(0);
    if ( ! cap.isOpened() )
         return;
    Size size( cap.get(CV_CAP_PROP_FRAME_WIDTH) / 2, 
               cap.get(CV_CAP_PROP_FRAME_HEIGHT) / 2 );
    Mat frame;
    while ( 1 )
    {
        if ( cap.read(frame) )
        {
            // processing here
            imshow("lalala",frame);
        }
        int k = waitKey(10);
        if ( k==27 )
) // 'esc' pressed
            break;
    }
    return 0;
}