main.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3. #include <opencv2/core/core.hpp>
  4. #include <opencv2/highgui/highgui.hpp>
  5. #include <opencv2/videoio/videoio.hpp>
  6. #include <QDebug>
  7. int main(int argc, char *argv[])
  8. {
  9. QApplication a(argc, argv);
  10. //jMainWindow w;
  11. //w.show();
  12. cv::Mat frame;
  13. //--- INITIALIZE VIDEOCAPTURE
  14. cv::VideoCapture cap;
  15. // open the default camera using default API
  16. // cap.open(0);
  17. // OR advance usage: select any API backend
  18. int deviceID = 0; // 0 = open default camera
  19. int apiID = cv::CAP_ANY; // 0 = autodetect default API
  20. // open selected camera using selected API
  21. cap.open(deviceID, apiID);
  22. // check if we succeeded
  23. if (!cap.isOpened()) {
  24. qDebug() << "ERROR! Unable to open camera";
  25. return a.exec();
  26. }
  27. qDebug() << "Camera Open !";
  28. //--- GRAB AND WRITE LOOP
  29. qDebug() << "Start grabbing";
  30. qDebug() << "Press any key to terminate";
  31. //for (;;)
  32. //{
  33. // wait for a new frame from camera and store it into 'frame'
  34. cap.read(frame);
  35. // check if we succeeded
  36. if (frame.empty()) {
  37. qDebug() << "ERROR! blank frame grabbed\n";
  38. //break;
  39. }
  40. else {
  41. // show live and wait for a key with timeout long enough to show images
  42. imshow("Live", frame);
  43. // if (cv::waitKey(5) > = 0)
  44. //b break;
  45. qDebug() << "FLUX !!\n";
  46. }
  47. // }
  48. // the camera will be deinitialized automatically in VideoCapture destructor
  49. return a.exec();
  50. }