QT-- dynamic flow of people monitoring system

QT-- dynamic flow of people monitoring system


Summary:

  • The project uses a dynamic flow of people to monitor api Baidu's AI to human head and shoulders as the main objective to identify suitable for low-overhead, import and export scene, it can be used for statistical picture of the current number of locks and the number of passes

Item Function

  • This project is divided into a camera module and an image recognition module

    • The camera module

      • Use the two button multiplexing, a slider

      • Press to open the camera button, ready to start taking pictures, button becomes close camera button, and then click to turn off the camera.

      • Before turning on the camera, start button can not be used.

      • When you open the camera, press the start button, button becomes a Stop button, and began taking pictures, as is the dynamic monitoring of the flow of people, so the pumping frequency of Chen 5fps , is the need to upload five photos per second shooting, first need to open connections network, it may be a little slow.

      • Click on the slide bar in the beginning before can not be used, when started taking pictures, you can drag the slider switch windows interface, enter the monitor interface

    • Image recognition module

      • Image recognition module may be taken by uploading a photo camera module network for human identification number to determine the number of images designated area at the designated area of ​​the current, leaving the number of designated areas

      • After upload pictures to the network returns the number of available values ​​and rendering images displayed on the monitor screen

      • The picture will appear in the rectangular box is locked after human head

      • Left border for the specified area

      • Upper left corner of the screen respectively, of the total number of locks , enter the total number of designated areas , the total number of people leaving the designated area

      • The lower left corner to the open run number

1. pro file
+ = QT Core Network Multimedia multimediawidgets GUI
                      // Network will be added to HTTP communication
                      // Multimedia multimediawidgets camera will increase
2.widget.h file
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QCamera>
#include <QCameraViewfinder>
#include <QCameraImageCapture>
#include <QTimer>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QJsonObject>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent =nullptr a);
     ~ the Widget (); 

public : 
    QTimer * Timer; 
    Qcamera * Camera;               // system camera apparatus 
    QCameraViewfinder * Finder;     // camera viewfinder 
    QCameraImageCapture * Capture; // theme means 
    the QImage Image;                  // save the photo 
    BOOL Switch;                   // switch 
    int the Position;                  // save the value of the slider 
    the QImage IMG;                   // return to the photo 
    int INS = 0 ;                   //The number entered 
    int outs = 0 ;                  // leave the number of 

    void Photo ();                  // pictures 
    void Run the display ();                // display 
    void Photograph ();             // camera initialize 
    void cameraImageCaptured ( int the above mentioned id, QImage Image); // get photos 


/ * ******************* network **************************** ********* * / 
    QNetworkAccessManager * Manager;     // network access manager 
    QNetworkReply * reply;              // network reply
    QNetworkRequest *requst;           //网络请求
    bool connection = false;

    void initialization();            //网络
    void sendHTTP();                  //发送请求

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void on_horizontalSlider_sliderMoved(int position);

private:
    Ui::Widget *ui;
};

#endif // WIDGET_H
3.widget.cpp file
#include "widget.h"
#include "ui_widget.h"
#include <QBuffer>
#include <QByteArray>
#include <QImageReader>
#include <QJsonDocument>
#include <QJsonObject>
#include <QThread>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    photograph();        //相机
    initialization();    //网络

}

Widget::~Widget()
{
    delete ui;
}

//网络
void Widget::initialization()
{
    manager  = new QNetworkAccessManager(this);
    requst = new QNetworkRequest;

    QString request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/body_tracking";                   //填入百度AI的请求URL
    
    QString toke = "24.6878d2808d1dd6be2a3a760c82d0979a.2592000.1570716999.282335-17208954";                                     // Fill access_token Baidu AI, specifically to see Baidu AI documents 
    
    QString url = request_url + " access_token =? " + Toke;     // note format 
    requst-> setUrl (QUrl (url)); 
    requst -> setHeader ( :: ContentTypeHeader QNetworkRequest, " file application / X-WWW-form-urlencoded " );                                  // head can not be incorrectly the Type-the Content 
    Connect (Manager, & QNetworkAccessManager :: Finished, the this , 
            [ =] (* QNetworkReply Reply) 
            { 
                the QByteArray Array= reply->readAll();        //获取信息
                qDebug() << array;
                QJsonObject json1 = QJsonDocument::fromJson(array).object();
                QString image = json1.value("image").toString();

                QByteArray ba;                                     //解析返回渲染图
                ba.append(image);
                QByteArray ba1 = ba.fromBase64(ba);

                QBuffer buffer(&ba1);
                buffer.open(QIODevice::ReadOnly);
                QImageReader reader(&buffer,"jpg");
                img = reader.read();

                int person_num = json1.value("person_num").toInt();
                QJsonObject object = json1.value("person_count").toObject();
                qDebug() << object;
                int in = object.value("in").toInt();
                int out = object.value("out") .toInt (); 
                INS + = in ; 
                outs + = OUT ; 

                QString str = " Current number: " + QString :: Number The (person_num);       // returns the number of 
                ui-> label_2-> setText (str); 
                QString str1 = " The number of entering: " + QString :: number The (INS); 
                ui -> label_3-> setText (str1); 
                QString str2 = " left number: " + QString :: number The (outs); 
                ui -> label_4->setText(str2);

            });

}

//发送请求
void Widget::sendHTTP()
{
    QByteArray ba;
    QBuffer buf(&ba);
    Image.save(&buf, "jpg");

    QByteArray SendData = "";

    SendData.append("&dynamic=true");                      //封装发送信息
    SendData.append("&case_id=1");
    SendData.append("&case_init=false");
    SendData.append("&image=");
    SendData.append(ba.toBase64().toPercentEncoding());
    SendData.append("&show=true");
    SendData.append("&area=1,1,700,1,700,719,1,719");
    qDebug() << SendData;

    manager->post(*requst,SendData);

}

//相机初始化
void Widget::photograph()
{
    this->resize(640,450);                               //设置窗口大小

    camera = newQcamera ( the this );                           // system camera apparatus 
    Finder = new new QCameraViewfinder ( the this );                 // camera viewfinder member 
    Capture = new new QCameraImageCapture (Camera);            // screenshot member 
    Timer = new new QTimer ( the this ); 

    UI -> verticalLayout-> addWidget (Finder);                // add layout is Finder 
    ui-> label-> setMaximumSize ( 0 , 0 );                       // set the initial size of the photo 
    ui-> pushButton_2-> setEnabled ( to false );
 
    Switch = false ; 
    Position = 0 ; 

    Connect (the Timer, & QTimer :: timeout, the this , & Widget :: Photo); // monitor timer 
    Connect (Capture, & QCameraImageCapture :: imageCaptured, the this ,
             & Widget :: cameraImageCaptured);                                / / image capturing 
    the capture-> setCaptureDestination (QCameraImageCapture :: CaptureToFile);   // set to capture the object 
    CAMERA-> setCaptureMode (Qcamera :: CaptureStillImage);                   // camera configured to capture a still frame. 
    camera-> setViewfinder (finder);                                       // Set the finder 
} 

// camera 
void the Widget :: Photo () 
{ 
    Capture -> Capture ();              // camera 
    sendHTTP (); 
    the display ();                      // display 
} 

// get the image 
void the Widget :: cameraImageCaptured ( int ID, the QImage Image) 
{ 
    Image = Image; 
} 

// open the camera 
void the Widget :: on_pushButton_clicked () 
{ 
    IF (! Switch) 
    { 
        camera -> Start ();           // open the camera
        ui-> pushButton-> the setText ( " Close camera " ); 
        UI -> pushButton_2-> setEnabled ( to true );    // Open Button 
        Switch = to true ; 
    } 
    the else 
    { 
        Camera -> STOP (); 
        UI -> pushButton-> the setText ( " turning on the camera " ); 
        UI -> pushButton_2-> setEnabled ( to false ); 
        Switch = to false ;
       //   Connection = to false; 
    } 

} 

// timer photographing 
void Widget::on_pushButton_2_clicked()
{
    if(!timer->isActive())
    {
        timer->start(200);
        ui->pushButton_2->setText("停止");
    }
    else
    {
        timer->stop();
        ui->pushButton_2->setText("开始");
    }

}

//滑动切换
void Widget::on_horizontalSlider_sliderMoved(int position)
{
    Position = position;
    display();
}

//显示
void Widget::display()
{
    ui->horizontalSlider->setMinimum(0);
    ui->horizontalSlider->setMaximum(this->width());
    ui->label->setMaximumSize(Position * (16/9),Position);

    QPixmap pixmap = QPixmap::fromImage(img );
    QPixmap fitpixmap = pixmap.scaled(Position * (16/9),Position, Qt::KeepAspectRatio, Qt::SmoothTransformation);  // 按比例缩放
    ui->label->setPixmap(fitpixmap);
    qDebug() << Position;
}
4.widget.ui file
  • The left empty as a control bureau

  • Within the space on the right for a label

  • The current number, enter the number of people leaving the number three label

5. Note
  • QT compiled some version of the run, the following error can occur when connecting to the network

    qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed1
  • QT5.13 Currently I do not know how to solve

  • QT5.12 need to find the following two files in the installation directory QT    

  • Choose their own compiler and the same file, I was 64, just 64 of the selected file

  • Will find two files into the project executable files under the folder that bebug or release, then compile and run on it

Guess you like

Origin www.cnblogs.com/IntelligencePointer/p/11525172.html