Zoom QCameraViewfinder Video possible?



  • Hi there,

    I have a simple app that shows me the live video of a webcam
    that looks through my telescope.

    I use a QCamera and a QCameraViewfinder object to view the live
    video from /dev/video0. The QCameraViewfinder is limited in size with 375x380. The video is set to 640x480. Of cause it gets squashed within the viewfinder dimension. But I am interested in the area around the circle (the red square). Is there any way to zoom into the red square triggered by a push button?
    image of the app

    I just stumbled upon the QGraphicsVideoItem that has a "setScale" Attribute. Is that the right way? But if yes how do I connect my QCamera to a QGraphicsVideoItem?

    EDIT:
    Here's some code that I use to build my camera:

            camera = new QCamera("/dev/video0");
    	cameraVf = new QCameraViewfinder(frame4);
    	camera->setViewfinder(cameraVf);
    	cameraVf->setGeometry(5,40,375,380);
    	QCameraViewfinderSettings vfsettings;
    	vfsettings.setPixelFormat(QVideoFrame::Format_YUV420P);
    	vfsettings.setResolution(640,480);
    	camera->setViewfinderSettings(vfsettings);
    	cameraVf->show();
    


  • I think I found a solution. I roughly quadrupled the QCameraViewfinder size and repositioned it to the middle.
    Its all done with "cameraVf->setGeometry(x,y,x,y);". And I parented the viewfinder to a new QFrame
    to have a frame and to have the viewfinder not overlaying the start button.

    alt text

    mainwindow.cpp

    ...
            QFrame *frameVideo = new QFrame(frame4);		// extra frame where the video is in
    	frameVideo->setGeometry(5,35,375,380);
    	
    	camera = new QCamera("/dev/video0");
    	cameraVf = new QCameraViewfinder(frameVideo);
    	camera->setViewfinder(cameraVf);
    	cameraVf->setGeometry(0,0,375,380);
    	QCameraViewfinderSettings vfsettings;
    	vfsettings.setPixelFormat(QVideoFrame::Format_YUV420P);
    	vfsettings.setResolution(640,480);
    	camera->setViewfinderSettings(vfsettings);
    	cameraVf->show();
    ...
    
    void MainWindow::onZoomClicked(){
    	if(cameraVf->width() != 1600)
    	{
    		cameraVf->setGeometry(-590,-490,1600,1440);  // zoom in
    	}
    	else
    	{
    		cameraVf->setGeometry(0,0,375,380);		// zoom out
    	}
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.