Camera Control Based on Qt + OpenCV in Ubuntu

Source: Internet
Author: User
Environment: it is easy to control the camera under Ubuntu10.04 + OpenCV2.2.0 + Qt4.7.0OpenCV. The highgui library provided can control the camera by calling the v4l2 mechanism of linux itself. here I am mixed programming with qt, and open a 30 ms timer in qt, constantly capturing images through the camera, this 30 ms is the frame rate. The captured image is of the IplImage type in OpenCV. Calling the image in qt is generally of the QImage type.

Environment: Ubuntu 10.04 + OpenCV2.2.0 + Qt4.7.0

It is easy to control the camera under OpenCV. The highgui library provided can control the camera by calling the v4l2 mechanism of linux itself. here I am mixed programming with qt, and open a 30 ms timer in qt, constantly capturing images through the camera, this 30 ms is the frame rate.

The captured image is of the IplImage type in OpenCV. Calling the image in qt is generally of the QImage type. Therefore, a format conversion is required, and the color of the captured image is BGR, you need to convert the city to RGB. The image display window captured by the camera is a QWidget.

Source code:

Widget. h

  1. # Ifndef WIDGET_H
  2. # Define WIDGET_H
  3. # Include
  4. # Include "iostream"
  5. # Include "stdio. h"
  6. # Include "highgui. h"
  7. # Include "cv. h"
  8. # Include
  9. # Include
  10. # Include
  11. Using NamespaceStd;
  12. # Define TIME_OUT 30 // specifies the video playback interval.
  13. # Define FPS 30 // playback frame rate
  14. NamespaceUi {
  15. ClassWidget;
  16. }
  17. ClassWidget:PublicQWidget
  18. {
  19. Q_OBJECT
  20. Public:
  21. ExplicitWidget (QWidget * parent = 0 );
  22. ~ Widget ();
  23. Private:
  24. Ui: Widget * ui;
  25. CvCapture * capture;// Video data structure
  26. IplImage * frame;
  27. QTimer * timer;
  28. QImage * img;
  29. PrivateSlots:
  30. VoidSlot_timer ();
  31. Protected:
  32. VoidPaintEvent (QPaintEvent *);
  33. };
  34. # Endif // WIDGET_H

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.