Kaynağa Gözat

add project rstpview for view rtsp stream.

yuchuli 2 yıl önce
ebeveyn
işleme
97284b5adf

+ 2 - 2
src/tool/bqev_pcdview/main.cpp

@@ -79,8 +79,8 @@ int main(int argc, char *argv[])
     showversion("bqev_pcdview");
     QApplication a(argc, argv);
 
-//    snprintf(gstr_memname,255,"lidar_pc");
-    snprintf(gstr_memname,255,"lidarpc_center");
+    snprintf(gstr_memname,255,"lidar_pc");
+ //   snprintf(gstr_memname,255,"lidarpc_center");
 
     int nRtn = GetOptLong(argc,argv);
     if(nRtn == 1)  //show help,so exit.

+ 11 - 0
src/tool/rtspview/main.cpp

@@ -0,0 +1,11 @@
+#include "mainwindow.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+    MainWindow w;
+    w.show();
+
+    return a.exec();
+}

+ 133 - 0
src/tool/rtspview/mainwindow.cpp

@@ -0,0 +1,133 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+#include <QInputDialog>
+#include <iostream>
+
+#include <opencv2/opencv.hpp>
+#include <opencv2/core.hpp>
+
+MainWindow::MainWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+    mprtspdown = new rtspclientdown(mstrrtspurl);
+    mph264decode = new ivh264framedecode(mnframewidth,mnframeheight,false);
+
+    mpthreadframe = new std::thread(&MainWindow::threadframe,this);
+    mpthreadpic =new std::thread(&MainWindow::threadpic,this);
+
+    mmyview = new MyView(ui->centralWidget);
+    mmyview->setObjectName(QStringLiteral("graphicsView"));
+    mmyview->setGeometry(QRect(30, 30, 600, 600));
+    mmyview->setCacheMode(mmyview->CacheBackground);
+
+    mpsceneImg = new QGraphicsScene;
+
+    connect(this,SIGNAL(CamUpdate()),this,SLOT(onCamUpdate()));
+
+}
+
+MainWindow::~MainWindow()
+{
+    mbthreadrun = false;
+    mpthreadframe->join();
+    mpthreadpic->join();
+
+    delete mprtspdown;
+    delete ui;
+}
+
+void MainWindow::on_actionSet_URL_triggered()
+{
+    bool ok;
+    QString strurl = QInputDialog::getText(this,tr("Set URL:"),tr("URL:"),QLineEdit::Normal,mstrrtspurl.data(),&ok);
+
+    if(ok &!strurl.isEmpty())
+    {
+
+    }
+}
+
+void MainWindow::threadframe()
+{
+    while(mbthreadrun)
+    {
+        iv::h264rawframedata xframe;
+        if(mprtspdown->Getrtspframe(xframe,30) == 1)
+        {
+            iv::rawframedata xraw;
+            xraw.mpstr_ptr = xframe.mpstr_ptr;
+            xraw.ndatasize = xframe.mdatasize;
+            mph264decode->addframedata(xraw);
+        }
+    }
+}
+
+void MainWindow::threadpic()
+{
+
+    while(mbthreadrun)
+    {
+        int nindex = mph264decode->GetUpdatedIndex(10);
+        if(nindex<0)continue;
+//        std::cout<<" recv a yuv."<<std::endl;
+        iv::framedecodebuf * pbuf =  mph264decode->LockReadBuff(nindex);
+        int cy = pbuf->frameheight;
+        int cx = pbuf->framewidth;
+        cv::Mat rgbImg(cy, cx,CV_8UC3);
+
+
+        cv::cvtColor(pbuf->myuvImg, rgbImg,  CV_YUV2RGB_I420);
+
+        mph264decode->UnlockReadBuff(nindex);
+
+        QImage image2 = QImage((uchar*)(rgbImg.data), rgbImg.cols, rgbImg.rows,  QImage::Format_RGB888);
+
+        mMutexCam.lock();
+//        emit CamUpdate(ncampos,image2);
+        *mpImageCam = image2.copy();
+        mbCamUpdate = true;
+        mMutexCam.unlock();
+        emit CamUpdate();
+    }
+}
+
+void MainWindow::resizeEvent(QResizeEvent *event)
+{
+    (void)event;
+
+    QSize sizemain = ui->centralWidget->size();
+
+    mmyview->setGeometry(0,0,sizemain.width(),sizemain.height());
+
+    double fscale = (sizemain.width()*3/3)*1.0/mnframewidth;
+    double fscale2 = (sizemain.height()*3/3)*1.0/mnframeheight;
+    if(fscale > fscale2) fscale = fscale2;
+    fscale = fscale * 0.99;
+    mmyview->viewscaleto(fscale);
+}
+
+void MainWindow::onCamUpdate()
+{
+    update();
+}
+
+void MainWindow::paintEvent(QPaintEvent *)
+{
+
+    if(mbCamUpdate)
+    {
+        mMutexCam.lock();
+        mbCamUpdate = false;
+        mpsceneImg->clear();
+        mpsceneImg->addPixmap(QPixmap::fromImage(*mpImageCam));
+        mmyview->setScene(mpsceneImg);
+        mmyview->show();
+        mMutexCam.unlock();
+
+    }
+
+
+}

+ 64 - 0
src/tool/rtspview/mainwindow.h

@@ -0,0 +1,64 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include "rtspclientdown.h"
+#include "ivh264framedecode.h"
+#include "myview.h"
+
+#include <thread>
+
+#include <QMutex>
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit MainWindow(QWidget *parent = 0);
+    ~MainWindow();
+
+private slots:
+    void on_actionSet_URL_triggered();
+    void onCamUpdate();
+    virtual void paintEvent(QPaintEvent *);
+
+signals:
+    void CamUpdate();
+
+private:
+    Ui::MainWindow *ui;
+
+    rtspclientdown * mprtspdown;
+    ivh264framedecode * mph264decode;
+
+
+    std::string mstrrtspurl = "rtsp://111.33.136.149:9554/AAAAAAAAAAAAAAAAA-front-hello";
+    int mnframewidth = 1920;
+    int mnframeheight = 1080;
+
+private:
+    void threadframe();
+    void threadpic();
+
+    bool mbthreadrun = true;
+
+    std::thread * mpthreadframe, * mpthreadpic;
+
+    MyView * mmyview;
+    QGraphicsScene * mpsceneImg;
+
+    QImage * mpImageCam;
+    bool mbCamUpdate;
+    QMutex mMutexCam;
+
+public:
+     void resizeEvent(QResizeEvent *event);
+};
+
+#endif // MAINWINDOW_H

+ 62 - 0
src/tool/rtspview/mainwindow.ui

@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>600</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralWidget"/>
+  <widget class="QMenuBar" name="menuBar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>22</height>
+    </rect>
+   </property>
+   <widget class="QMenu" name="menuFile">
+    <property name="title">
+     <string>File</string>
+    </property>
+    <addaction name="actionSet_URL"/>
+   </widget>
+   <addaction name="menuFile"/>
+  </widget>
+  <widget class="QToolBar" name="mainToolBar">
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+   <addaction name="actionSet_URL"/>
+  </widget>
+  <widget class="QStatusBar" name="statusBar"/>
+  <action name="actionSet_URL">
+   <property name="icon">
+    <iconset resource="rtspview.qrc">
+     <normaloff>:/rtspurl.png</normaloff>:/rtspurl.png</iconset>
+   </property>
+   <property name="text">
+    <string>Set URL</string>
+   </property>
+   <property name="toolTip">
+    <string>Set RTSP URL</string>
+   </property>
+  </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources>
+  <include location="rtspview.qrc"/>
+ </resources>
+ <connections/>
+</ui>

+ 128 - 0
src/tool/rtspview/myview.cpp

@@ -0,0 +1,128 @@
+#include "myview.h"
+#include <QScrollBar>
+#include <iostream>
+#define VIEW_CENTER viewport()->rect().center()
+const double PI = 3.1415926535898;
+
+MyView::MyView(QWidget *parent) :
+     QGraphicsView(parent),
+    beishu(1.00000)
+{
+    setDragMode(QGraphicsView::ScrollHandDrag);
+}
+
+void MyView::mousePressEvent(QMouseEvent *event)
+{
+//    qDebug("x is %d",event->pos().x());
+    bottonstatus = true;
+    QGraphicsView::mousePressEvent(event);
+}
+void MyView::mouseMoveEvent(QMouseEvent *event)
+{
+    QGraphicsView::mouseMoveEvent(event);
+//    QScrollBar * ps = verticalScrollBar();
+//    std::cout<<" size is "<<ps->size().height()<<" v = "<<ps->value()<<std::endl;
+//    QScrollBar * ps2= horizontalScrollBar();
+//     std::cout<<" size is "<<ps2->size().width()<<" h = "<<ps2->value()<<std::endl;
+}
+void MyView::mouseReleaseEvent(QMouseEvent *event)
+{
+    bottonstatus = false;
+    QGraphicsView::mouseReleaseEvent(event);
+}
+
+// 放大/缩小
+void MyView::wheelEvent(QWheelEvent *event)
+{
+    // 滚轮的滚动量
+    QPoint scrollAmount = event->angleDelta();
+    // 正值表示滚轮远离使用者(放大),负值表示朝向使用者(缩小)
+    scrollAmount.y() > 0 ? zoomIn() : zoomOut();
+}
+
+
+// 放大
+void MyView::zoomIn()
+{
+
+    int width,hgt;
+    width = sceneRect().width();
+    hgt = sceneRect().height();
+    QScrollBar * psV = verticalScrollBar();
+    QScrollBar * psH = horizontalScrollBar();
+
+    int centery = (psV->value() + psV->size().height()/2)/beishu;
+    int centerx = (psH->value() + psH->size().width()/2)/beishu;
+
+    scale(1.1, 1.1);
+    beishu *= 1.1;
+ //   centerOn(450, 700 - (200 / beishu));
+
+
+
+
+
+    centerOn(centerx,centery);
+
+//    QPoint x = viewport()->rect().center();
+
+
+//    std::cout<<" x is"<<sceneRect().bottom()<<" y is "<<sceneRect().y()<<std::endl;
+//    QScrollBar * ps = verticalScrollBar();
+//    std::cout<<" size is "<<ps->size().height()<<" v = "<<ps->value()<<std::endl;
+
+}
+
+// 缩小
+void MyView::zoomOut()
+{
+
+    int width,hgt;
+    width = sceneRect().width();
+    hgt = sceneRect().height();
+    QScrollBar * psV = verticalScrollBar();
+    QScrollBar * psH = horizontalScrollBar();
+
+    int centery = (psV->value() + psV->size().height()/2)/beishu;
+    int centerx = (psH->value() + psH->size().width()/2)/beishu;
+
+    scale(1 / 1.1, 1 / 1.1);
+    beishu /= 1.1;
+//    centerOn(450, 700 - (200 / beishu));
+
+    centerOn(centerx,centery);
+}
+
+void MyView::mouseDoubleClickEvent(QMouseEvent *event)
+{
+
+    QScrollBar * psV = verticalScrollBar();
+    QScrollBar * psH = horizontalScrollBar();
+
+    int centery = (psV->value() + psV->size().height()/2)/beishu;
+    int centerx = (psH->value() + psH->size().width()/2)/beishu;
+
+
+//    qDebug("x is %d y is %d view center x is %d  centerx is %d",event->pos().x(),
+//           event->pos().y(),
+//           viewport()->rect().center().x(),centerx);
+
+    int viewx,viewy;
+    if(beishu == 0)return;
+    viewx = centerx +(event->pos().x() - viewport()->rect().center().x())/beishu;
+    viewy = centery +(event->pos().y() - viewport()->rect().center().y())/beishu;
+
+    QPoint viewpoint;
+    viewpoint.setX(viewx);
+    viewpoint.setY(viewy);
+
+//    qDebug("view x is %d view y is %d ",viewx,viewy);
+}
+
+void MyView::viewscaleto(double fratio)
+{
+    double fscale = fratio/beishu;
+    scale(fscale,fscale);
+    beishu *= fscale;
+    centerOn(450, 700 - (200 / beishu));
+}

+ 36 - 0
src/tool/rtspview/myview.h

@@ -0,0 +1,36 @@
+#ifndef MYVIEW_H
+#define MYVIEW_H
+
+#include <qtimer.h>
+#include <qpainter.h>
+#include <QGraphicsView>
+#include <QWheelEvent>
+#include <QKeyEvent>
+#include <QPoint>
+#include <QPointF>
+#include <QGraphicsItem>
+#include <QKeyEvent>
+
+class MyView : public QGraphicsView
+{
+    Q_OBJECT
+
+public:
+    explicit MyView(QWidget *parent =0);
+    qreal x, y, beishu;
+    void viewscaleto(double fratio);
+protected:
+    void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
+    void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+    void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+    void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+    void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+public Q_SLOTS:
+    void zoomIn();  // 放大
+    void zoomOut();  // 缩小
+private:
+    bool bottonstatus = false;
+    QPoint myview_lastMousePos;
+};
+
+#endif // MYVIEW_H

BIN
src/tool/rtspview/rtspurl.png


+ 63 - 0
src/tool/rtspview/rtspview.pro

@@ -0,0 +1,63 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2022-06-29T09:17:06
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = rtspview
+TEMPLATE = app
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which has been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+
+SOURCES += \
+        main.cpp \
+    ../../driver/driver_h264_dec/ivh264framedecode.cpp \
+    ../RemoteCtrl_h264/rtspclientdown.cpp \
+        mainwindow.cpp \
+    myview.cpp
+
+HEADERS += \
+        mainwindow.h  \
+    ../../driver/driver_h264_dec/ivh264framedecode.h \
+    ../RemoteCtrl_h264/rtspclientdown.h \
+    myview.h
+
+FORMS += \
+        mainwindow.ui
+
+RESOURCES += \
+    rtspview.qrc
+
+#DEFINES += USEJPEG_NOOPENCV
+
+INCLUDEPATH += $$PWD/../../driver/driver_h264_dec
+INCLUDEPATH += $$PWD/../RemoteCtrl_h264
+
+INCLUDEPATH +=  D:\ffmpegwin\include
+
+unix:LIBS += -ldl -lrt
+
+INCLUDEPATH += /usr/include/x86_64-linux-gnu
+unix:LIBS +=  -lavcodec -lavformat -lavutil
+win32:LIBS += -LD:\ffmpegwin\bin
+win32:LIBS += -lavcodec-58 -lavformat-58 -lavutil-56  -lwsock32 -lws2_32
+
+INCLUDEPATH += /usr/include/opencv4
+
+LIBS += -lopencv_highgui -lopencv_core -lopencv_imgproc -lopencv_imgcodecs -lopencv_video  -lopencv_videoio -lpthread #-lopencv_shape
+
+

+ 5 - 0
src/tool/rtspview/rtspview.qrc

@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>rtspurl.png</file>
+    </qresource>
+</RCC>