qixiaoning
2025-07-08 84d2ef9760af0a4a4aa933937294400b3caa291d
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// Created by Scheaven on 2020/4/26.
//
 
#include "h_interface.h"
#include <opencv2/opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "log_util.h"
#include <string>
#include <list>
#include <algorithm>
#include <fstream>
#include <stdint.h>
#include <vector>
#include <thread>
#include <json/json.h>
#include "time.h"
#include "stdio.h"
#include "stdlib.h"
#include <iostream>
#include <sys/time.h>
#include "homography_util.h"
 
 
using namespace std;
 
COORDINATE_API char* transCoord(const char* data)
{
    Json::Reader reader;
    Json::Value root;
    vector<cv::Point> srcFPoint_vec;
    vector<cv::Point> dstFPoint_vec;
    if(reader.parse(data,root))
    {
        SLOG::getInstance()->addLog(0, "-----root----" + std::string(data));
        SLOG::getInstance()->addLog(0, "-----root.size()----" + to_string(root.size()));
        int point_count = root["coordTrans"].size();
        for (int i = 0; i < point_count; ++i)
        {
            cv::Point local_Point;
            cv::Point aerial_Point;
            local_Point.x = root["coordTrans"][i]["x0"].asFloat()*root["w"].asInt()/960;
            local_Point.y = root["coordTrans"][i]["y0"].asFloat()*root["h"].asInt()/540;
            aerial_Point.x = root["coordTrans"][i]["x1"].asFloat();
            aerial_Point.y = root["coordTrans"][i]["y1"].asFloat();
//                        printf("---local_Point-----%f--%f--%f--%f-\n", local_Point.x, local_Point.y, aerial_Point.x,aerial_Point.y);
            string pointJ ="---local_Point----" + to_string(local_Point.x) + ":" + to_string(local_Point.y) +  " aerial_Point: " + to_string(aerial_Point.x)  + ":" + to_string(aerial_Point.y);
            SLOG::getInstance()->addLog(0, pointJ);
            srcFPoint_vec.emplace_back(local_Point);
            dstFPoint_vec.emplace_back(aerial_Point);
        }
    }else
    {
//        delete reader;
        SLOG::getInstance()->addLog(0, "--Enter the correct polygon JSON format!!\n");
    }
 
 
    cv::Mat homography = cv::findHomography(srcFPoint_vec, dstFPoint_vec);
 
 
     SLOG::getInstance()->addLog(0, "--homography start--\n");
    for (int j = 0; j < homography.rows; ++j)
    {
        for (int k = 0; k < homography.cols; ++k)
        {
            SLOG::getInstance()->addLog(0,  to_string(homography.at<float>(j,k)) + " " );
        }
        SLOG::getInstance()->addLog(0,  "\n");
    }
    SLOG::getInstance()->addLog(0,  "--homography end--\n" );
 
    std::string result_json = "{\"result\":[";
    std::string tmp_json;
    for(auto& human_point:srcFPoint_vec)
    {
        cv::Point2f merge_p = getTransPoint(human_point, homography);
        result_json += "[\"x\":" + to_string(merge_p.x) + ",\"y\":" + to_string(merge_p.y)+"],";
    }
    result_json = result_json.substr(0,result_json.length()-1) + "}";
    SLOG::getInstance()->addLog(0,  "--result json: "+  result_json);
    return const_cast<char *>(result_json.c_str());
}