633 lines
22 KiB
C++
633 lines
22 KiB
C++
|
|
// BQ_workpieceCornerExtract_test.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
#include <iostream>
|
|||
|
|
#include <fstream>
|
|||
|
|
#include <vector>
|
|||
|
|
#include <stdio.h>
|
|||
|
|
#include <VZNL_Types.h>
|
|||
|
|
#include "direct.h"
|
|||
|
|
#include <string>
|
|||
|
|
#include "WD_particleSizeMeasure_Export.h"
|
|||
|
|
#include <opencv2/opencv.hpp>
|
|||
|
|
#include <Windows.h>
|
|||
|
|
#include <limits>
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
sscanf_s(linedata.c_str(), "{%f,%f,%f}-{%f,%f}-{%f,%f}", &X, &Y, &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 _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 _outputParticleSizeInfo(char* fileName, std::vector<SWD_ParticlePosInfo>& particles)
|
|||
|
|
{
|
|||
|
|
int particleSize = (int)particles.size();
|
|||
|
|
if (particleSize == 0)
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
std::ofstream sw(fileName);
|
|||
|
|
char dataStr[250];
|
|||
|
|
sprintf_s(dataStr, 250, "particleNum: %d", particleSize);
|
|||
|
|
sw << dataStr << std::endl;
|
|||
|
|
|
|||
|
|
for (int i = 0; i < particleSize; i++)
|
|||
|
|
{
|
|||
|
|
sprintf_s(dataStr, 250, " id_%d: (%g, %g, %g)", i, particles[i].size.length, particles[i].size.width, particles[i].size.height);
|
|||
|
|
sw << dataStr << std::endl;
|
|||
|
|
}
|
|||
|
|
sw.close();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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 _outputScanDataResult_RGBD(
|
|||
|
|
char* fileName,
|
|||
|
|
std::vector<std::vector<SVzNL3DPosition>>& scanLines,
|
|||
|
|
std::vector<SWD_ParticlePosInfo>& particles)
|
|||
|
|
{
|
|||
|
|
int lineNum = (int)scanLines.size();
|
|||
|
|
std::ofstream sw(fileName);
|
|||
|
|
int realLines = lineNum;
|
|||
|
|
if (particles.size() > 0)
|
|||
|
|
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 };
|
|||
|
|
int size = 1;
|
|||
|
|
int lineIdx = 0;
|
|||
|
|
for (int line = 0; line < lineNum; line++)
|
|||
|
|
{
|
|||
|
|
int linePtNum = (int)scanLines[line].size();
|
|||
|
|
if (linePtNum == 0)
|
|||
|
|
continue;
|
|||
|
|
|
|||
|
|
int vldNum = 0;
|
|||
|
|
for (int i = 0; i < linePtNum; i++)
|
|||
|
|
{
|
|||
|
|
if (scanLines[line][i].pt3D.z > 1e-4)
|
|||
|
|
vldNum++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
sw << "Line_" << lineIdx << "_0_" << vldNum << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
for (int i = 0; i < linePtNum; i++)
|
|||
|
|
{
|
|||
|
|
if (scanLines[line][i].pt3D.z <= 1e-4)
|
|||
|
|
continue;
|
|||
|
|
|
|||
|
|
SVzNL3DPosition* pt3D = &scanLines[line][i];
|
|||
|
|
int mkID = pt3D->nPointIdx;
|
|||
|
|
if (mkID < 2)
|
|||
|
|
{
|
|||
|
|
rgb = { 200, 200, 200 };
|
|||
|
|
size = 1;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
rgb.r = (mkID * 97) % 256;
|
|||
|
|
rgb.g = (mkID * 73) % 256;
|
|||
|
|
rgb.b = (mkID * 59) % 256;
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rgb = { 255,0,0 };
|
|||
|
|
if (particles.size() > 0)
|
|||
|
|
{
|
|||
|
|
int objNum = (int)particles.size();
|
|||
|
|
int lineIdx = 0;
|
|||
|
|
for (int i = 0; i < objNum; i++)
|
|||
|
|
{
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[0].x << "," << particles[i].vertix[0].y << "," << particles[i].vertix[0].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[1].x << "," << particles[i].vertix[1].y << "," << particles[i].vertix[1].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[1].x << "," << particles[i].vertix[1].y << "," << particles[i].vertix[1].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[2].x << "," << particles[i].vertix[2].y << "," << particles[i].vertix[2].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[2].x << "," << particles[i].vertix[2].y << "," << particles[i].vertix[2].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[3].x << "," << particles[i].vertix[3].y << "," << particles[i].vertix[3].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[3].x << "," << particles[i].vertix[3].y << "," << particles[i].vertix[3].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[0].x << "," << particles[i].vertix[0].y << "," << particles[i].vertix[0].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[0].x << "," << particles[i].vertix[0].y << "," << particles[i].vertix[0].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[4].x << "," << particles[i].vertix[4].y << "," << particles[i].vertix[4].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[1].x << "," << particles[i].vertix[1].y << "," << particles[i].vertix[1].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[5].x << "," << particles[i].vertix[5].y << "," << particles[i].vertix[5].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[2].x << "," << particles[i].vertix[2].y << "," << particles[i].vertix[2].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[6].x << "," << particles[i].vertix[6].y << "," << particles[i].vertix[6].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[3].x << "," << particles[i].vertix[3].y << "," << particles[i].vertix[3].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[7].x << "," << particles[i].vertix[7].y << "," << particles[i].vertix[7].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[4].x << "," << particles[i].vertix[4].y << "," << particles[i].vertix[4].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[5].x << "," << particles[i].vertix[5].y << "," << particles[i].vertix[5].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[5].x << "," << particles[i].vertix[5].y << "," << particles[i].vertix[5].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[6].x << "," << particles[i].vertix[6].y << "," << particles[i].vertix[6].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[6].x << "," << particles[i].vertix[6].y << "," << particles[i].vertix[6].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[7].x << "," << particles[i].vertix[7].y << "," << particles[i].vertix[7].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[7].x << "," << particles[i].vertix[7].y << "," << particles[i].vertix[7].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[i].vertix[4].x << "," << particles[i].vertix[4].y << "," << particles[i].vertix[4].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
}
|
|||
|
|
sw << "Poly_" << lineIdx << "_2" << std::endl;
|
|||
|
|
sw << "{" << particles[0].vertix[0].x << "," << particles[0].vertix[0].y << "," << particles[0].vertix[0].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
sw << "{" << particles[0].vertix[1].x << "," << particles[0].vertix[1].y << "," << particles[0].vertix[1].z << "}-";
|
|||
|
|
sw << "{0,0}-{0,0}-";
|
|||
|
|
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl;
|
|||
|
|
lineIdx++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
sw.close();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#define CONVERT_TO_GRID 0
|
|||
|
|
#define TEST_COMPUTE_CALIB_PARA 0
|
|||
|
|
#define TEST_COMPUTE_PARTICE_SIZE 1
|
|||
|
|
#define TEST_GROUP 1
|
|||
|
|
int main()
|
|||
|
|
{
|
|||
|
|
const char* dataPath[TEST_GROUP] = {
|
|||
|
|
"F:\\ShangGu\\粒径数据\\曝光\\3D数据\\" //0
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
SVzNLRange fileIdx[TEST_GROUP] = {
|
|||
|
|
{1,10}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
#if TEST_COMPUTE_PARTICE_SIZE
|
|||
|
|
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 = 2600.0;
|
|||
|
|
for (int i = 0; i < 9; i++)
|
|||
|
|
poseCalibPara.invRMatrix[i] = poseCalibPara.planeCalib[i];
|
|||
|
|
char calibFile[250];
|
|||
|
|
#if 0
|
|||
|
|
if (grp == 0)
|
|||
|
|
{
|
|||
|
|
sprintf_s(calibFile, "F:\\ShangGu\\粒径数据\\曝光\\3D数据\\ground_calib_para.txt");
|
|||
|
|
poseCalibPara = _readCalibPara(calibFile);
|
|||
|
|
}
|
|||
|
|
#endif
|
|||
|
|
for (int fidx = fileIdx[grp].nMin; fidx <= fileIdx[grp].nMax; fidx++)
|
|||
|
|
{
|
|||
|
|
//fidx =1;
|
|||
|
|
char _scan_file[256];
|
|||
|
|
sprintf_s(_scan_file, "%sgridScanData_%d.txt", dataPath[grp], fidx);
|
|||
|
|
std::vector<std::vector< SVzNL3DPosition>> scanLines;
|
|||
|
|
vzReadLaserScanPointFromFile_XYZ_vector(_scan_file, scanLines);
|
|||
|
|
|
|||
|
|
long t1 = (long)GetTickCount64();//统计时间
|
|||
|
|
for (int i = 0, i_max = (int)scanLines.size(); i < i_max; i++)
|
|||
|
|
{
|
|||
|
|
if (i == 14)
|
|||
|
|
int kkk = 1;
|
|||
|
|
//行处理
|
|||
|
|
//调平,去除地面
|
|||
|
|
wd_lineDataR(scanLines[i], poseCalibPara.planeCalib, -1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SWD_paricleSizeParam paricleSizeParam;
|
|||
|
|
paricleSizeParam.minSize = { 100.0, 100.0, 100.0 };
|
|||
|
|
paricleSizeParam.alarmSize = { 1000.0, 1000.0, 1000.0 };
|
|||
|
|
SWD_PSM_algoParam algoParam;
|
|||
|
|
algoParam.filterParam.continuityTh = 20.0; //噪声滤除。当相邻点的z跳变大于此门限时,检查是否为噪声。若长度小于outlierLen, 视为噪声
|
|||
|
|
algoParam.filterParam.outlierTh = 5;
|
|||
|
|
algoParam.cornerParam.cornerTh = 60; //45度角
|
|||
|
|
algoParam.cornerParam.scale = 50; // algoParam.bagParam.bagH / 8; // 15; // algoParam.bagParam.bagH / 8;
|
|||
|
|
algoParam.cornerParam.minEndingGap = 20; // algoParam.bagParam.bagW / 4;
|
|||
|
|
algoParam.cornerParam.minEndingGap_z = 20;
|
|||
|
|
algoParam.cornerParam.jumpCornerTh_1 = 10; //水平角度,小于此角度视为水平
|
|||
|
|
algoParam.cornerParam.jumpCornerTh_2 = 60;
|
|||
|
|
algoParam.growParam.maxLineSkipNum = 10;
|
|||
|
|
algoParam.growParam.yDeviation_max = 10.0;
|
|||
|
|
algoParam.growParam.maxSkipDistance = 10.0;
|
|||
|
|
algoParam.growParam.zDeviation_max = 10.0;// algoParam.bagParam.bagH / 2; //袋子高度1/2
|
|||
|
|
algoParam.growParam.minLTypeTreeLen = 100; //mm
|
|||
|
|
algoParam.growParam.minVTypeTreeLen = 100; //mm
|
|||
|
|
|
|||
|
|
int errCode = 0;
|
|||
|
|
std::vector<SWD_ParticlePosInfo> particles;
|
|||
|
|
wd_particleSizeMeasure(
|
|||
|
|
scanLines,
|
|||
|
|
paricleSizeParam,
|
|||
|
|
poseCalibPara,
|
|||
|
|
algoParam,
|
|||
|
|
particles,
|
|||
|
|
&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);
|
|||
|
|
_outputScanDataResult_RGBD(_scan_file, scanLines, particles);
|
|||
|
|
sprintf_s(calibFile, "%sresult\\LaserLine%d_corner_info.txt", dataPath[grp], fidx);
|
|||
|
|
_outputParticleSizeInfo(calibFile, particles);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endif
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
|
|||
|
|
// 调试程序: F5 或调试 >“开始调试”菜单
|
|||
|
|
|
|||
|
|
// 入门使用技巧:
|
|||
|
|
// 1. 使用解决方案资源管理器窗口添加/管理文件
|
|||
|
|
// 2. 使用团队资源管理器窗口连接到源代码管理
|
|||
|
|
// 3. 使用输出窗口查看生成输出和其他消息
|
|||
|
|
// 4. 使用错误列表窗口查看错误
|
|||
|
|
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
|
|||
|
|
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
|
|||
|
|
|