File size: 1,974 Bytes
1bfe214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include <string>
#include <filesystem>
#include <fstream>
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "jsoncpp/json/json.h"
#include "../../../libvideo_compensator/include/seq_compensator.h"

namespace fs = std::experimental::filesystem;
static const std::string strTestFolder{"D:\\myProject\\VideoCompensator\\test\\test_video_compensator\\data"};

namespace Ivs
{
inline std::vector<cv::Rect> LoadJsonMeta(const std::string& strFilePath)
{
    std::ifstream fInput{ strFilePath };
    Json::Value root;
    Json::Reader reader;
    std::vector<cv::Rect> vecRectObjects;

    if (reader.parse(fInput, root))
    {
        for (auto& obj : root)
        {
            cv::Rect rectObject;
            rectObject.x = obj["X"].asInt();
            rectObject.y = obj["Y"].asInt();
            rectObject.width = obj["Width"].asInt();
            rectObject.height = obj["Height"].asInt();
            vecRectObjects.emplace_back(rectObject);
        }
    }

    return std::move(vecRectObjects);
}

inline std::vector<TInputImageMeta> ReadImageMeta(const std::string& strTestFolder)
{
    std::vector<TInputImageMeta> vecSequenceInput;
    auto itFiles = fs::directory_iterator{ strTestFolder };

    for (auto& itFile : itFiles)
    {
        if (itFile.path().extension() == ".png")
        {
            TInputImageMeta tInput;
            auto pathFile = itFile.path();
            std::string strFileName = pathFile.stem().string();
            auto pathJsonFile = pathFile.parent_path() / fs::path{ strFileName + ".json" };

            tInput.matImage = cv::imread(itFile.path().string());
            tInput.vecObjRegions = LoadJsonMeta(pathJsonFile.string());

            for (auto& rect : tInput.vecObjRegions)
            {
                cv::rectangle(tInput.matImage, rect, { 255, 0, 0 });
            }

            vecSequenceInput.emplace_back(tInput);
        }
    }

    return std::move(vecSequenceInput);
}


}