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
- # Ifndef WIDGET_H
- # Define WIDGET_H
- # Include
- # Include "iostream"
- # Include "stdio. h"
- # Include "highgui. h"
- # Include "cv. h"
- # Include
- # Include
- # Include
- Using NamespaceStd;
- # Define TIME_OUT 30 // specifies the video playback interval.
- # Define FPS 30 // playback frame rate
- NamespaceUi {
- ClassWidget;
- }
- ClassWidget:PublicQWidget
- {
- Q_OBJECT
- Public:
- ExplicitWidget (QWidget * parent = 0 );
- ~ Widget ();
- Private:
- Ui: Widget * ui;
- CvCapture * capture;// Video data structure
- IplImage * frame;
- QTimer * timer;
- QImage * img;
- PrivateSlots:
- VoidSlot_timer ();
- Protected:
- VoidPaintEvent (QPaintEvent *);
- };
- # Endif // WIDGET_H