// // Created by Scheaven on 2020/4/26. // #include "h_interface.h" #include #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "log_util.h" #include #include #include #include #include #include #include #include #include "time.h" #include "stdio.h" #include "stdlib.h" #include #include #include "homography_util.h" using namespace std; COORDINATE_API char* transCoord(const char* data) { Json::Reader reader; Json::Value root; vector srcFPoint_vec; vector 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(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(result_json.c_str()); }