0

I've decided no to use OpenCV. I will use the QCamera class. Everything is working perfect to this moment. I can capture and save images wherever I want, but the problem is how I can set the camera to a label or graphics view?

I mean, to see what is happening at the moment. When I make infinite loop everything crashes. Write any information you know, cause there are no examples how to do that, or I just can't see. If you can please write some source code.

Mat
  • 202,337
  • 40
  • 393
  • 406
Rado G
  • 87
  • 1
  • 5
  • 14
  • "Write any information you know"... eh that's going to take a while given the hundreds of thousands of SO users and the average amount of knowledge a human being has... Please show the relevant parts of the code you have that is "crashing", and explain exactly what "crashing" means (what behavior you see) so that people can help you fix it. – Mat Jun 30 '13 at 10:49
  • void Dialog::on_pushButton_clicked() //start capturing { camera->start(); while(1){ camera->searchAndLock(); imageCapture->capture(imagePath); ui->label->setPixmap(QPixmap(imagePath)); camera->unlock(); } } – Rado G Jun 30 '13 at 11:48
  • Never use infinite loop with Qt. Use events instead. [QTimer](http://qt-project.org/doc/qt-5.0/qtcore/qtimer.html) is most probably what you need. –  Jun 30 '13 at 12:04
  • 1
    @user2521257: please [edit] your post to add the code in there. (Take care to format it as code, read the editor help for guidance.) Never post code in comments, it's unreadable. – Mat Jun 30 '13 at 12:23
  • Thank you all for helping me.I will see what i can do now.Roku i was not pretty sure to this moment is there a problem to use infinite loop in QT, but now i know.There is always problem with the infinite loop in QT. – Rado G Jun 30 '13 at 12:50

1 Answers1

2

Use QCameraVievFinder or QVideoWidget widgets ( docs - here) for that purpose, here is example for you:

#include <QCameraViewfinder>

// .......   
QCamera *camera=new QCamera(this);
QCameraViewfinder *viewfinder = new QCameraViewfinder(this);
viewfinder->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
camera->setViewfinder(viewfinder);

setCentralWidget(viewfinder);
//viewfinder->show();

camera->start(); // to start the viewfinder

Note: you need to add to your *,pro file this config to use them: QT += multimedia multimediawidgets

If you want a bit more low level widget (to process every frame the way you like (face detection etc), subclass QAbstractVideoSurface, docs - here or try to connect to QVideoProbe class (docs - here), though i could not do it myself, this class is a bit experimental i guess, didn't worked

Shf
  • 3,463
  • 2
  • 26
  • 42
  • Shf, thanks for the answer.I 've heard about QCameraViewFinder before but i didn't read anything.Now i will look what i can do with it.Thanks – Rado G Jun 30 '13 at 12:51
  • @user2521257 glad to be helpfull, upvote & accept if it solves your problem – Shf Jun 30 '13 at 13:00
  • After this day, my problem with the camera was totally solved.There are no more problems.Now i will continue my GUI project thanks to all of you guys.After 1-2 months i will start searching for how to write printer driver ;), but however.Thanks too all again. ;) – Rado G Jun 30 '13 at 21:15