2026-01-05 01:19:04 +08:00
|
|
|
|
// BQ_workpieceCornerExtract_test.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
|
2025-12-18 20:25:30 +08:00
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
2026-01-05 01:19:04 +08:00
|
|
|
|
#include <fstream>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <VZNL_Types.h>
|
|
|
|
|
|
#include "direct.h"
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include "BQ_assemblyPosition_Export.h"
|
|
|
|
|
|
#include <opencv2/opencv.hpp>
|
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
#include <limits>
|
2025-12-18 20:25:30 +08:00
|
|
|
|
|
2026-01-05 01:19:04 +08:00
|
|
|
|
typedef struct
|
|
|
|
|
|
{
|
|
|
|
|
|
int r;
|
|
|
|
|
|
int g;
|
|
|
|
|
|
int b;
|
|
|
|
|
|
}SG_color;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
|
{
|
|
|
|
|
|
int nPointIdx;
|
|
|
|
|
|
double x;
|
|
|
|
|
|
double y;
|
|
|
|
|
|
double z;
|
|
|
|
|
|
float r;
|
|
|
|
|
|
float g;
|
|
|
|
|
|
float b;
|
|
|
|
|
|
} SPointXYZRGB;
|
|
|
|
|
|
|
|
|
|
|
|
void vzReadLaserScanPointFromFile_XYZ_vector(const char* fileName, std::vector<std::vector< SVzNL3DPosition>>& scanData)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ifstream inputFile(fileName);
|
|
|
|
|
|
std::string linedata;
|
|
|
|
|
|
|
|
|
|
|
|
if (inputFile.is_open() == false)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector< SVzNL3DPosition> a_line;
|
|
|
|
|
|
int ptIdx = 0;
|
|
|
|
|
|
while (getline(inputFile, linedata))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (0 == strncmp("Line_", linedata.c_str(), 5))
|
|
|
|
|
|
{
|
|
|
|
|
|
int ptSize = (int)a_line.size();
|
|
|
|
|
|
if (ptSize > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
scanData.push_back(a_line);
|
|
|
|
|
|
}
|
|
|
|
|
|
a_line.clear();
|
|
|
|
|
|
ptIdx = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (0 == strncmp("{", linedata.c_str(), 1))
|
|
|
|
|
|
{
|
|
|
|
|
|
float X, Y, Z;
|
|
|
|
|
|
int imageY = 0;
|
|
|
|
|
|
float leftX, leftY;
|
|
|
|
|
|
float rightX, rightY;
|
|
|
|
|
|
//迁移相机的XY次序和伟景相机正好相反
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "{%f,%f,%f}-{%f,%f}-{%f,%f}", &Y, &X, &Z, &leftX, &leftY, &rightX, &rightY);
|
|
|
|
|
|
SVzNL3DPosition a_pt;
|
|
|
|
|
|
a_pt.pt3D.x = X;
|
|
|
|
|
|
a_pt.pt3D.y = Y;
|
|
|
|
|
|
a_pt.pt3D.z = Z;
|
|
|
|
|
|
a_pt.nPointIdx = ptIdx;
|
|
|
|
|
|
ptIdx++;
|
|
|
|
|
|
a_line.push_back(a_pt);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//last line
|
|
|
|
|
|
int ptSize = (int)a_line.size();
|
|
|
|
|
|
if (ptSize > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
scanData.push_back(a_line);
|
|
|
|
|
|
a_line.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inputFile.close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wdSavePlyTxt(const char* fileName, std::vector<std::vector< SVzNL3DPosition>> scanLines)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ofstream sw(fileName);
|
|
|
|
|
|
int lineNum = scanLines.size();
|
|
|
|
|
|
for (int line = 0; line < lineNum; line++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int nPositionCnt = scanLines[line].size();
|
|
|
|
|
|
for (int i = 0; i < nPositionCnt; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPoint* pt3D = &scanLines[line][i].pt3D;
|
|
|
|
|
|
if (pt3D->z < 1e-4)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
double x = (double)pt3D->x;
|
|
|
|
|
|
double y = (double)pt3D->y;
|
|
|
|
|
|
double z = (double)pt3D->z;
|
|
|
|
|
|
sw << x << "," << y << "," << z << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
sw.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _convertToGridData_XYZ_vector(std::vector<std::vector< SVzNL3DPosition>>& scanData, double _F, std::vector<std::vector< SVzNL3DPosition>>& scanData_grid)
|
|
|
|
|
|
{
|
|
|
|
|
|
int min_y = 100000000;
|
|
|
|
|
|
int max_y = -10000000;
|
|
|
|
|
|
int lineNum = scanData.size();
|
|
|
|
|
|
for (int line = 0; line < lineNum; line++)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::vector< SVzNL3DPosition>& a_line = scanData[line];
|
|
|
|
|
|
int nPointCnt = a_line.size();
|
|
|
|
|
|
for (int i = 0; i < nPointCnt; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPosition* a_pt = &scanData[line][i];
|
|
|
|
|
|
if (a_pt->pt3D.z > 1e-4)
|
|
|
|
|
|
{
|
|
|
|
|
|
double v = _F * a_pt->pt3D.y / a_pt->pt3D.z + 2000;
|
|
|
|
|
|
a_pt->nPointIdx = (int)(v + 0.5);
|
|
|
|
|
|
max_y = max_y < (int)a_pt->nPointIdx ? (int)a_pt->nPointIdx : max_y;
|
|
|
|
|
|
min_y = min_y > (int)a_pt->nPointIdx ? (int)a_pt->nPointIdx : min_y;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (min_y == 100000000)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
int pt_counter = max_y - min_y + 1;
|
|
|
|
|
|
for (int line = 0; line < lineNum; line++)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::vector< SVzNL3DPosition> gridData;
|
|
|
|
|
|
gridData.resize(pt_counter);
|
|
|
|
|
|
for (int i = 0; i < pt_counter; i++)
|
|
|
|
|
|
gridData[i] = { 0,{ 0.0, 0.0, 0.0} };
|
|
|
|
|
|
|
|
|
|
|
|
std::vector< SVzNL3DPosition>& a_line = scanData[line];
|
|
|
|
|
|
int nPointCnt = a_line.size();
|
|
|
|
|
|
for (int i = 0; i < nPointCnt; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPosition a_pt = a_line[i];
|
|
|
|
|
|
if (a_pt.pt3D.z > 1e-4)
|
|
|
|
|
|
{
|
|
|
|
|
|
int pt_id = a_pt.nPointIdx - min_y;
|
|
|
|
|
|
gridData[pt_id] = a_pt;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
scanData_grid.push_back(gridData);
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _outputScanDataFile_XYZ_vector(char* fileName, std::vector<std::vector< SVzNL3DPosition>>& scanData)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ofstream sw(fileName);
|
|
|
|
|
|
int lineNum = scanData.size();
|
|
|
|
|
|
sw << "LineNum:" << lineNum << std::endl;
|
|
|
|
|
|
sw << "DataType: 0" << std::endl;
|
|
|
|
|
|
sw << "ScanSpeed: 0" << std::endl;
|
|
|
|
|
|
sw << "PointAdjust: 1" << std::endl;
|
|
|
|
|
|
sw << "MaxTimeStamp: 0_0" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
for (int line = 0; line < lineNum; line++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int nPositionCnt = scanData[line].size();
|
|
|
|
|
|
sw << "Line_" << line << "_0_" << nPositionCnt << std::endl;
|
|
|
|
|
|
for (int i = 0; i < nPositionCnt; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPosition* pt3D = &scanData[line][i];
|
|
|
|
|
|
float x = (float)pt3D->pt3D.x;
|
|
|
|
|
|
float y = (float)pt3D->pt3D.y;
|
|
|
|
|
|
float z = (float)pt3D->pt3D.z;
|
|
|
|
|
|
char str[250];
|
|
|
|
|
|
sprintf_s(str, "{ %f, %f, %f } - { 0, 0 } - { 0, 0 }", x, y, z);
|
|
|
|
|
|
|
|
|
|
|
|
sw << str << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
sw.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _getRoiData_XYZ_vector(
|
|
|
|
|
|
std::vector<std::vector< SVzNL3DPosition>>& scanData,
|
|
|
|
|
|
std::vector<std::vector< SVzNL3DPosition>>& roiData,
|
|
|
|
|
|
SVzNL3DRangeD roi)
|
|
|
|
|
|
{
|
|
|
|
|
|
int lineNum = scanData.size();
|
|
|
|
|
|
for (int line = 0; line < lineNum; line++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int nPositionCnt = scanData[line].size();
|
|
|
|
|
|
std::vector< SVzNL3DPosition> linePts;
|
|
|
|
|
|
for (int i = 0; i < nPositionCnt; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPosition pt3D = scanData[line][i];
|
|
|
|
|
|
if ((pt3D.pt3D.z >= roi.zRange.min) &&
|
|
|
|
|
|
(pt3D.pt3D.z <= roi.zRange.max) &&
|
|
|
|
|
|
(pt3D.pt3D.y >= roi.yRange.min) &&
|
|
|
|
|
|
(pt3D.pt3D.y <= roi.yRange.max))
|
|
|
|
|
|
{
|
|
|
|
|
|
linePts.push_back(pt3D);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
roiData.push_back(linePts);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _outputCalibPara(char* fileName, SSG_planeCalibPara calibPara)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ofstream sw(fileName);
|
|
|
|
|
|
char dataStr[250];
|
|
|
|
|
|
//调平矩阵
|
|
|
|
|
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.planeCalib[0], calibPara.planeCalib[1], calibPara.planeCalib[2]);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.planeCalib[3], calibPara.planeCalib[4], calibPara.planeCalib[5]);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.planeCalib[6], calibPara.planeCalib[7], calibPara.planeCalib[8]);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
//地面高度
|
|
|
|
|
|
sprintf_s(dataStr, 250, "%g", calibPara.planeHeight);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
//反向旋转矩阵
|
|
|
|
|
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.invRMatrix[0], calibPara.invRMatrix[1], calibPara.invRMatrix[2]);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.invRMatrix[3], calibPara.invRMatrix[4], calibPara.invRMatrix[5]);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
sprintf_s(dataStr, 250, "%g, %g, %g", calibPara.invRMatrix[6], calibPara.invRMatrix[7], calibPara.invRMatrix[8]);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
sw.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _outputPoseInfo(char* fileName, SSX_BQAssemblyInfo assemblyPose)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ofstream sw(fileName);
|
|
|
|
|
|
char dataStr[250];
|
|
|
|
|
|
sprintf_s(dataStr, 250, " O: (%g, %g, %g)", assemblyPose.O.x, assemblyPose.O.y, assemblyPose.O.z);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
sprintf_s(dataStr, 250, " X: (%g, %g, %g)", assemblyPose.X.x, assemblyPose.X.y, assemblyPose.X.z);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
sprintf_s(dataStr, 250, " Y: (%g, %g, %g)", assemblyPose.Y.x, assemblyPose.Y.y, assemblyPose.Y.z);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
sprintf_s(dataStr, 250, " Z: (%g, %g, %g)", assemblyPose.Z.x, assemblyPose.Z.y, assemblyPose.Z.z);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
sw.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SSX_BQAssemblyInfo _readPoseInfo(char* fileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ifstream inputFile(fileName);
|
|
|
|
|
|
std::string linedata;
|
|
|
|
|
|
|
|
|
|
|
|
SSX_BQAssemblyInfo pose;
|
|
|
|
|
|
memset(&pose, 0, sizeof(SSX_BQAssemblyInfo));
|
|
|
|
|
|
if (inputFile.is_open() == false)
|
|
|
|
|
|
return pose;
|
|
|
|
|
|
|
|
|
|
|
|
getline(inputFile, linedata);
|
|
|
|
|
|
sscanf_s(linedata.c_str(), " O: (%lf, %lf, %lf)", &pose.O.x, &pose.O.y, &pose.O.z);
|
|
|
|
|
|
getline(inputFile, linedata);
|
|
|
|
|
|
sscanf_s(linedata.c_str(), " X: (%lf, %lf, %lf)", &pose.X.x, &pose.X.y, &pose.X.z);
|
|
|
|
|
|
getline(inputFile, linedata);
|
|
|
|
|
|
sscanf_s(linedata.c_str(), " Y: (%lf, %lf, %lf)", &pose.Y.x, &pose.Y.y, &pose.Y.z);
|
|
|
|
|
|
getline(inputFile, linedata);
|
|
|
|
|
|
sscanf_s(linedata.c_str(), " Z: (%lf, %lf, %lf)", &pose.Z.x, &pose.Z.y, &pose.Z.z);
|
|
|
|
|
|
|
|
|
|
|
|
inputFile.close();
|
|
|
|
|
|
return pose;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-11 17:04:06 +08:00
|
|
|
|
// 检测并跳过UTF-8 BOM头的工具函数
|
|
|
|
|
|
void skipUTF8BOM(std::ifstream& file) {
|
|
|
|
|
|
// 存储BOM的3个字节(初始化为0)
|
|
|
|
|
|
char bom[3] = { 0 };
|
|
|
|
|
|
// 读取文件前3个字节
|
|
|
|
|
|
file.read(bom, 3);
|
|
|
|
|
|
|
|
|
|
|
|
// 检测是否是UTF-8 BOM(0xEF 0xBB 0xBF)
|
|
|
|
|
|
bool isBOM = (bom[0] == (char)0xEF) &&
|
|
|
|
|
|
(bom[1] == (char)0xBB) &&
|
|
|
|
|
|
(bom[2] == (char)0xBF);
|
|
|
|
|
|
|
|
|
|
|
|
// 不是BOM则将文件指针重置到开头,保证正常读取
|
|
|
|
|
|
if (!isBOM) {
|
|
|
|
|
|
file.seekg(0); // 重置文件指针到起始位置
|
|
|
|
|
|
}
|
|
|
|
|
|
// 是BOM则文件指针已在第4字节,无需处理
|
|
|
|
|
|
}
|
2026-01-05 01:19:04 +08:00
|
|
|
|
void _readMarkData(char* fileName, std::vector<SWD_charuco3DMark>& marks)
|
|
|
|
|
|
{
|
2026-01-11 17:04:06 +08:00
|
|
|
|
std::ifstream inputFile(fileName, std::ios::in | std::ios::binary);
|
|
|
|
|
|
skipUTF8BOM(inputFile);
|
2026-01-05 01:19:04 +08:00
|
|
|
|
std::string linedata;
|
|
|
|
|
|
while (getline(inputFile, linedata))
|
|
|
|
|
|
{
|
|
|
|
|
|
SWD_charuco3DMark a_mark;
|
|
|
|
|
|
float x, y, z;
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "MarkID_%d: %f, %f, %f", &a_mark.markID, &x, &y, &z);
|
|
|
|
|
|
a_mark.mark3D = { x, y, z };
|
|
|
|
|
|
marks.push_back(a_mark);
|
|
|
|
|
|
}
|
|
|
|
|
|
inputFile.close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _outputScanDataFile_vector(char* fileName, std::vector<std::vector<SVzNL3DPosition>>& scanLines, bool removeZeros, int* headNullLines)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ofstream sw(fileName);
|
|
|
|
|
|
int lineNum = (int)scanLines.size();
|
|
|
|
|
|
if (lineNum == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
sw << "LineNum:" << lineNum << std::endl;
|
|
|
|
|
|
sw << "DataType: 0" << std::endl;
|
|
|
|
|
|
sw << "ScanSpeed: 0" << std::endl;
|
|
|
|
|
|
sw << "PointAdjust: 1" << std::endl;
|
|
|
|
|
|
sw << "MaxTimeStamp: 0_0" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
int lineIdx = 0;
|
|
|
|
|
|
int null_lines = 0;
|
|
|
|
|
|
bool counterNull = true;
|
|
|
|
|
|
for (int line = 0; line < lineNum; line++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int linePtNum = (int)scanLines[line].size();
|
|
|
|
|
|
if (linePtNum == 0)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (true == removeZeros)
|
|
|
|
|
|
{
|
|
|
|
|
|
int vldPtNum = 0;
|
|
|
|
|
|
for (int i = 0; i < linePtNum; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (scanLines[line][i].pt3D.z > 1e-4)
|
|
|
|
|
|
vldPtNum++;
|
|
|
|
|
|
}
|
|
|
|
|
|
linePtNum = vldPtNum;
|
|
|
|
|
|
}
|
|
|
|
|
|
sw << "Line_" << lineIdx << "_0_" << linePtNum << std::endl;
|
|
|
|
|
|
lineIdx++;
|
|
|
|
|
|
bool isNull = true;
|
|
|
|
|
|
for (int i = 0; i < linePtNum; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPoint* pt3D = &scanLines[line][i].pt3D;
|
|
|
|
|
|
if ((pt3D->z > 1e-4) && (isNull == true))
|
|
|
|
|
|
isNull = false;
|
|
|
|
|
|
if ((true == removeZeros) && (pt3D->z < 1e-4))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
float x = (float)pt3D->x;
|
|
|
|
|
|
float y = (float)pt3D->y;
|
|
|
|
|
|
float z = (float)pt3D->z;
|
|
|
|
|
|
sw << "{ " << x << "," << y << "," << z << " }-";
|
|
|
|
|
|
sw << "{0,0}-{0,0}" << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (true == counterNull)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (true == isNull)
|
|
|
|
|
|
null_lines++;
|
|
|
|
|
|
else
|
|
|
|
|
|
counterNull = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*headNullLines = null_lines;
|
|
|
|
|
|
sw.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SSG_planeCalibPara _readCalibPara(char* fileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
//设置初始结果
|
|
|
|
|
|
double initCalib[9] = {
|
|
|
|
|
|
1.0, 0.0, 0.0,
|
|
|
|
|
|
0.0, 1.0, 0.0,
|
|
|
|
|
|
0.0, 0.0, 1.0 };
|
|
|
|
|
|
SSG_planeCalibPara planePara;
|
|
|
|
|
|
for (int i = 0; i < 9; i++)
|
|
|
|
|
|
planePara.planeCalib[i] = initCalib[i];
|
|
|
|
|
|
planePara.planeHeight = -1.0;
|
|
|
|
|
|
for (int i = 0; i < 9; i++)
|
|
|
|
|
|
planePara.invRMatrix[i] = initCalib[i];
|
|
|
|
|
|
|
|
|
|
|
|
std::ifstream inputFile(fileName);
|
|
|
|
|
|
std::string linedata;
|
|
|
|
|
|
|
|
|
|
|
|
if (inputFile.is_open() == false)
|
|
|
|
|
|
return planePara;
|
|
|
|
|
|
|
|
|
|
|
|
//调平矩阵
|
|
|
|
|
|
std::getline(inputFile, linedata);
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.planeCalib[0], &planePara.planeCalib[1], &planePara.planeCalib[2]);
|
|
|
|
|
|
std::getline(inputFile, linedata);
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.planeCalib[3], &planePara.planeCalib[4], &planePara.planeCalib[5]);
|
|
|
|
|
|
std::getline(inputFile, linedata);
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.planeCalib[6], &planePara.planeCalib[7], &planePara.planeCalib[8]);
|
|
|
|
|
|
//地面高度
|
|
|
|
|
|
std::getline(inputFile, linedata);
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "%lf", &planePara.planeHeight);
|
|
|
|
|
|
//反向旋转矩阵
|
|
|
|
|
|
std::getline(inputFile, linedata);
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.invRMatrix[0], &planePara.invRMatrix[1], &planePara.invRMatrix[2]);
|
|
|
|
|
|
std::getline(inputFile, linedata);
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.invRMatrix[3], &planePara.invRMatrix[4], &planePara.invRMatrix[5]);
|
|
|
|
|
|
std::getline(inputFile, linedata);
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "%lf, %lf, %lf", &planePara.invRMatrix[6], &planePara.invRMatrix[7], &planePara.invRMatrix[8]);
|
|
|
|
|
|
|
|
|
|
|
|
inputFile.close();
|
|
|
|
|
|
return planePara;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _outputRGBDScanLapWeld_RGBD(
|
|
|
|
|
|
char* fileName,
|
|
|
|
|
|
std::vector<std::vector<SVzNL3DPosition>>& scanLines,
|
|
|
|
|
|
SSX_BQAssemblyInfo assemblyPose)
|
|
|
|
|
|
{
|
|
|
|
|
|
int lineNum = (int)scanLines.size();
|
|
|
|
|
|
std::ofstream sw(fileName);
|
|
|
|
|
|
int realLines = lineNum;
|
|
|
|
|
|
realLines++;
|
|
|
|
|
|
sw << "LineNum:" << realLines << std::endl;
|
|
|
|
|
|
sw << "DataType: 0" << std::endl;
|
|
|
|
|
|
sw << "ScanSpeed: 0" << std::endl;
|
|
|
|
|
|
sw << "PointAdjust: 1" << std::endl;
|
|
|
|
|
|
sw << "MaxTimeStamp: 0_0" << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
int maxLineIndex = 0;
|
|
|
|
|
|
int max_stamp = 0;
|
|
|
|
|
|
|
|
|
|
|
|
SG_color rgb = { 0, 0, 0 };
|
|
|
|
|
|
|
|
|
|
|
|
SG_color objColor[8] = {
|
|
|
|
|
|
{245,222,179},//淡黄色
|
|
|
|
|
|
{210,105, 30},//巧克力色
|
|
|
|
|
|
{240,230,140},//黄褐色
|
|
|
|
|
|
{135,206,235},//天蓝色
|
|
|
|
|
|
{250,235,215},//古董白
|
|
|
|
|
|
{189,252,201},//薄荷色
|
|
|
|
|
|
{221,160,221},//梅红色
|
|
|
|
|
|
{188,143,143},//玫瑰红色
|
|
|
|
|
|
};
|
|
|
|
|
|
int size = 1;
|
|
|
|
|
|
int lineIdx = 0;
|
|
|
|
|
|
for (int line = 0; line < lineNum; line++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int linePtNum = (int)scanLines[line].size();
|
|
|
|
|
|
if (linePtNum == 0)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
sw << "Line_" << lineIdx << "_0_" << linePtNum << std::endl;
|
|
|
|
|
|
lineIdx++;
|
|
|
|
|
|
for (int i = 0; i < linePtNum; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPosition* pt3D = &scanLines[line][i];
|
|
|
|
|
|
if (pt3D->nPointIdx > 0)
|
|
|
|
|
|
int kkk = 1;
|
|
|
|
|
|
int featureType_v = pt3D->nPointIdx & 0xff;
|
|
|
|
|
|
int featureType_h = featureType_v >> 4;
|
|
|
|
|
|
featureType_v &= 0x0f;
|
|
|
|
|
|
|
|
|
|
|
|
if (pt3D->nPointIdx == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
rgb = { 255, 97, 0 };
|
|
|
|
|
|
size = 5;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
rgb = { 200, 200, 200 };
|
|
|
|
|
|
size = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
float x = (float)pt3D->pt3D.x;
|
|
|
|
|
|
float y = (float)pt3D->pt3D.y;
|
|
|
|
|
|
float z = (float)pt3D->pt3D.z;
|
|
|
|
|
|
sw << "{" << x << "," << y << "," << z << "}-";
|
|
|
|
|
|
sw << "{0,0}-{0,0}-";
|
|
|
|
|
|
sw << "{" << rgb.r << "," << rgb.g << "," << rgb.b << "," << size << " }" << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int linePtNum = 1;
|
|
|
|
|
|
sw << "Line_" << lineNum << "_0_" << linePtNum + 1 << std::endl;
|
|
|
|
|
|
lineNum++;
|
|
|
|
|
|
|
|
|
|
|
|
rgb = { 255, 0, 0 };
|
|
|
|
|
|
size = 15;
|
|
|
|
|
|
float x = (float)assemblyPose.O.x;
|
|
|
|
|
|
float y = (float)assemblyPose.O.y;
|
|
|
|
|
|
float z = (float)assemblyPose.O.z;
|
|
|
|
|
|
sw << "{" << x << "," << y << "," << z << "}-";
|
|
|
|
|
|
sw << "{0,0}-{0,0}-";
|
|
|
|
|
|
sw << "{" << rgb.r << "," << rgb.g << "," << rgb.b << "," << size << " }" << std::endl;
|
|
|
|
|
|
sw.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SVzNL3DPoint _pointRT(SVzNL3DPoint& origin, const double* R, const double* T)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPoint result;
|
|
|
|
|
|
result.x = origin.x * R[0] + origin.y * R[1] + origin.z * R[2];
|
|
|
|
|
|
result.y = origin.x * R[3] + origin.y * R[4] + origin.z * R[5];
|
|
|
|
|
|
result.z = origin.x * R[6] + origin.y * R[7] + origin.z * R[8];
|
|
|
|
|
|
result.x += T[0];
|
|
|
|
|
|
result.y += T[1];
|
|
|
|
|
|
result.z += T[2];
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _wirteVerifyResult(char* fileName,
|
|
|
|
|
|
std::vector<std::vector< SVzNL3DPoint>>& originMarksBuff,
|
|
|
|
|
|
std::vector<std::vector< SVzNL3DPoint>>& currMarksBuff,
|
|
|
|
|
|
std::vector< SSX_BQAssemblyInfo>& oiginPoseBuff,
|
|
|
|
|
|
std::vector< SSX_BQAssemblyInfo>& computePoseBuff,
|
|
|
|
|
|
std::vector< SSX_BQAssemblyInfo>& verifyPoseBuff)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ofstream sw(fileName);
|
|
|
|
|
|
char dataStr[250];
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)originMarksBuff.size(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int markSize = (int)originMarksBuff[i].size();
|
|
|
|
|
|
sprintf_s(dataStr, 250, "origin: ");
|
|
|
|
|
|
for (int j = 0; j < markSize; j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
sprintf_s(dataStr, 250, "{ %g, %g, %g },", originMarksBuff[i][j].x, originMarksBuff[i][j].y, originMarksBuff[i][j].z);
|
|
|
|
|
|
sw << dataStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
sprintf_s(dataStr, 250, " operate: ");
|
|
|
|
|
|
for (int j = 0; j < markSize; j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
sprintf_s(dataStr, 250, "{ %g, %g, %g },", currMarksBuff[i][j].x, currMarksBuff[i][j].y, currMarksBuff[i][j].z);
|
|
|
|
|
|
sw << dataStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
sprintf_s(dataStr, 250, " oriPose: { %g, %g, %g },", oiginPoseBuff[i].O.x, oiginPoseBuff[i].O.y, oiginPoseBuff[i].O.z);
|
|
|
|
|
|
sw << dataStr;
|
|
|
|
|
|
sprintf_s(dataStr, 250, " verifyPose: { %g, %g, %g },", verifyPoseBuff[i].O.x, verifyPoseBuff[i].O.y, verifyPoseBuff[i].O.z);
|
|
|
|
|
|
sw << dataStr;
|
|
|
|
|
|
sprintf_s(dataStr, 250, " computePose: { %g, %g, %g },", computePoseBuff[i].O.x, computePoseBuff[i].O.y, computePoseBuff[i].O.z);
|
|
|
|
|
|
sw << dataStr << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
sw.close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define CONVERT_TO_GRID 0
|
|
|
|
|
|
#define TEST_COMPUTE_CALIB_PARA 0
|
|
|
|
|
|
#define TEST_COMPUTE_CORNER 0
|
|
|
|
|
|
#define TEST_COMPUTE_POSE 1
|
2026-01-11 17:04:06 +08:00
|
|
|
|
#define TEST_GROUP 3
|
2025-12-18 20:25:30 +08:00
|
|
|
|
int main()
|
|
|
|
|
|
{
|
2026-01-05 01:19:04 +08:00
|
|
|
|
const char* dataPath[TEST_GROUP] = {
|
|
|
|
|
|
|
|
|
|
|
|
"F:/ShangGu/项目/冠钦_博清科技/组装/3D与Mark/21epic/", //0
|
|
|
|
|
|
"F:/ShangGu/项目/冠钦_博清科技/组装/3D与Mark/20vizum/",
|
2026-01-11 17:04:06 +08:00
|
|
|
|
"F:/ShangGu/项目/冠钦_博清科技/组装/3D与Mark/现场_张奔_20260106/",
|
2026-01-05 01:19:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SVzNLRange fileIdx[TEST_GROUP] = {
|
2026-01-11 17:04:06 +08:00
|
|
|
|
{2,33},{2,33}, {1,14}
|
2026-01-05 01:19:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TEST_COMPUTE_POSE
|
|
|
|
|
|
double R_3D_mark[9] = {
|
2026-01-11 17:04:06 +08:00
|
|
|
|
9.7432217968400503e-01, - 6.5983238824482409e-03,
|
|
|
|
|
|
- 2.2506166332308031e-01, 6.5293199817128209e-03,
|
|
|
|
|
|
9.9997813155105764e-01, - 1.0509044828439812e-03,
|
|
|
|
|
|
2.2506367578173436e-01, - 4.4558006908867375e-04,
|
|
|
|
|
|
9.7434395533713669e-01
|
2026-01-05 01:19:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
double T_3D_mark[3] = {
|
2026-01-11 17:04:06 +08:00
|
|
|
|
2.0100138599065690e+02, - 3.4778670146875356e+02,
|
|
|
|
|
|
- 2.8208030634996298e+01
|
2026-01-05 01:19:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
double R_mark_3D[9] = {
|
2026-01-11 17:04:06 +08:00
|
|
|
|
9.7432217968400503e-01, 6.5293199817128209e-03, 2.2506367578173436e-01,
|
|
|
|
|
|
- 6.5983238824482409e-03, 9.9997813155105764e-01,
|
|
|
|
|
|
- 4.4558006908867375e-04, - 2.2506166332308031e-01,
|
|
|
|
|
|
- 1.0509044828439812e-03, 9.7434395533713669e-01
|
2026-01-05 01:19:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
double T_mark_3D[3] = {
|
2026-01-11 17:04:06 +08:00
|
|
|
|
-1.8722069479737289e+02, 3.4909279922237783e+02,
|
|
|
|
|
|
7.2356539798828123e+01
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
double R_ip21_ip20[9] = {
|
|
|
|
|
|
-9.0136463861749749e-01, 1.0494706583686632e-03,
|
|
|
|
|
|
- 4.3305968048444010e-01, 3.8989008937143142e-03,
|
|
|
|
|
|
- 9.9993686885077060e-01, - 1.0538353037260263e-02,
|
|
|
|
|
|
- 4.3304340062142632e-01, - 1.1187355552326124e-02,
|
|
|
|
|
|
9.0130364264989893e-01
|
|
|
|
|
|
};
|
|
|
|
|
|
double T_ip21_ip20[3] = {
|
|
|
|
|
|
7.4953277493063717e+02, 2.8014434657528108e+02, 1.7494775044638942e+02
|
|
|
|
|
|
};
|
|
|
|
|
|
double R_ip20_ip21[9] = {
|
|
|
|
|
|
-9.0136463861749749e-01, 3.8989008937143142e-03,
|
|
|
|
|
|
- 4.3304340062142632e-01, 1.0494706583686632e-03,
|
|
|
|
|
|
- 9.9993686885077060e-01, - 1.1187355552326124e-02,
|
|
|
|
|
|
- 4.3305968048444010e-01, - 1.0538353037260263e-02,
|
|
|
|
|
|
9.0130364264989893e-01
|
|
|
|
|
|
};
|
|
|
|
|
|
double T_ip20_ip21[3] = {
|
|
|
|
|
|
7.5027005254846563e+02, 2.8129725077327970e+02, 1.6986363929894415e+02
|
2026-01-05 01:19:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
double R_3D_mark_20[9] = {
|
2026-01-11 17:04:06 +08:00
|
|
|
|
-9.7565715189866242e-01, 1.0207261472102205e-02,
|
|
|
|
|
|
- 2.1906376642939016e-01, - 8.0279186459975786e-03,
|
|
|
|
|
|
- 9.9990905961091314e-01, - 1.0836283045053035e-02,
|
|
|
|
|
|
- 2.1915445345966281e-01, - 8.8138709577232511e-03,
|
|
|
|
|
|
9.7565036832235041e-01
|
2026-01-05 01:19:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
double T_3D_mark_20[3] = {
|
2026-01-11 17:04:06 +08:00
|
|
|
|
5.7984427943242531e+02, 6.3069724580763238e+02, 6.1343276694911815e+01
|
2026-01-05 01:19:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
double R_mark_3D_20[9] = {
|
2026-01-11 17:04:06 +08:00
|
|
|
|
-9.7565715189866242e-01, - 8.0279186459975786e-03,
|
|
|
|
|
|
- 2.1915445345966281e-01, 1.0207261472102205e-02,
|
|
|
|
|
|
- 9.9990905961091314e-01, - 8.8138709577232511e-03,
|
|
|
|
|
|
- 2.1906376642939016e-01, - 1.0836283045053035e-02,
|
|
|
|
|
|
9.7565036832235041e-01
|
2026-01-05 01:19:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
double T_mark_3D_20[3] = {
|
2026-01-11 17:04:06 +08:00
|
|
|
|
5.8423605667286893e+02, 6.2526193950634604e+02, 7.4007695164819168e+01
|
2026-01-05 01:19:04 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-01-11 17:04:06 +08:00
|
|
|
|
for (int grp = 2; grp <= 2; grp++)
|
2026-01-05 01:19:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
char _scan_file[256];
|
|
|
|
|
|
std::vector<std::vector< SVzNL3DPoint>> originMarksBuff;
|
|
|
|
|
|
std::vector<std::vector< SVzNL3DPoint>> currMarksBuff;
|
|
|
|
|
|
std::vector< SSX_BQAssemblyInfo> oiginPoseBuff;
|
|
|
|
|
|
std::vector< SSX_BQAssemblyInfo> computePoseBuff;
|
|
|
|
|
|
std::vector< SSX_BQAssemblyInfo> verifyPoseBuff;
|
|
|
|
|
|
for (int fidx = fileIdx[grp].nMin; fidx <= fileIdx[grp].nMax; fidx++)
|
|
|
|
|
|
{
|
|
|
|
|
|
//fidx =4;
|
|
|
|
|
|
char _scan_file[256];
|
2026-01-11 17:04:06 +08:00
|
|
|
|
sprintf_s(_scan_file, "%sepic-cloud/result/LaserLine%d_corner_info.txt", dataPath[grp], fidx);
|
|
|
|
|
|
SSX_BQAssemblyInfo pose_3D = _readPoseInfo(_scan_file);
|
|
|
|
|
|
SSX_BQAssemblyInfo pose_3D_ip21;
|
|
|
|
|
|
pose_3D_ip21.O = _pointRT(pose_3D.O, R_3D_mark, T_3D_mark);
|
|
|
|
|
|
SSX_BQAssemblyInfo originPose_ip21_ip20_check;
|
|
|
|
|
|
originPose_ip21_ip20_check.O = _pointRT(pose_3D_ip21.O, R_ip21_ip20, T_ip21_ip20);
|
|
|
|
|
|
SSX_BQAssemblyInfo pose_3D_ip20;
|
|
|
|
|
|
pose_3D_ip20.O = _pointRT(pose_3D.O, R_3D_mark_20, T_3D_mark_20);
|
|
|
|
|
|
|
|
|
|
|
|
sprintf_s(_scan_file, "%smark21/marks_%d.txt", dataPath[grp], fidx);
|
2026-01-05 01:19:04 +08:00
|
|
|
|
std::vector<SWD_charuco3DMark> marks_origin;
|
|
|
|
|
|
_readMarkData(_scan_file, marks_origin);
|
|
|
|
|
|
|
2026-01-11 17:04:06 +08:00
|
|
|
|
sprintf_s(_scan_file, "%smark20/marks_%d.txt", dataPath[grp], fidx);
|
2026-01-05 01:19:04 +08:00
|
|
|
|
std::vector<SWD_charuco3DMark> marks_curr;
|
|
|
|
|
|
_readMarkData(_scan_file, marks_curr);
|
|
|
|
|
|
|
|
|
|
|
|
//配对
|
|
|
|
|
|
std::vector<SVzNL3DPoint> originMarkPos;
|
|
|
|
|
|
std::vector<SVzNL3DPoint> currMarkPos;
|
|
|
|
|
|
for (int i = 0; i < (int)marks_origin.size(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int j = 0; j < (int)marks_curr.size(); j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (marks_origin[i].markID == marks_curr[j].markID)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPoint pt_1 = { marks_origin[i].mark3D.x, marks_origin[i].mark3D.y, marks_origin[i].mark3D.z };
|
|
|
|
|
|
SVzNL3DPoint pt_2 = { marks_curr[j].mark3D.x, marks_curr[j].mark3D.y, marks_curr[j].mark3D.z };
|
|
|
|
|
|
originMarkPos.push_back(pt_1);
|
|
|
|
|
|
currMarkPos.push_back(pt_2);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SSX_BQAssemblyInfo testPose_origin, testPose_verify;
|
|
|
|
|
|
|
|
|
|
|
|
if (originMarkPos.size() >= 4) //同时使用最后一个作验证
|
|
|
|
|
|
{
|
|
|
|
|
|
testPose_origin.O = originMarkPos.back();
|
|
|
|
|
|
testPose_verify.O = currMarkPos.back();
|
|
|
|
|
|
originMarkPos.pop_back();
|
|
|
|
|
|
currMarkPos.pop_back();
|
|
|
|
|
|
|
|
|
|
|
|
originMarksBuff.push_back(originMarkPos);
|
|
|
|
|
|
currMarksBuff.push_back(currMarkPos);
|
|
|
|
|
|
|
|
|
|
|
|
int errCode = 0;
|
|
|
|
|
|
SSX_BQAssemblyInfo currPose = sx_BQ_computeAssemblyInfoFromMark(
|
2026-01-11 17:04:06 +08:00
|
|
|
|
pose_3D_ip21, originMarkPos, currMarkPos, &errCode);
|
2026-01-05 01:19:04 +08:00
|
|
|
|
|
|
|
|
|
|
SSX_BQAssemblyInfo compute_testPose = sx_BQ_computeAssemblyInfoFromMark(
|
|
|
|
|
|
testPose_origin, originMarkPos, currMarkPos, &errCode);
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
SSX_BQAssemblyInfo checkPose;
|
|
|
|
|
|
checkPose.O = _pointRT(originPose_raw.O, R_3D_mark_20, T_3D_mark_20);
|
|
|
|
|
|
SSX_BQAssemblyInfo checkPose_check;
|
|
|
|
|
|
checkPose_check.O = _pointRT(checkPose.O, R_mark_3D_20, T_mark_3D_20);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
if (errCode != 0)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
//输出
|
|
|
|
|
|
oiginPoseBuff.push_back(testPose_origin);
|
|
|
|
|
|
computePoseBuff.push_back(compute_testPose);
|
|
|
|
|
|
verifyPoseBuff.push_back(testPose_verify);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
sprintf_s(_scan_file, "%sresult/group_verify_data.txt", dataPath[grp]);
|
|
|
|
|
|
_wirteVerifyResult(_scan_file,
|
|
|
|
|
|
originMarksBuff,
|
|
|
|
|
|
currMarksBuff,
|
|
|
|
|
|
oiginPoseBuff,
|
|
|
|
|
|
computePoseBuff,
|
|
|
|
|
|
verifyPoseBuff);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#if TEST_COMPUTE_CALIB_PARA
|
|
|
|
|
|
char _calib_datafile[256];
|
|
|
|
|
|
sprintf_s(_calib_datafile, "F:/ShangGu/项目/冠钦_博清科技/组装/3D与Mark/21epic/调平/scan3D_0.txt");
|
|
|
|
|
|
int lineNum = 0;
|
|
|
|
|
|
float lineV = 0.0f;
|
|
|
|
|
|
int dataCalib = 0;
|
|
|
|
|
|
int maxTimeStamp = 0;
|
|
|
|
|
|
int clockPerSecond = 0;
|
|
|
|
|
|
std::vector<std::vector< SVzNL3DPosition>> scanData;
|
|
|
|
|
|
vzReadLaserScanPointFromFile_XYZ_vector(_calib_datafile, scanData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SVzNL3DRangeD roi;
|
|
|
|
|
|
roi.xRange.min = -DBL_MAX;
|
|
|
|
|
|
roi.xRange.max = DBL_MAX;
|
|
|
|
|
|
roi.yRange.min = -DBL_MAX;
|
|
|
|
|
|
roi.yRange.max = 580.0;
|
|
|
|
|
|
roi.zRange.min = 2380.0;
|
|
|
|
|
|
roi.zRange.max = 2460.0;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::vector< SVzNL3DPosition>> roiData;
|
|
|
|
|
|
_getRoiData_XYZ_vector(scanData, roiData, roi);
|
|
|
|
|
|
|
|
|
|
|
|
lineNum = (int)scanData.size();
|
|
|
|
|
|
if (scanData.size() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
SSG_planeCalibPara calibPara = sx_BQ_getHoleBaseCalibPara(scanData);
|
|
|
|
|
|
//结果进行验证
|
|
|
|
|
|
for (int i = 0; i < lineNum; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (i == 14)
|
|
|
|
|
|
int kkk = 1;
|
|
|
|
|
|
//行处理
|
|
|
|
|
|
//调平,去除地面
|
|
|
|
|
|
sx_BQ_lineDataR(scanData[i], calibPara.planeCalib, -1); // calibPara.planeHeight);
|
|
|
|
|
|
}
|
|
|
|
|
|
//
|
|
|
|
|
|
char calibFile[250];
|
|
|
|
|
|
sprintf_s(calibFile, "F:/ShangGu/项目/冠钦_博清科技/组装/3D与Mark/21epic/ground_calib_para.txt");
|
|
|
|
|
|
_outputCalibPara(calibFile, calibPara);
|
|
|
|
|
|
char _out_file[256];
|
|
|
|
|
|
sprintf_s(_out_file, "F:/ShangGu/项目/冠钦_博清科技/组装/3D与Mark/21epic/调平/scanData_ground_calib.txt");
|
|
|
|
|
|
int headNullLines = 0;
|
|
|
|
|
|
_outputScanDataFile_vector(_out_file, scanData, false, &headNullLines);
|
|
|
|
|
|
printf("%s: calib done!\n", _calib_datafile);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if TEST_COMPUTE_CORNER
|
|
|
|
|
|
const char* ver = wd_BQAssemblyPositionVersion();
|
|
|
|
|
|
printf("ver:%s\n", ver);
|
|
|
|
|
|
|
|
|
|
|
|
for (int grp = 0; grp <= 0; grp++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SSG_planeCalibPara poseCalibPara;
|
|
|
|
|
|
//初始化成单位阵
|
|
|
|
|
|
poseCalibPara.planeCalib[0] = 1.0;
|
|
|
|
|
|
poseCalibPara.planeCalib[1] = 0.0;
|
|
|
|
|
|
poseCalibPara.planeCalib[2] = 0.0;
|
|
|
|
|
|
poseCalibPara.planeCalib[3] = 0.0;
|
|
|
|
|
|
poseCalibPara.planeCalib[4] = 1.0;
|
|
|
|
|
|
poseCalibPara.planeCalib[5] = 0.0;
|
|
|
|
|
|
poseCalibPara.planeCalib[6] = 0.0;
|
|
|
|
|
|
poseCalibPara.planeCalib[7] = 0.0;
|
|
|
|
|
|
poseCalibPara.planeCalib[8] = 1.0;
|
|
|
|
|
|
poseCalibPara.planeHeight = -1.0;
|
|
|
|
|
|
for (int i = 0; i < 9; i++)
|
|
|
|
|
|
poseCalibPara.invRMatrix[i] = poseCalibPara.planeCalib[i];
|
|
|
|
|
|
char calibFile[250];
|
|
|
|
|
|
sprintf_s(calibFile, "%sground_calib_para.txt", dataPath[grp]);
|
|
|
|
|
|
poseCalibPara = _readCalibPara(calibFile);
|
|
|
|
|
|
|
|
|
|
|
|
for (int fidx = fileIdx[grp].nMin; fidx <= fileIdx[grp].nMax; fidx++)
|
|
|
|
|
|
{
|
|
|
|
|
|
//fidx =4;
|
|
|
|
|
|
char _scan_file[256];
|
|
|
|
|
|
sprintf_s(_scan_file, "%sscan3D_%d.txt", dataPath[grp], fidx);
|
|
|
|
|
|
std::vector<std::vector< SVzNL3DPosition>> scanLines;
|
|
|
|
|
|
vzReadLaserScanPointFromFile_XYZ_vector(_scan_file, scanLines);
|
|
|
|
|
|
if (scanLines.size() == 0)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
//转成plyTxt格式
|
|
|
|
|
|
//sprintf_s(_scan_file, "%s%d_ply_Hi229229.txt", dataPath[grp], fidx);
|
|
|
|
|
|
//wdSavePlyTxt(_scan_file, scanLines);
|
|
|
|
|
|
|
|
|
|
|
|
long t1 = (long)GetTickCount64();//统计时间
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
char _out_file[256];
|
|
|
|
|
|
sprintf_s(_out_file, "%sscanData_%d_calib.txt", dataPath[grp], fidx);
|
|
|
|
|
|
int headNullLines = 0;
|
|
|
|
|
|
_outputScanDataFile_vector(_out_file, scanLines, false, &headNullLines);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
SSG_cornerParam cornerParam;
|
|
|
|
|
|
cornerParam.cornerTh = 30; //45度角
|
|
|
|
|
|
cornerParam.scale = 5; // algoParam.bagParam.bagH / 8; // 15; // algoParam.bagParam.bagH / 8;
|
|
|
|
|
|
cornerParam.minEndingGap = 20; // algoParam.bagParam.bagW / 4;
|
|
|
|
|
|
cornerParam.minEndingGap_z = 20;
|
|
|
|
|
|
cornerParam.jumpCornerTh_1 = 10; //水平角度,小于此角度视为水平
|
|
|
|
|
|
cornerParam.jumpCornerTh_2 = 60;
|
|
|
|
|
|
SSG_outlierFilterParam filterParam;
|
|
|
|
|
|
filterParam.continuityTh = 20.0; //噪声滤除。当相邻点的z跳变大于此门限时,检查是否为噪声。若长度小于outlierLen, 视为噪声
|
|
|
|
|
|
filterParam.outlierTh = 5;
|
|
|
|
|
|
SSG_treeGrowParam growParam;
|
|
|
|
|
|
growParam.maxLineSkipNum = 10;
|
|
|
|
|
|
growParam.yDeviation_max = 10.0;
|
|
|
|
|
|
growParam.maxSkipDistance = 10.0;
|
|
|
|
|
|
growParam.zDeviation_max = 10.0;// algoParam.bagParam.bagH / 2; //袋子高度1/2
|
|
|
|
|
|
growParam.minLTypeTreeLen = 100; //mm
|
|
|
|
|
|
growParam.minVTypeTreeLen = 100; //mm
|
|
|
|
|
|
SSX_BQAssemblyPara workpieceParam;
|
|
|
|
|
|
workpieceParam.type = 0;
|
|
|
|
|
|
workpieceParam.lineLen = 160.0; //直线段长度
|
|
|
|
|
|
int errCode = 0;
|
|
|
|
|
|
SSX_BQAssemblyInfo assemblyPose = sx_BQ_computeAssemblyInfoFrom3D(
|
|
|
|
|
|
scanLines,
|
|
|
|
|
|
cornerParam,
|
|
|
|
|
|
filterParam,
|
|
|
|
|
|
growParam,
|
|
|
|
|
|
poseCalibPara,
|
|
|
|
|
|
workpieceParam,
|
|
|
|
|
|
&errCode);
|
|
|
|
|
|
long t2 = (long)GetTickCount64();
|
|
|
|
|
|
printf("%s: %d(ms)!\n", _scan_file, (int)(t2 - t1));
|
|
|
|
|
|
//输出测试结果
|
|
|
|
|
|
//sprintf_s(_scan_file, "%sresult\\LaserLine%d_result.txt", dataPath[grp], fidx);
|
|
|
|
|
|
//_outputRGBDScanLapWeld_RGBD(_scan_file, scanLines, assemblyPose);
|
|
|
|
|
|
sprintf_s(calibFile, "%sresult\\LaserLine%d_corner_info.txt", dataPath[grp], fidx);
|
|
|
|
|
|
_outputPoseInfo(calibFile, assemblyPose);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
2025-12-18 20:25:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
|
|
|
|
|
|
// 调试程序: F5 或调试 >“开始调试”菜单
|
|
|
|
|
|
|
|
|
|
|
|
// 入门使用技巧:
|
|
|
|
|
|
// 1. 使用解决方案资源管理器窗口添加/管理文件
|
|
|
|
|
|
// 2. 使用团队资源管理器窗口连接到源代码管理
|
|
|
|
|
|
// 3. 使用输出窗口查看生成输出和其他消息
|
|
|
|
|
|
// 4. 使用错误列表窗口查看错误
|
|
|
|
|
|
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
|
|
|
|
|
|
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
|