mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
update videotest5 code.
This commit is contained in:
parent
248bd8397e
commit
5ebd3df8bd
@ -6,9 +6,27 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui ( new Ui::MainWindow )
|
||||
{
|
||||
ui->setupUi ( this );
|
||||
|
||||
manager = new QQtV4L2VideoManager ( this );
|
||||
connect ( manager, SIGNAL ( readyRead ( QImage ) ), this, SLOT ( slotCaptured ( QImage ) ) );
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_clicked()
|
||||
{
|
||||
manager->startCapture();
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_2_clicked()
|
||||
{
|
||||
manager->stopCapture();
|
||||
}
|
||||
|
||||
void MainWindow::slotCaptured ( const QImage& img )
|
||||
{
|
||||
ui->widget->setPixmap ( img );
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <qqtv4l2videomanager.h>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@ -15,8 +16,15 @@ public:
|
||||
explicit MainWindow ( QWidget* parent = 0 );
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
void on_pushButton_2_clicked();
|
||||
|
||||
void slotCaptured ( const QImage& img );
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
|
||||
QQtV4L2VideoManager* manager;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -6,20 +6,52 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>176</width>
|
||||
<height>328</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>videotest5</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget"/>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QQtWidget" name="widget" native="true"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<width>176</width>
|
||||
<height>17</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -35,6 +67,14 @@
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QQtWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qqtwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -1,18 +1,21 @@
|
||||
#include <qqtv4l2videomanager.h>
|
||||
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
QQtV4L2VideoManager::QQtV4L2VideoManager ( QObject* parent ) : QObject ( parent )
|
||||
{
|
||||
handler = 0;
|
||||
pp = 0;
|
||||
frame = 0;
|
||||
|
||||
mDevName = "/dev/video0";
|
||||
mSize = QSize ( 720, 480 );
|
||||
mFormat = 0; //NV21? YUV? RGB?
|
||||
mRate = 30;
|
||||
mFormat = V4L2_PIX_FMT_NV21; //NV21? YUV? RGB?
|
||||
mRate = 10;
|
||||
|
||||
timer = new QTimer ( this );
|
||||
timer->setSingleShot ( false );
|
||||
timer->setInterval(200);
|
||||
timer->setInterval ( 100 );
|
||||
connect ( timer, SIGNAL ( timeout() ), this, SLOT ( slotGetCapture() ) );
|
||||
}
|
||||
|
||||
@ -42,11 +45,13 @@ void QQtV4L2VideoManager::startCapture()
|
||||
{
|
||||
if ( handler )
|
||||
capture_close ( handler );
|
||||
|
||||
struct cap_param param;
|
||||
param.dev_name = mDevName.toLocal8Bit().data();
|
||||
param.width = mSize.width();
|
||||
param.height = mSize.height();
|
||||
param.rate = mRate;
|
||||
param.pixfmt = mFormat;
|
||||
handler = capture_open ( param );
|
||||
|
||||
pp = ( unsigned char* ) malloc ( param.width * param.height * 3 * sizeof ( char ) );
|
||||
@ -56,8 +61,14 @@ void QQtV4L2VideoManager::startCapture()
|
||||
|
||||
void QQtV4L2VideoManager::stopCapture()
|
||||
{
|
||||
timer->stop();
|
||||
|
||||
if ( handler )
|
||||
capture_close ( handler );
|
||||
if ( pp )
|
||||
free ( pp );
|
||||
if ( frame )
|
||||
delete frame;
|
||||
}
|
||||
|
||||
int QQtV4L2VideoManager::convert_yuv_to_rgb_pixel ( int y, int u, int v )
|
||||
|
Loading…
x
Reference in New Issue
Block a user