Ask Your Question
0

transform camera resolution in opencv

asked 2013-02-19 09:46:01 -0600

Ahsin gravatar image

updated 2013-02-19 10:42:55 -0600

berak gravatar image

I'm using a web cam of resolution 640x480 and I want to increase the resolution to 1024x768 so that the camera video can come up on the full screen. I'm sending you a sample code and please check and give me feedback.

Note: I'm using version 2.3 of OPENCV on Visual Sudio C++ (2010)

CODE:

#include <WINDOWS.H>
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
CvFont font;
IplImage* frame = 0;
CvCapture* capture;

using namespace std;

int main()
{
    CvCapture* capture=cvCreateCameraCapture(0);
    cvNamedWindow("Cam Feed",CV_WINDOW_NORMAL);

    while(1)
    {
        //Getting the present frame
        frame=cvQueryFrame(capture);

        capture = cvCreateCameraCapture(0);

        cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 1024 );

        cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 768 );

        cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, 5);

        frame = cvQueryFrame(capture);
        printf("camera: %f x %f\n", cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH),cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT));
        BattleMenu();

        cvResizeWindow("Cam Feed", 1024, 768);

        cvMoveWindow("Cam Feed", 400, 130);
        cvWaitKey(1);
        cvShowImage("Cam Feed",frame);
    }

    /* free memory */
    cvDestroyWindow( "Cam Feed" );
    cvReleaseCapture( &capture );

    return 0;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-02-19 10:50:21 -0600

berak gravatar image

maybe your camera does not support your desired resolution ?

if all you want, is to watch your movie fullscreen, there's an easy way (without changing the resolution):

// CV_WINDOW_NORMAL is important here, since CV_WINDOW_AUTOSIZE won't let you resize(to full)
namedWindow("Cam Feed",CV_WINDOW_NORMAL);  

// now make it fullscreen:
setWindowProperty("Cam Feed", CV_WND_PROP_FULLSCREEN, 1.0);
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-19 09:46:01 -0600

Seen: 2,028 times

Last updated: Feb 19 '13