Untitled
raw download clone
TEXT
views 85
,
size 5937 b
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include <opencv2/imgproc.hpp>
#include <string>
#include <chrono>
#include <sys/types.h>
#include <sys/stat.h>
#include <iostream>
#include <memory>
#include <string>
#include <fstream>
#include <time.h>
#include <chrono>
#include <ctime>

#include <dlib/dnn.h>
#include <dlib/image_processing.h>
#include <dlib/image_io.h>
#include <dlib/opencv/cv_image.h>
#include <dlib/opencv.h>
#include <dlib/gui_widgets.h>
#include <dlib/clustering.h>
#include <dlib/config_reader.h>

#include <jsoncpp/json/json.h>
#include <jsoncpp/json/value.h>
#include <jsoncpp/json/writer.h>

#include "../include/detection/darknet.hpp"
#include "../include/connectCMS/connectCMS.h"
#include "../include/connectAPI/connectAPI.h"
#include "../include/storageData/storageData.h"
#include "../include/tracker/Dtracker.hpp"

#include <iostream>
#include <thread>
#include <mutex>
#include <exception>

#include "VideoReader.h"
#include "PlateReader.h"
#include "PlateRecognizator.h"
#include "PlateRecognitionAction.h"
#include "publicValue.h"
#include "../include/ecovisonyolo.hpp"


ConnectCMS cmsVideo;

std::vector<double> endgrid, divgrid, l1, v1, v2;
double scale111;
extern int video_width, video_height;

std::queue<FrameData> frameQueue;
std::mutex frameQueueMutex;

//Mode: kinds plate
//0: While square
//1: While long
//2: BlueRed square
//3: BlueRed long

QueuePlates plateQueue;
std::queue<PlateData> plateQueue_showFrame;
std::mutex plateQueue_showFrameMutex;
std::queue<image_details> OnvifDetailsQueue;

pr::ObjectUtils objects;

void showFrame(int FrameIgnored2, int fps) {
    int nframe = 0;
    auto start = CLOCK_NOW();
    int delay = 1000 / fps * FrameIgnored2;
    while (true) {
        std::this_thread::sleep_for(std::chrono::milliseconds(1));
        auto startime = CLOCK_NOW();
        if (plateQueue_showFrame.empty())
            continue;
        plateQueue_showFrameMutex.lock();
        PlateData data = plateQueue_showFrame.front();
        plateQueue_showFrame.pop();
        plateQueue_showFrameMutex.unlock();

        cv::Mat frame = data.frame.clone();
        cv::resize(frame, frame, cv::Size(), 0.4, 0.4);
        cmsVideo.push_frame_info_into_cms(frame.clone());
        cv::imshow("Plate Regconition", frame);
        cv::waitKey(1);
        nframe++;
        auto end = CLOCK_NOW();
        pr::ElapsedTime elapsed = end - start;
        if (nframe % 100 == 0) {
            //cout << " display fps=" << nframe / elapsed.count() << endl;
        }
        while (1) {
            auto endtime = CLOCK_NOW();
            pr::ElapsedTime elapsedtime = endtime - startime;
            if (elapsedtime.count() * 1000 < delay)
                std::this_thread::sleep_for(std::chrono::milliseconds(1));
            else break;
        }
    }
}

int main(int argc, char **argv) {
//    std::string linkFileConfig = argv[1];
//    cout << linkFileConfig << endl;

    std::string linkFileConfig = "/media/dannv/Data/SourceCode/ecovision-plate-recognition/ecovision_engine/data/Config1.txt";
    dlib::config_reader cr("../data/config.txt");

    int cropX = stoi(cr["cropX"]);
    int cropY = stoi(cr["cropY"]);
    int cropWidth = stoi(cr["cropWidth"]);
    int cropHeight = stoi(cr["cropHeight"]);
    int showVideo = stoi(cr["showVideo"]);

    int videoWidth = stoi(cr["video_width"]);
    int videoHeight = stoi(cr["video_height"]);

    int frameIgnored = stoi(cr["FrameIgnored"]);
    int fpsReading = stoi(cr["fps_video_reading"]);

    std::string input_cfg_file = cr["cfg"];
    std::string input_weights_file = cr["weight"];
    std::string input_names_file = cr["coco"];

    std::string url = cr["url"];

    EcovisionYoloV3Params params;


    params.datacfg = input_names_file.c_str();
    params.cfgfile = input_cfg_file.c_str();
    params.weightfile = input_weights_file.c_str();
    params.nms = 0.4;
    params.maxClasses = 2;

    int expectedW = 0, expectedH = 0;
    EcoYolo::EcovisionYoloV3 *p = new EcoYolo::EcovisionYoloV3();
    p->Setup(params, expectedW, expectedH);

    cv::Rect cropRect;
    cropRect = cv::Rect(cropX, cropY, cropWidth, cropHeight);
    pr::VideoReader VideoReader(url, videoWidth, videoHeight, cropRect, frameQueue, linkFileConfig);

    pr::PlateReader plateReader(
            cropRect,
            frameQueue,
            frameQueueMutex,
            plateQueue,
            OnvifDetailsQueue,
            plateQueue_showFrame,
            plateQueue_showFrameMutex,
            linkFileConfig,
            showVideo);

    pr::PlateRecognitionAction PlateRecognitionAction(
            cropRect,
            plateQueue,
            linkFileConfig);

    int base_video_width = 1280;
    int base_video_height = 960;

//    scout << videoWidth << " " << videoHeight << endl;

    double scale_video_x = (float) videoWidth / base_video_width;
    double scale_video_y = (float) videoWidth / base_video_height;
    scale111 = stof(cr["scale_speed"]);
    endgrid.push_back(0 * scale_video_x);
    endgrid.push_back(960 * scale_video_y);
    divgrid.push_back(1533 * scale_video_x);
    divgrid.push_back(-264.147 * scale_video_y);
    l1.push_back(960 * scale_video_y);
    l1.push_back(-0.79853 * scale_video_y / scale_video_x);
    v1.push_back(1633 * scale_video_x);
    v1.push_back(-344 * scale_video_y);
    v2.push_back(12099 * scale_video_x);
    v2.push_back(300 * scale_video_y);

    std::vector<std::thread> ths;
    ths.push_back(std::thread(VideoReader));
    ths.push_back(std::thread(plateReader));
    ths.push_back(std::thread(PlateRecognitionAction));
    if (showVideo)
        ths.push_back(std::thread(showFrame, frameIgnored, fpsReading));
    for (auto &t : ths)
        t.join();
}
close fullscreen
Login or Register to edit or fork this paste. It's free.