|
|
#include "lpGlobalConfig.h"
|
|
|
#include <QApplication>
|
|
|
#include <QFile>
|
|
|
#include <QJsonObject>
|
|
|
#include <QJsonDocument>
|
|
|
#include <QJsonArray>
|
|
|
#include <opencv.hpp>
|
|
|
using namespace cv;
|
|
|
lpGlobalConfig::lpGlobalConfig(QObject *parent)
|
|
|
: QObject(parent)
|
|
|
{
|
|
|
m_rootPath = QApplication::applicationDirPath();
|
|
|
}
|
|
|
|
|
|
lpGlobalConfig::~lpGlobalConfig()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
void lpGlobalConfig::readConfig()
|
|
|
{
|
|
|
QString strPath = m_rootPath + "/user/globalConfig.json";
|
|
|
QFile file(strPath);
|
|
|
if (true == file.open(QIODevice::ReadOnly))
|
|
|
{
|
|
|
QByteArray readData = file.readAll();
|
|
|
QJsonObject rootObj = QJsonDocument::fromJson(readData).object();
|
|
|
if (!rootObj.isEmpty())
|
|
|
{
|
|
|
QString strCam1 = rootObj.value("station_camkey_1").toString();
|
|
|
QString strCam2 = rootObj.value("station_camkey_2").toString();
|
|
|
QString strSolution1 = rootObj.value("station_solution_1").toString();
|
|
|
QString strSolution2 = rootObj.value("station_solution_2").toString();
|
|
|
QString strRunModel1 = rootObj.value("station_runModel_1").toString();
|
|
|
QString strRunModel2 = rootObj.value("station_runModel_2").toString();
|
|
|
m_StationXYTrans_1 = rootObj.value("station_xytrans_1").toBool();
|
|
|
m_StationXYTrans_2 = rootObj.value("station_xytrans_2").toBool();
|
|
|
m_StationCamKey_1 = strCam1;
|
|
|
m_StationCamKey_2 = strCam2;
|
|
|
m_StationSolution_1 = strSolution1;
|
|
|
m_StationSolution_2 = strSolution2;
|
|
|
m_StationRunModel_1 = strRunModel1;
|
|
|
m_StationRunModel_2 = strRunModel2;
|
|
|
|
|
|
m_bOnlineMode = rootObj.value("onlineMode").toBool(false);
|
|
|
|
|
|
int p1x_1 = rootObj.value("point1_x_1").toInt(0);
|
|
|
int p1y_1 = rootObj.value("point1_y_1").toInt(0);
|
|
|
int p2x_1 = rootObj.value("point2_x_1").toInt(100);
|
|
|
int p2y_1 = rootObj.value("point2_y_1").toInt(100);
|
|
|
double length_1 = rootObj.value("length_1").toDouble(1000);
|
|
|
point1_1.setX(p1x_1);
|
|
|
point1_1.setY(p1y_1);
|
|
|
point2_1.setX(p2x_1);
|
|
|
point2_1.setY(p2y_1);
|
|
|
fLength_1 = length_1;
|
|
|
m_StationScale_1 = rootObj.value("StationScale_1").toDouble(1.0);
|
|
|
m_StationXOffset_1 = rootObj.value("StationXOffset_1").toDouble(0.0);
|
|
|
m_StationYOffset_1 = rootObj.value("StationYOffset_1").toDouble(0.0);
|
|
|
|
|
|
int p1x_2 = rootObj.value("point1_x_2").toInt(0);
|
|
|
int p1y_2 = rootObj.value("point1_y_2").toInt(0);
|
|
|
int p2x_2 = rootObj.value("point2_x_2").toInt(100);
|
|
|
int p2y_2 = rootObj.value("point2_y_2").toInt(100);
|
|
|
double length_2 = rootObj.value("length_2").toDouble(1000);
|
|
|
point1_2.setX(p1x_2);
|
|
|
point1_2.setY(p1y_2);
|
|
|
point2_2.setX(p2x_2);
|
|
|
point2_2.setY(p2y_2);
|
|
|
fLength_2 = length_2;
|
|
|
m_StationScale_2 = rootObj.value("StationScale_2").toDouble(1.0);
|
|
|
m_StationXOffset_2 = rootObj.value("StationXOffset_2").toDouble(0.0);
|
|
|
m_StationYOffset_2 = rootObj.value("StationYOffset_2").toDouble(0.0);
|
|
|
|
|
|
pointCircle = rootObj.value("pointCircle").toInt(20);
|
|
|
trigerFilter = rootObj.value("trigerFilter").toInt(1000);
|
|
|
//new
|
|
|
bUse4PointStand = rootObj.value("use4pointstand").toBool(false);
|
|
|
|
|
|
QJsonObject stand1Obj = rootObj.value("station1_4p").toObject();
|
|
|
if (!stand1Obj.isEmpty())
|
|
|
{
|
|
|
stationParam1.bXYTrans = stand1Obj.value("bXYTrans").toBool(false);
|
|
|
stationParam1.Pixpoint1 = QPoint(stand1Obj.value("pixpoint1_x").toInt(), stand1Obj.value("pixpoint1_y").toInt());
|
|
|
stationParam1.Pixpoint2 = QPoint(stand1Obj.value("pixpoint2_x").toInt(), stand1Obj.value("pixpoint2_y").toInt());
|
|
|
stationParam1.Pixpoint3 = QPoint(stand1Obj.value("pixpoint3_x").toInt(), stand1Obj.value("pixpoint3_y").toInt());
|
|
|
stationParam1.Pixpoint4 = QPoint(stand1Obj.value("pixpoint4_x").toInt(), stand1Obj.value("pixpoint4_y").toInt());
|
|
|
|
|
|
stationParam1.Realpoint1 = QPointF(stand1Obj.value("Realpoint1_x").toDouble(), stand1Obj.value("Realpoint1_y").toDouble());
|
|
|
stationParam1.Realpoint2 = QPointF(stand1Obj.value("Realpoint2_x").toDouble(), stand1Obj.value("Realpoint2_y").toDouble());
|
|
|
stationParam1.Realpoint3 = QPointF(stand1Obj.value("Realpoint3_x").toDouble(), stand1Obj.value("Realpoint3_y").toDouble());
|
|
|
stationParam1.Realpoint4 = QPointF(stand1Obj.value("Realpoint4_x").toDouble(), stand1Obj.value("Realpoint4_y").toDouble());
|
|
|
|
|
|
stationParam1.testPoint = QPoint(stand1Obj.value("testPoint_x").toInt(), stand1Obj.value("testPoint_y").toInt());
|
|
|
|
|
|
stationParam1.xPointOffset = stand1Obj.value("xoffset").toDouble();
|
|
|
stationParam1.yPointOffset = stand1Obj.value("yoffset").toDouble();
|
|
|
|
|
|
stationParam1.matix.m11 = stand1Obj.value("m11").toDouble();
|
|
|
stationParam1.matix.m12 = stand1Obj.value("m12").toDouble();
|
|
|
stationParam1.matix.m21 = stand1Obj.value("m21").toDouble();
|
|
|
stationParam1.matix.m22 = stand1Obj.value("m22").toDouble();
|
|
|
stationParam1.matix.dx = stand1Obj.value("dx").toDouble();
|
|
|
stationParam1.matix.dy = stand1Obj.value("dy").toDouble();
|
|
|
}
|
|
|
QJsonObject stand2Obj = rootObj.value("station2_4p").toObject();
|
|
|
if (!stand2Obj.isEmpty())
|
|
|
{
|
|
|
stationParam2.bXYTrans = stand2Obj.value("bXYTrans").toBool(false);
|
|
|
stationParam2.Pixpoint1 = QPoint(stand2Obj.value("pixpoint1_x").toInt(), stand2Obj.value("pixpoint1_y").toInt());
|
|
|
stationParam2.Pixpoint2 = QPoint(stand2Obj.value("pixpoint2_x").toInt(), stand2Obj.value("pixpoint2_y").toInt());
|
|
|
stationParam2.Pixpoint3 = QPoint(stand2Obj.value("pixpoint3_x").toInt(), stand2Obj.value("pixpoint3_y").toInt());
|
|
|
stationParam2.Pixpoint4 = QPoint(stand2Obj.value("pixpoint4_x").toInt(), stand2Obj.value("pixpoint4_y").toInt());
|
|
|
|
|
|
stationParam2.Realpoint1 = QPointF(stand2Obj.value("Realpoint1_x").toDouble(), stand2Obj.value("Realpoint1_y").toDouble());
|
|
|
stationParam2.Realpoint2 = QPointF(stand2Obj.value("Realpoint2_x").toDouble(), stand2Obj.value("Realpoint2_y").toDouble());
|
|
|
stationParam2.Realpoint3 = QPointF(stand2Obj.value("Realpoint3_x").toDouble(), stand2Obj.value("Realpoint3_y").toDouble());
|
|
|
stationParam2.Realpoint4 = QPointF(stand2Obj.value("Realpoint4_x").toDouble(), stand2Obj.value("Realpoint4_y").toDouble());
|
|
|
|
|
|
stationParam2.testPoint = QPoint(stand2Obj.value("testPoint_x").toInt(), stand2Obj.value("testPoint_y").toInt());
|
|
|
|
|
|
stationParam2.xPointOffset = stand2Obj.value("xoffset").toDouble();
|
|
|
stationParam2.yPointOffset = stand2Obj.value("yoffset").toDouble();
|
|
|
|
|
|
stationParam2.matix.m11 = stand2Obj.value("m11").toDouble();
|
|
|
stationParam2.matix.m12 = stand2Obj.value("m12").toDouble();
|
|
|
stationParam2.matix.m21 = stand2Obj.value("m21").toDouble();
|
|
|
stationParam2.matix.m22 = stand2Obj.value("m22").toDouble();
|
|
|
stationParam2.matix.dx = stand2Obj.value("dx").toDouble();
|
|
|
stationParam2.matix.dy = stand2Obj.value("dy").toDouble();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
file.close();
|
|
|
}
|
|
|
|
|
|
void lpGlobalConfig::writeConfig()
|
|
|
{
|
|
|
QString strPath = m_rootPath + "/user/globalConfig.json";
|
|
|
QFile file(strPath);
|
|
|
if (true == file.open(QIODevice::WriteOnly))
|
|
|
{
|
|
|
QJsonObject rootObj;
|
|
|
rootObj.insert("station_camkey_1", m_StationCamKey_1);
|
|
|
rootObj.insert("station_camkey_2", m_StationCamKey_2);
|
|
|
rootObj.insert("station_solution_1", m_StationSolution_1);
|
|
|
rootObj.insert("station_solution_2", m_StationSolution_2);
|
|
|
rootObj.insert("station_runModel_1", m_StationRunModel_1);
|
|
|
rootObj.insert("station_runModel_2", m_StationRunModel_2);
|
|
|
|
|
|
rootObj.insert("station_xytrans_1", m_StationXYTrans_1);
|
|
|
rootObj.insert("station_xytrans_2", m_StationXYTrans_2);
|
|
|
|
|
|
rootObj.insert("onlineMode", m_bOnlineMode);
|
|
|
|
|
|
rootObj.insert("point1_x_1", point1_1.x());
|
|
|
rootObj.insert("point1_y_1", point1_1.y());
|
|
|
rootObj.insert("point2_x_1", point2_1.x());
|
|
|
rootObj.insert("point2_y_1", point2_1.y());
|
|
|
rootObj.insert("length_1", fLength_1);
|
|
|
|
|
|
rootObj.insert("StationScale_1",m_StationScale_1);
|
|
|
rootObj.insert("StationXOffset_1",m_StationXOffset_1);
|
|
|
rootObj.insert("StationYOffset_1",m_StationYOffset_1);
|
|
|
|
|
|
rootObj.insert("point1_x_2", point1_2.x());
|
|
|
rootObj.insert("point1_y_2", point1_2.y());
|
|
|
rootObj.insert("point2_x_2", point2_2.x());
|
|
|
rootObj.insert("point2_y_2", point2_2.y());
|
|
|
rootObj.insert("length_2", fLength_2);
|
|
|
|
|
|
rootObj.insert("StationScale_2",m_StationScale_2);
|
|
|
rootObj.insert("StationXOffset_2",m_StationXOffset_2);
|
|
|
rootObj.insert("StationYOffset_2",m_StationYOffset_2);
|
|
|
rootObj.insert("pointCircle", pointCircle);
|
|
|
rootObj.insert("trigerFilter", trigerFilter);
|
|
|
|
|
|
rootObj.insert("use4pointstand", bUse4PointStand);
|
|
|
|
|
|
|
|
|
QJsonObject stand1Obj;
|
|
|
stand1Obj.insert("bXYTrans", stationParam1.bXYTrans);
|
|
|
stand1Obj.insert("pixpoint1_x", stationParam1.Pixpoint1.x());
|
|
|
stand1Obj.insert("pixpoint1_y", stationParam1.Pixpoint1.y());
|
|
|
stand1Obj.insert("pixpoint2_x", stationParam1.Pixpoint2.x());
|
|
|
stand1Obj.insert("pixpoint2_y", stationParam1.Pixpoint2.y());
|
|
|
stand1Obj.insert("pixpoint3_x", stationParam1.Pixpoint3.x());
|
|
|
stand1Obj.insert("pixpoint3_y", stationParam1.Pixpoint3.y());
|
|
|
stand1Obj.insert("pixpoint4_x", stationParam1.Pixpoint4.x());
|
|
|
stand1Obj.insert("pixpoint4_y", stationParam1.Pixpoint4.y());
|
|
|
|
|
|
stand1Obj.insert("Realpoint1_x", stationParam1.Realpoint1.x());
|
|
|
stand1Obj.insert("Realpoint1_y", stationParam1.Realpoint1.y());
|
|
|
stand1Obj.insert("Realpoint2_x", stationParam1.Realpoint2.x());
|
|
|
stand1Obj.insert("Realpoint2_y", stationParam1.Realpoint2.y());
|
|
|
stand1Obj.insert("Realpoint3_x", stationParam1.Realpoint3.x());
|
|
|
stand1Obj.insert("Realpoint3_y", stationParam1.Realpoint3.y());
|
|
|
stand1Obj.insert("Realpoint4_x", stationParam1.Realpoint4.x());
|
|
|
stand1Obj.insert("Realpoint4_y", stationParam1.Realpoint4.y());
|
|
|
|
|
|
stand1Obj.insert("testPoint_x",stationParam1.testPoint.x());
|
|
|
stand1Obj.insert("testPoint_y", stationParam1.testPoint.y());
|
|
|
|
|
|
stand1Obj.insert("xoffset",stationParam1.xPointOffset);
|
|
|
stand1Obj.insert("yoffset",stationParam1.yPointOffset);
|
|
|
|
|
|
stand1Obj.insert("m11",stationParam1.matix.m11);
|
|
|
stand1Obj.insert("m12",stationParam1.matix.m12);
|
|
|
stand1Obj.insert("m21",stationParam1.matix.m21);
|
|
|
stand1Obj.insert("m22",stationParam1.matix.m22);
|
|
|
stand1Obj.insert("dx",stationParam1.matix.dx);
|
|
|
stand1Obj.insert("dy",stationParam1.matix.dy);
|
|
|
|
|
|
rootObj.insert("station1_4p",stand1Obj);
|
|
|
|
|
|
QJsonObject stand2Obj;
|
|
|
stand2Obj.insert("bXYTrans", stationParam2.bXYTrans);
|
|
|
stand2Obj.insert("pixpoint1_x", stationParam2.Pixpoint1.x());
|
|
|
stand2Obj.insert("pixpoint1_y", stationParam2.Pixpoint1.y());
|
|
|
stand2Obj.insert("pixpoint2_x", stationParam2.Pixpoint2.x());
|
|
|
stand2Obj.insert("pixpoint2_y", stationParam2.Pixpoint2.y());
|
|
|
stand2Obj.insert("pixpoint3_x", stationParam2.Pixpoint3.x());
|
|
|
stand2Obj.insert("pixpoint3_y", stationParam2.Pixpoint3.y());
|
|
|
stand2Obj.insert("pixpoint4_x", stationParam2.Pixpoint4.x());
|
|
|
stand2Obj.insert("pixpoint4_y", stationParam2.Pixpoint4.y());
|
|
|
|
|
|
stand2Obj.insert("Realpoint1_x", stationParam2.Realpoint1.x());
|
|
|
stand2Obj.insert("Realpoint1_y", stationParam2.Realpoint1.y());
|
|
|
stand2Obj.insert("Realpoint2_x", stationParam2.Realpoint2.x());
|
|
|
stand2Obj.insert("Realpoint2_y", stationParam2.Realpoint2.y());
|
|
|
stand2Obj.insert("Realpoint3_x", stationParam2.Realpoint3.x());
|
|
|
stand2Obj.insert("Realpoint3_y", stationParam2.Realpoint3.y());
|
|
|
stand2Obj.insert("Realpoint4_x", stationParam2.Realpoint4.x());
|
|
|
stand2Obj.insert("Realpoint4_y", stationParam2.Realpoint4.y());
|
|
|
|
|
|
stand2Obj.insert("testPoint_x", stationParam2.testPoint.x());
|
|
|
stand2Obj.insert("testPoint_y", stationParam2.testPoint.y());
|
|
|
|
|
|
stand2Obj.insert("xoffset", stationParam2.xPointOffset);
|
|
|
stand2Obj.insert("yoffset", stationParam2.yPointOffset);
|
|
|
|
|
|
stand2Obj.insert("m11", stationParam2.matix.m11);
|
|
|
stand2Obj.insert("m12", stationParam2.matix.m12);
|
|
|
stand2Obj.insert("m21", stationParam2.matix.m21);
|
|
|
stand2Obj.insert("m22", stationParam2.matix.m22);
|
|
|
stand2Obj.insert("dx", stationParam2.matix.dx);
|
|
|
stand2Obj.insert("dy", stationParam2.matix.dy);
|
|
|
|
|
|
rootObj.insert("station2_4p", stand2Obj);
|
|
|
|
|
|
QJsonDocument doc(rootObj);
|
|
|
QByteArray writeData = doc.toJson();
|
|
|
file.write(writeData);
|
|
|
}
|
|
|
file.close();
|
|
|
}
|
|
|
|
|
|
QPointF transWorldPoint(QPointF imgPoint, MatixParam param)
|
|
|
{
|
|
|
double temX = imgPoint.x() * param.m11 + imgPoint.y() * param.m21 + param.dx;
|
|
|
double temY = imgPoint.x() * param.m12 + imgPoint.y() * param.m22 + param.dy;
|
|
|
return QPointF(temX, temY);
|
|
|
}
|
|
|
|
|
|
MatixParam gentransform(QPolygonF srcPos, QPolygonF dstPos)
|
|
|
{
|
|
|
Point2f srcVec[4];
|
|
|
Point2f dstTri[4];
|
|
|
|
|
|
srcVec[0].x = srcPos.at(0).x();
|
|
|
srcVec[0].y = srcPos.at(0).y();
|
|
|
|
|
|
srcVec[1].x = srcPos.at(1).x();
|
|
|
srcVec[1].y = srcPos.at(1).y();
|
|
|
|
|
|
srcVec[2].x = srcPos.at(2).x();
|
|
|
srcVec[2].y = srcPos.at(2).y();
|
|
|
|
|
|
srcVec[3].x = srcPos.at(3).x();
|
|
|
srcVec[3].y = srcPos.at(3).y();
|
|
|
|
|
|
dstTri[0].x = dstPos.at(0).x();
|
|
|
dstTri[0].y = dstPos.at(0).y();
|
|
|
|
|
|
dstTri[1].x = dstPos.at(1).x();
|
|
|
dstTri[1].y = dstPos.at(1).y();
|
|
|
|
|
|
dstTri[2].x = dstPos.at(2).x();
|
|
|
dstTri[2].y = dstPos.at(2).y();
|
|
|
|
|
|
dstTri[3].x = dstPos.at(3).x();
|
|
|
dstTri[3].y = dstPos.at(3).y();
|
|
|
|
|
|
/// <20><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD>任
|
|
|
Mat warp_mat = getAffineTransform(srcVec, dstTri);
|
|
|
double* pTransMat = (double*)(warp_mat.data);
|
|
|
double m00 = pTransMat[0];
|
|
|
double m10 = pTransMat[1];
|
|
|
double m20 = pTransMat[2];
|
|
|
double m01 = pTransMat[3];
|
|
|
double m11 = pTransMat[4];
|
|
|
double m21 = pTransMat[5];
|
|
|
|
|
|
MatixParam param;
|
|
|
param.m11 = m00;
|
|
|
param.m21 = m10;
|
|
|
param.dx = m20;
|
|
|
param.m12 = m01;
|
|
|
param.m22 = m11;
|
|
|
param.dy = m21;
|
|
|
return param;
|
|
|
}
|