2025-07-15 21:35:15 +08:00
|
|
|
|
// QRcode3Ddetection_test.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <VZNL_Types.h>
|
|
|
|
|
|
#include "direct.h"
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include "WD_QRcode3Ddetection_Export.h"
|
|
|
|
|
|
#include <opencv2/opencv.hpp>
|
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
|
{
|
|
|
|
|
|
int r;
|
|
|
|
|
|
int g;
|
|
|
|
|
|
int b;
|
|
|
|
|
|
}SG_color;
|
|
|
|
|
|
|
|
|
|
|
|
void vzReadLaserScanPointFromFile_plyTxt(const char* fileName, std::vector< SVzNL3DPoint>& scanData, bool removeZeros, bool exchangeXY)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ifstream inputFile(fileName);
|
|
|
|
|
|
std::string linedata;
|
|
|
|
|
|
|
|
|
|
|
|
if (inputFile.is_open() == false)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
while (std::getline(inputFile, linedata))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (linedata.empty())
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
double X, Y, Z, tmp;
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "%lf %lf %lf %lf", &X, &Y, &Z, &tmp);
|
|
|
|
|
|
if (true == removeZeros)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Z > 1e-4)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPoint a_pt;
|
|
|
|
|
|
if (true == exchangeXY)
|
|
|
|
|
|
{
|
|
|
|
|
|
a_pt.x = Y; //将扫描线调整为Y方向;扫描方向为X方向
|
|
|
|
|
|
a_pt.y = X;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
a_pt.x = X;
|
|
|
|
|
|
a_pt.y = Y;
|
|
|
|
|
|
}
|
|
|
|
|
|
a_pt.z = Z;
|
|
|
|
|
|
scanData.push_back(a_pt);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPoint a_pt;
|
|
|
|
|
|
if (true == exchangeXY)
|
|
|
|
|
|
{
|
|
|
|
|
|
a_pt.x = Y; //将扫描线调整为Y方向;扫描方向为X方向
|
|
|
|
|
|
a_pt.y = X;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
a_pt.x = X;
|
|
|
|
|
|
a_pt.y = Y;
|
|
|
|
|
|
}
|
|
|
|
|
|
a_pt.z = Z;
|
|
|
|
|
|
scanData.push_back(a_pt);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-08 02:13:19 +08:00
|
|
|
|
typedef struct
|
|
|
|
|
|
{
|
|
|
|
|
|
int x;
|
|
|
|
|
|
double y;
|
|
|
|
|
|
double z;
|
|
|
|
|
|
} WD_Encode3DPoint;
|
|
|
|
|
|
void vzReadLaserScanPointFromFile_encodePlyTxt(const char* fileName, std::vector< WD_Encode3DPoint>& scanData)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ifstream inputFile(fileName);
|
|
|
|
|
|
std::string linedata;
|
|
|
|
|
|
|
|
|
|
|
|
if (inputFile.is_open() == false)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
while (std::getline(inputFile, linedata))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (linedata.empty())
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
int X;
|
|
|
|
|
|
double Y, Z, tmp;
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "%d,%lf,%lf", &X, &Y, &Z);
|
|
|
|
|
|
WD_Encode3DPoint a_pt;
|
|
|
|
|
|
a_pt.x = X;
|
|
|
|
|
|
a_pt.y = Y;
|
|
|
|
|
|
a_pt.z = Z;
|
|
|
|
|
|
scanData.push_back(a_pt);
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
void convertEncodePlyToVzData(std::vector< WD_Encode3DPoint>& scanData, std::vector<std::vector<SVzNL3DPosition>>& scanLines, double stepping, bool toGrid)
|
|
|
|
|
|
{
|
|
|
|
|
|
int size = (int)scanData.size();
|
|
|
|
|
|
int preEnc = -1;
|
|
|
|
|
|
std::vector<SVzNL3DPosition> a_line;
|
|
|
|
|
|
int vldNum = 0;
|
|
|
|
|
|
double lineX = 0;
|
|
|
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
WD_Encode3DPoint a_ply = scanData[i];
|
|
|
|
|
|
if (a_ply.x != preEnc) //new line
|
|
|
|
|
|
{
|
|
|
|
|
|
if (vldNum > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
scanLines.push_back(a_line);
|
|
|
|
|
|
a_line.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (preEnc < 0)
|
|
|
|
|
|
lineX = 0;
|
|
|
|
|
|
else
|
|
|
|
|
|
lineX += (double)(a_ply.x - preEnc) * stepping;
|
|
|
|
|
|
preEnc = a_ply.x;
|
|
|
|
|
|
vldNum = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SVzNL3DPosition a_pt;
|
|
|
|
|
|
a_pt.nPointIdx = vldNum;
|
|
|
|
|
|
|
|
|
|
|
|
bool zeroPt = true;
|
|
|
|
|
|
if ((a_ply.z > 29.0) && (a_ply.z < 34.0))
|
|
|
|
|
|
{
|
|
|
|
|
|
a_pt.pt3D.x = lineX;
|
|
|
|
|
|
a_pt.pt3D.y = a_ply.y;
|
|
|
|
|
|
a_pt.pt3D.z = a_ply.z;
|
|
|
|
|
|
zeroPt = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
a_pt.pt3D.x = 0;
|
|
|
|
|
|
a_pt.pt3D.y = 0;
|
|
|
|
|
|
a_pt.pt3D.z = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (toGrid == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
a_line.push_back(a_pt);
|
|
|
|
|
|
vldNum++;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (false == zeroPt)
|
|
|
|
|
|
{
|
|
|
|
|
|
a_line.push_back(a_pt);
|
|
|
|
|
|
vldNum++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-15 21:35:15 +08:00
|
|
|
|
void _outputScanDataFile_vector(char* fileName, std::vector<std::vector<SVzNL3DPosition>>& scanLines, bool removeZeros, int* headNullLines)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ofstream sw(fileName);
|
|
|
|
|
|
int lineNum = 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 = 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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-08 02:13:19 +08:00
|
|
|
|
void _outputScanPlyTxtFile_vector(char* fileName, std::vector<std::vector<SVzNL3DPosition>>& scanLines, bool removeZeros, int* headNullLines)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ofstream sw(fileName);
|
|
|
|
|
|
int lineNum = scanLines.size();
|
|
|
|
|
|
if (lineNum == 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
int null_lines = 0;
|
|
|
|
|
|
bool counterNull = true;
|
|
|
|
|
|
for (int line = 0; line < lineNum; line++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int linePtNum = scanLines[line].size();
|
|
|
|
|
|
if (linePtNum == 0)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
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<< std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (true == counterNull)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (true == isNull)
|
|
|
|
|
|
null_lines++;
|
|
|
|
|
|
else
|
|
|
|
|
|
counterNull = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*headNullLines = null_lines;
|
|
|
|
|
|
sw.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-15 21:35:15 +08:00
|
|
|
|
void _outputRGBDScanDataFile_RGBD(
|
|
|
|
|
|
char* fileName,
|
|
|
|
|
|
std::vector<std::vector<SVzNL3DPosition>>& scanLines,
|
|
|
|
|
|
std::vector< SVzNL3DPosition> objPoints)
|
|
|
|
|
|
{
|
|
|
|
|
|
int lineNum = scanLines.size();
|
|
|
|
|
|
std::ofstream sw(fileName);
|
|
|
|
|
|
int realLines = lineNum;
|
|
|
|
|
|
if (objPoints.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 };
|
|
|
|
|
|
|
|
|
|
|
|
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 = 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];
|
|
|
|
|
|
int featureType = pt3D->nPointIdx;
|
|
|
|
|
|
if (LINE_FEATURE_PEAK_TOP == featureType)
|
|
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (objPoints.size() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
int linePtNum = objPoints.size();
|
|
|
|
|
|
sw << "Line_" << lineNum << "_0_" << linePtNum+1 << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
rgb = { 0, 0, 255 };
|
|
|
|
|
|
size = 25;
|
|
|
|
|
|
for (int i = 0; i < linePtNum; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
float x = (float)objPoints[i].pt3D.x;
|
|
|
|
|
|
float y = (float)objPoints[i].pt3D.y;
|
|
|
|
|
|
float z = (float)objPoints[i].pt3D.z;
|
|
|
|
|
|
sw << "{" << x << "," << y << "," << z << "}-";
|
|
|
|
|
|
sw << "{0,0}-{0,0}-";
|
|
|
|
|
|
sw << "{" << rgb.r << "," << rgb.g << "," << rgb.b << "," << size << " }" << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
float x = (float)objPoints[0].pt3D.x;
|
|
|
|
|
|
float y = (float)objPoints[0].pt3D.y;
|
|
|
|
|
|
float z = (float)objPoints[0].pt3D.z;
|
|
|
|
|
|
sw << "{" << x << "," << y << "," << z << "}-";
|
|
|
|
|
|
sw << "{0,0}-{0,0}-";
|
|
|
|
|
|
sw << "{" << rgb.r << "," << rgb.g << "," << rgb.b << "," << size << " }" << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
sw.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _outputScanDataFile_ptr(char* fileName, SVzNL3DLaserLine* scanData, int lineNum)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ofstream sw(fileName);
|
|
|
|
|
|
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++)
|
|
|
|
|
|
{
|
|
|
|
|
|
sw << "Line_" << line << "_" << scanData[line].nTimeStamp << "_" << scanData[line].nPositionCnt << std::endl;
|
|
|
|
|
|
for (int i = 0; i < scanData[line].nPositionCnt; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPosition* pt3D = &scanData[line].p3DPosition[i];
|
|
|
|
|
|
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}" << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
sw.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define DATA_VER_OLD 0
|
|
|
|
|
|
#define DATA_VER_NEW 1
|
|
|
|
|
|
#define DATA_VER_FROM_CUSTOM 2
|
|
|
|
|
|
#define VZ_LASER_LINE_PT_MAX_NUM 4096
|
|
|
|
|
|
SVzNL3DLaserLine* vzReadLaserScanPointFromFile_XYZ(const char* fileName, int* scanLineNum, float* scanV,
|
|
|
|
|
|
int* dataCalib, int* scanMaxStamp, int* canClockUnit)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ifstream inputFile(fileName);
|
|
|
|
|
|
std::string linedata;
|
|
|
|
|
|
|
|
|
|
|
|
if (inputFile.is_open() == false)
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
SVzNL3DLaserLine* _scanLines = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
int lines = 0;
|
|
|
|
|
|
int dataElements = 4;
|
|
|
|
|
|
int firstIndex = -1;
|
|
|
|
|
|
|
|
|
|
|
|
int dataFileVer = DATA_VER_OLD;
|
|
|
|
|
|
std::getline(inputFile, linedata); //第一行
|
|
|
|
|
|
int lineNum = 0;
|
|
|
|
|
|
if (0 == strncmp("LineNum:", linedata.c_str(), 8))
|
|
|
|
|
|
{
|
|
|
|
|
|
dataFileVer = DATA_VER_NEW;
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "LineNum:%d", &lines);
|
|
|
|
|
|
if (lines == 0)
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
lineNum = lines;
|
|
|
|
|
|
_scanLines = (SVzNL3DLaserLine*)malloc(sizeof(SVzNL3DLaserLine) * (lineNum + 1));
|
|
|
|
|
|
memset(_scanLines, 0, sizeof(SVzNL3DLaserLine) * (lineNum + 1));
|
|
|
|
|
|
if (scanLineNum)
|
|
|
|
|
|
*scanLineNum = lines;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (0 == strncmp("LineNum_", linedata.c_str(), 8))
|
|
|
|
|
|
{
|
|
|
|
|
|
dataFileVer = DATA_VER_OLD;
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "LineNum_%d", &lines);
|
|
|
|
|
|
if (lines == 0)
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
lineNum = lines;
|
|
|
|
|
|
_scanLines = (SVzNL3DLaserLine*)malloc(sizeof(SVzNL3DLaserLine) * (lineNum + 1));
|
|
|
|
|
|
memset(_scanLines, 0, sizeof(SVzNL3DLaserLine) * (lineNum + 1));
|
|
|
|
|
|
if (scanLineNum)
|
|
|
|
|
|
*scanLineNum = lines;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (_scanLines == NULL)
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
int ptNum = 0;
|
|
|
|
|
|
int lineIdx = -1;
|
|
|
|
|
|
int ptIdx = 0;
|
|
|
|
|
|
SVzNL3DPosition* p3DPoint = NULL;
|
|
|
|
|
|
if (dataFileVer == DATA_VER_NEW)
|
|
|
|
|
|
{
|
|
|
|
|
|
while (getline(inputFile, linedata))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (0 == strncmp("ScanSpeed:", linedata.c_str(), 10))
|
|
|
|
|
|
{
|
|
|
|
|
|
double lineV = 0;
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "ScanSpeed:%lf", &lineV);
|
|
|
|
|
|
if (scanV)
|
|
|
|
|
|
*scanV = (float)lineV;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (0 == strncmp("PointAdjust:", linedata.c_str(), 12))
|
|
|
|
|
|
{
|
|
|
|
|
|
int ptAdjusted = 0;
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "PointAdjust:%d", &ptAdjusted);
|
|
|
|
|
|
if (dataCalib)
|
|
|
|
|
|
*dataCalib = ptAdjusted;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (0 == strncmp("MaxTimeStamp:", linedata.c_str(), 13))
|
|
|
|
|
|
{
|
|
|
|
|
|
unsigned int maxTimeStamp = 0;
|
|
|
|
|
|
unsigned int timePerStamp = 0;
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "MaxTimeStamp:%u_%u", &maxTimeStamp, &timePerStamp);
|
|
|
|
|
|
if (scanMaxStamp)
|
|
|
|
|
|
*scanMaxStamp = maxTimeStamp;
|
|
|
|
|
|
if (canClockUnit)
|
|
|
|
|
|
*canClockUnit = timePerStamp;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (0 == strncmp("Line_", linedata.c_str(), 5))
|
|
|
|
|
|
{
|
|
|
|
|
|
int lineIndex;
|
|
|
|
|
|
unsigned int timeStamp;
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "Line_%d_%u_%d", &lineIndex, &timeStamp, &ptNum);
|
|
|
|
|
|
if (firstIndex < 0)
|
|
|
|
|
|
firstIndex = lineIndex;
|
|
|
|
|
|
|
|
|
|
|
|
lineIndex = lineIndex - firstIndex;
|
|
|
|
|
|
if ((lineIndex < 0) || (lineIndex >= lines))
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
//new Line
|
|
|
|
|
|
lineIdx++;
|
|
|
|
|
|
if (ptNum > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
p3DPoint = (SVzNL3DPosition*)malloc(sizeof(SVzNL3DPosition) * ptNum);
|
|
|
|
|
|
memset(p3DPoint, 0, sizeof(SVzNL3DPosition) * ptNum);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
p3DPoint = NULL;
|
|
|
|
|
|
_scanLines[lineIdx].nPositionCnt = 0;
|
|
|
|
|
|
_scanLines[lineIdx].nTimeStamp = timeStamp;
|
|
|
|
|
|
_scanLines[lineIdx].p3DPosition = p3DPoint;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
int id = _scanLines[lineIdx].nPositionCnt;
|
|
|
|
|
|
if (id < ptNum)
|
|
|
|
|
|
{
|
|
|
|
|
|
p3DPoint[id].pt3D.x = X;
|
|
|
|
|
|
p3DPoint[id].pt3D.y = Y;
|
|
|
|
|
|
p3DPoint[id].pt3D.z = Z;
|
|
|
|
|
|
_scanLines[lineIdx].nPositionCnt = id + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (dataFileVer == DATA_VER_OLD)
|
|
|
|
|
|
{
|
|
|
|
|
|
while (getline(inputFile, linedata))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (0 == strncmp("DataElements_", linedata.c_str(), 13))
|
|
|
|
|
|
{
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "DataElements_%d", &dataElements);
|
|
|
|
|
|
if ((dataElements != 3) && (dataElements != 4))
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (0 == strncmp("LineV_", linedata.c_str(), 6))
|
|
|
|
|
|
{
|
|
|
|
|
|
double lineV = 0;
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "LineV_%lf", &lineV);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (0 == strncmp("Line_", linedata.c_str(), 5))
|
|
|
|
|
|
{
|
|
|
|
|
|
int lineIndex;
|
|
|
|
|
|
unsigned int timeStamp;
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "Line_%d_%u", &lineIndex, &timeStamp);
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
if (scanLineListTail == NULL)
|
|
|
|
|
|
firstIndex = lineIndex;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
lineIndex = lineIndex - firstIndex;
|
|
|
|
|
|
if ((lineIndex < 0) || (lineIndex >= lines))
|
|
|
|
|
|
break;
|
|
|
|
|
|
//new Line
|
|
|
|
|
|
//new Line
|
|
|
|
|
|
lineIdx++;
|
|
|
|
|
|
p3DPoint = (SVzNL3DPosition*)malloc(sizeof(SVzNL3DPosition) * VZ_LASER_LINE_PT_MAX_NUM);
|
|
|
|
|
|
memset(p3DPoint, 0, sizeof(SVzNL3DPosition) * VZ_LASER_LINE_PT_MAX_NUM);
|
|
|
|
|
|
_scanLines[lineIdx].nPositionCnt = 0;
|
|
|
|
|
|
_scanLines[lineIdx].nTimeStamp = timeStamp;
|
|
|
|
|
|
_scanLines[lineIdx].p3DPosition = p3DPoint;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (0 == strncmp("(", linedata.c_str(), 1))
|
|
|
|
|
|
{
|
|
|
|
|
|
float X, Y, Z;
|
|
|
|
|
|
int imageY = 0;
|
|
|
|
|
|
if (dataElements == 4)
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "(%f,%f,%f,%d)", &X, &Y, &Z, &imageY);
|
|
|
|
|
|
else
|
|
|
|
|
|
sscanf_s(linedata.c_str(), "(%f,%f,%f)", &X, &Y, &Z);
|
|
|
|
|
|
int id = _scanLines[lineIdx].nPositionCnt;
|
|
|
|
|
|
if (id < VZ_LASER_LINE_PT_MAX_NUM)
|
|
|
|
|
|
{
|
|
|
|
|
|
p3DPoint[id].pt3D.x = X;
|
|
|
|
|
|
p3DPoint[id].pt3D.y = Y;
|
|
|
|
|
|
p3DPoint[id].pt3D.z = Z;
|
|
|
|
|
|
_scanLines[lineIdx].nPositionCnt = id + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
inputFile.close();
|
|
|
|
|
|
return _scanLines;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void vzReadLaserScanPointFromFile_XYZ_vector(const char* fileName, std::vector< SVzNL3DPoint>& scanData)
|
|
|
|
|
|
{
|
|
|
|
|
|
std::ifstream inputFile(fileName);
|
|
|
|
|
|
std::string linedata;
|
|
|
|
|
|
|
|
|
|
|
|
if (inputFile.is_open() == false)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
while (getline(inputFile, linedata))
|
|
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
SVzNL3DPoint a_pt;
|
|
|
|
|
|
a_pt.x = X;
|
|
|
|
|
|
a_pt.y = Y;
|
|
|
|
|
|
a_pt.z = Z;
|
|
|
|
|
|
scanData.push_back(a_pt);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
inputFile.close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 _getRoiClouds(
|
|
|
|
|
|
std::vector< std::vector<SVzNL3DPosition>>& scanLines,
|
|
|
|
|
|
int startLine,
|
|
|
|
|
|
int endLine,
|
|
|
|
|
|
int startPtIdx,
|
|
|
|
|
|
int endPtIdx,
|
|
|
|
|
|
std::vector< std::vector<SVzNL3DPosition>>& roiScanLines)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = startLine; i < endLine; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (i >= scanLines.size())
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<SVzNL3DPosition> cut_line;
|
|
|
|
|
|
std::vector<SVzNL3DPosition>& a_line = scanLines[i];
|
|
|
|
|
|
for (int j = startPtIdx; j < endPtIdx; j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
SVzNL3DPosition a_pt;
|
|
|
|
|
|
if (j >= a_line.size())
|
|
|
|
|
|
{
|
|
|
|
|
|
a_pt.nPointIdx = 0;
|
|
|
|
|
|
a_pt.pt3D = { 0,0,0 };
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
a_pt = a_line[j];
|
|
|
|
|
|
cut_line.push_back(a_pt);
|
|
|
|
|
|
}
|
|
|
|
|
|
roiScanLines.push_back(cut_line);
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-08 02:13:19 +08:00
|
|
|
|
#define CONVERT_TO_GRID 1
|
2025-07-15 21:35:15 +08:00
|
|
|
|
#define TEST_COMPUTE_CALIB_PARA 0
|
2025-11-08 02:13:19 +08:00
|
|
|
|
#define TEST_COMPUTE_QRCODE_IMG 0
|
|
|
|
|
|
#define TEST_GROUP 2
|
2025-07-15 21:35:15 +08:00
|
|
|
|
int main()
|
|
|
|
|
|
{
|
|
|
|
|
|
const char* dataPath[TEST_GROUP] = {
|
2025-11-08 02:13:19 +08:00
|
|
|
|
"F:\\ShangGu\\项目\\国铭铸管\\二维码\\", //0
|
|
|
|
|
|
"F:\\ShangGu\\项目\\国铭铸管\\字符\\" //1
|
2025-07-15 21:35:15 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SVzNLRange fileIdx[TEST_GROUP] = {
|
2025-10-06 14:21:33 +08:00
|
|
|
|
{3,3}, {1,8}
|
2025-07-15 21:35:15 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-08 02:13:19 +08:00
|
|
|
|
#if CONVERT_TO_GRID
|
|
|
|
|
|
int convertGrp = 1;
|
|
|
|
|
|
for (int fidx = fileIdx[convertGrp].nMin; fidx <= fileIdx[convertGrp].nMax; fidx++)
|
|
|
|
|
|
{
|
|
|
|
|
|
char _scan_file[256];
|
|
|
|
|
|
sprintf_s(_scan_file, "%sdata%d.txt", dataPath[convertGrp], fidx);
|
|
|
|
|
|
|
|
|
|
|
|
std::vector< WD_Encode3DPoint> scanPly;
|
|
|
|
|
|
vzReadLaserScanPointFromFile_encodePlyTxt(_scan_file, scanPly);
|
|
|
|
|
|
|
|
|
|
|
|
double stepping = 0.0625;
|
|
|
|
|
|
std::vector<std::vector< SVzNL3DPosition>> scanData;
|
|
|
|
|
|
std::vector<std::vector< SVzNL3DPosition>> gridScanData;
|
|
|
|
|
|
bool toGrid = false;
|
|
|
|
|
|
convertEncodePlyToVzData(scanPly, scanData, stepping, toGrid);
|
|
|
|
|
|
toGrid = true;
|
|
|
|
|
|
convertEncodePlyToVzData(scanPly, gridScanData, stepping, toGrid);
|
|
|
|
|
|
//将数据恢复为按扫描线存储格式
|
|
|
|
|
|
sprintf_s(_scan_file, "%sscanDataPlyTxt_%d.txt", dataPath[convertGrp], fidx);
|
|
|
|
|
|
int headNullLines = 0;
|
|
|
|
|
|
_outputScanPlyTxtFile_vector(_scan_file, scanData, false, &headNullLines);
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
sprintf_s(_scan_file, "%svzScanData_%d.txt", dataPath[convertGrp], fidx);
|
|
|
|
|
|
int headNullLines = 0;
|
|
|
|
|
|
_outputScanDataFile_vector(_scan_file, scanData, false, &headNullLines);
|
|
|
|
|
|
sprintf_s(_scan_file, "%svzScanData_grid_%d.txt", dataPath[convertGrp], fidx);
|
|
|
|
|
|
_outputScanDataFile_vector(_scan_file, gridScanData, false, &headNullLines);
|
|
|
|
|
|
printf("%s: head null lines = %d\n", _scan_file, headNullLines);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2025-07-15 21:35:15 +08:00
|
|
|
|
#if TEST_COMPUTE_CALIB_PARA
|
|
|
|
|
|
char _calib_datafile[256];
|
|
|
|
|
|
sprintf_s(_calib_datafile, "F:\\ShangGu\\项目\\工件端部圆点二维码\\LaserLine3_grid.txt");
|
|
|
|
|
|
int lineNum = 0;
|
|
|
|
|
|
float lineV = 0.0f;
|
|
|
|
|
|
int dataCalib = 0;
|
|
|
|
|
|
int maxTimeStamp = 0;
|
|
|
|
|
|
int clockPerSecond = 0;
|
|
|
|
|
|
SVzNL3DLaserLine* laser3DPoints = vzReadLaserScanPointFromFile_XYZ(_calib_datafile, &lineNum, &lineV, &dataCalib, &maxTimeStamp, &clockPerSecond);
|
|
|
|
|
|
if (laser3DPoints)
|
|
|
|
|
|
{
|
|
|
|
|
|
SSG_planeCalibPara calibPara = wd_getBaseCalibPara(
|
|
|
|
|
|
laser3DPoints,
|
|
|
|
|
|
lineNum);
|
|
|
|
|
|
//结果进行验证
|
|
|
|
|
|
for (int i = 0; i < lineNum; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (i == 14)
|
|
|
|
|
|
int kkk = 1;
|
|
|
|
|
|
//行处理
|
|
|
|
|
|
//调平,去除地面
|
|
|
|
|
|
wd_lineDataR(&laser3DPoints[i], calibPara.planeCalib, -1);// calibPara.planeHeight);
|
|
|
|
|
|
}
|
|
|
|
|
|
//
|
|
|
|
|
|
char calibFile[250];
|
|
|
|
|
|
sprintf_s(calibFile, "F:\\ShangGu\\项目\\工件端部圆点二维码\\ground_calib_para.txt");
|
|
|
|
|
|
_outputCalibPara(calibFile, calibPara);
|
|
|
|
|
|
char _out_file[256];
|
|
|
|
|
|
sprintf_s(_out_file, "F:\\ShangGu\\项目\\工件端部圆点二维码\\LaserLine3_calib_data.txt");
|
|
|
|
|
|
_outputScanDataFile_ptr(_out_file, laser3DPoints, lineNum);
|
|
|
|
|
|
printf("%s: calib done!\n", _calib_datafile);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if TEST_COMPUTE_QRCODE_IMG
|
|
|
|
|
|
for (int grp = 0; grp <= 0; grp++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int cloud_rows = 4200;
|
|
|
|
|
|
int cloud_cols = 2160;
|
|
|
|
|
|
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, "F:\\ShangGu\\项目\\工件端部圆点二维码\\ground_calib_para.txt");
|
|
|
|
|
|
poseCalibPara = _readCalibPara(calibFile);
|
|
|
|
|
|
|
|
|
|
|
|
for (int fidx = fileIdx[grp].nMin; fidx <= fileIdx[grp].nMax; fidx++)
|
|
|
|
|
|
{
|
|
|
|
|
|
//fidx = 1;
|
|
|
|
|
|
char _scan_file[256];
|
|
|
|
|
|
sprintf_s(_scan_file, "%s%d_Cloud.txt", dataPath[grp], fidx);
|
|
|
|
|
|
std::vector< SVzNL3DPoint> scanData;
|
|
|
|
|
|
bool removeZeros = false;
|
|
|
|
|
|
bool exchangeXY = true;
|
|
|
|
|
|
if (fidx < 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
cloud_cols = 1; //单行测试文件
|
|
|
|
|
|
exchangeXY = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
cloud_cols = 2160; //单行测试文件
|
|
|
|
|
|
exchangeXY = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (fidx == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
vzReadLaserScanPointFromFile_XYZ_vector(_scan_file, scanData);
|
|
|
|
|
|
cloud_cols = 1100;
|
|
|
|
|
|
cloud_rows = 1300;
|
|
|
|
|
|
if (scanData.size() != (cloud_rows * cloud_cols))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
vzReadLaserScanPointFromFile_plyTxt(_scan_file, scanData, removeZeros, exchangeXY);
|
|
|
|
|
|
if (scanData.size() != (cloud_rows * cloud_cols))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
//将数据恢复为按扫描线存储格式
|
|
|
|
|
|
std::vector< std::vector<SVzNL3DPosition>> scanLines;
|
|
|
|
|
|
wd_getScanLines(scanData, scanLines, cloud_rows);
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
//点云裁剪
|
|
|
|
|
|
std::vector< std::vector<SVzNL3DPosition>> roiScanLines;
|
|
|
|
|
|
_getRoiClouds(scanLines, 700, 1800, 400, 1700, roiScanLines);
|
|
|
|
|
|
sprintf_s(_scan_file, "%sLaserLine4_grid.txt", dataPath[grp]);
|
|
|
|
|
|
int headNullLines = 0;
|
|
|
|
|
|
_outputScanDataFile_vector(_scan_file, roiScanLines, false, &headNullLines);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
sprintf_s(_scan_file, "%sLaserLine%d_grid.txt", dataPath[grp], fidx);
|
|
|
|
|
|
int headNullLines = 0;
|
|
|
|
|
|
_outputScanDataFile_vector(_scan_file, scanLines, false, &headNullLines);
|
|
|
|
|
|
printf("%s: head null lines = %d\n", _scan_file, headNullLines);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
WD_QRcodeParam qrcode_param;
|
|
|
|
|
|
qrcode_param.rows = 14;
|
|
|
|
|
|
qrcode_param.cols = 14;
|
|
|
|
|
|
qrcode_param.row_space = 30.0 / 14;
|
|
|
|
|
|
qrcode_param.col_space = 30.0 / 14;
|
|
|
|
|
|
qrcode_param.pointHoleDepth = 1.0;
|
|
|
|
|
|
qrcode_param.pointHoleR = 0.6;
|
|
|
|
|
|
|
|
|
|
|
|
long t1 = GetTickCount64();//统计时间
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0, i_max= scanLines.size(); i < i_max; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (i == 14)
|
|
|
|
|
|
int kkk = 1;
|
|
|
|
|
|
//行处理
|
|
|
|
|
|
//调平,去除地面
|
|
|
|
|
|
wd_lineDataR(scanLines[i], poseCalibPara.planeCalib, -1);
|
|
|
|
|
|
}
|
|
|
|
|
|
//
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
sprintf_s(_scan_file, "%sresult\\LaserLine%d_calib_data.txt", dataPath[grp], fidx);
|
|
|
|
|
|
int headNulls = 0;
|
|
|
|
|
|
_outputScanDataFile_vector(_scan_file, scanLines, true, &headNulls);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
cv::Mat dmCodeImg;
|
|
|
|
|
|
std::vector< SVzNL3DPosition> objPoints;
|
|
|
|
|
|
wd_QRcode3Ddetection(
|
|
|
|
|
|
scanLines,
|
|
|
|
|
|
qrcode_param,
|
|
|
|
|
|
objPoints,
|
|
|
|
|
|
dmCodeImg);
|
|
|
|
|
|
|
|
|
|
|
|
long t2 = GetTickCount64();
|
|
|
|
|
|
printf("%s: %d(ms)!\n", _scan_file, (int)(t2 - t1));
|
|
|
|
|
|
//输出测试结果
|
|
|
|
|
|
sprintf_s(_scan_file, "%sresult\\LaserLine%d_result.txt", dataPath[grp], fidx);
|
|
|
|
|
|
_outputRGBDScanDataFile_RGBD(_scan_file, scanLines, objPoints);
|
|
|
|
|
|
if (!dmCodeImg.empty())
|
|
|
|
|
|
{
|
|
|
|
|
|
sprintf_s(_scan_file, "%sresult\\LaserLine%d_img.png", dataPath[grp], fidx);
|
|
|
|
|
|
cv::Mat normDmCodeImg;
|
|
|
|
|
|
cv::normalize(dmCodeImg, normDmCodeImg, 0, 255, cv::NORM_MINMAX, CV_8U);
|
|
|
|
|
|
cv::imwrite(_scan_file, normDmCodeImg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
|
|
|
|
|
|
// 调试程序: F5 或调试 >“开始调试”菜单
|
|
|
|
|
|
|
|
|
|
|
|
// 入门使用技巧:
|
|
|
|
|
|
// 1. 使用解决方案资源管理器窗口添加/管理文件
|
|
|
|
|
|
// 2. 使用团队资源管理器窗口连接到源代码管理
|
|
|
|
|
|
// 3. 使用输出窗口查看生成输出和其他消息
|
|
|
|
|
|
// 4. 使用错误列表窗口查看错误
|
|
|
|
|
|
// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
|
|
|
|
|
|
// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
|