update:WorkpieceRotor 更新算法解决漏检;更新定子模型

This commit is contained in:
YangSn 2026-10-30 17:23:45 +08:00
parent d4210719e0
commit bf29dbd825
14 changed files with 224 additions and 51 deletions

View File

@ -4,7 +4,7 @@
// 版本字符串 // 版本字符串
#define STATORWORKPIECEPOSITION_APP_NAME "转子钢芯定位" #define STATORWORKPIECEPOSITION_APP_NAME "转子钢芯定位"
#define STATORWORKPIECEPOSITION_APP_KEY "WorkpieceRotorApp" #define STATORWORKPIECEPOSITION_APP_KEY "WorkpieceRotorApp"
#define STATORWORKPIECEPOSITION_VERSION_STRING "2.1.2" #define STATORWORKPIECEPOSITION_VERSION_STRING "2.1.3"
#define STATORWORKPIECEPOSITION_BUILD_STRING "1" #define STATORWORKPIECEPOSITION_BUILD_STRING "1"
#define STATORWORKPIECEPOSITION_FULL_VERSION_STRING "V" STATORWORKPIECEPOSITION_VERSION_STRING "_" STATORWORKPIECEPOSITION_BUILD_STRING #define STATORWORKPIECEPOSITION_FULL_VERSION_STRING "V" STATORWORKPIECEPOSITION_VERSION_STRING "_" STATORWORKPIECEPOSITION_BUILD_STRING

View File

@ -1,3 +1,8 @@
# 2.1.3
## build_1 20261030
1. 更新算法解决漏检
2. 更新定子模型
# 2.1.2 # 2.1.2
## build_1 20261030 ## build_1 20261030
1. 更新转子模型 1. 更新转子模型

View File

@ -1,10 +1,13 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <algorithm>
#include <cstdio>
#include <filesystem>
#include <string>
#include <vector> #include <vector>
#include <stdio.h> #include <stdio.h>
#include <VZNL_Types.h> #include <VZNL_Types.h>
#include "direct.h" #include "direct.h"
#include <string>
#include "hybridPosePositioning_Export.h" #include "hybridPosePositioning_Export.h"
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include <Windows.h> #include <Windows.h>
@ -776,14 +779,20 @@ void _outputRGBDResult_XYZ_RGBD_workpieceInfo(
objNumber = 1; objNumber = 1;
int lineNum = (int)scanLines.size(); int lineNum = (int)scanLines.size();
std::ofstream sw(fileName); std::ofstream sw(fileName, std::ios::out | std::ios::trunc);
int realLines = (objNumber == 0) ? lineNum : (lineNum + 1); int realLines = (objNumber == 0) ? lineNum : (lineNum + 1);
sw << "LineNum:" << realLines << std::endl; sw << "LineNum:" << realLines << '\n';
sw << "DataType: 0" << std::endl; sw << "DataType: 0" << '\n';
sw << "ScanSpeed: 0" << std::endl; sw << "ScanSpeed: 0" << '\n';
sw << "PointAdjust: 1" << std::endl; sw << "PointAdjust: 1" << '\n';
sw << "MaxTimeStamp: 0_0" << std::endl; sw << "MaxTimeStamp: 0_0" << '\n';
if (!sw) {
std::cerr << "Write failed: line = MaxTimeStamp"
<< ", rdstate = " << sw.rdstate()
<< ", bad = " << sw.bad()
<< ", fail = " << sw.fail()
<< '\n';
}
int maxLineIndex = 0; int maxLineIndex = 0;
int max_stamp = 0; int max_stamp = 0;
SG_color rgb = { 0, 0, 0 }; SG_color rgb = { 0, 0, 0 };
@ -855,9 +864,46 @@ void _outputRGBDResult_XYZ_RGBD_workpieceInfo(
float x = (float)pt3D->pt3D.x; float x = (float)pt3D->pt3D.x;
float y = (float)pt3D->pt3D.y; float y = (float)pt3D->pt3D.y;
float z = (float)pt3D->pt3D.z; float z = (float)pt3D->pt3D.z;
errno = 0;
// RGB 显式转为整数,避免 unsigned char 被按字符输出。
sw << "{" << x << "," << y << "," << z << "}-"; sw << "{" << x << "," << y << "," << z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << rgb.r << "," << rgb.g << "," << rgb.b << "," << size << " }" << std::endl; sw << "{"
<< static_cast<int>(rgb.r) << ","
<< static_cast<int>(rgb.g) << ","
<< static_cast<int>(rgb.b) << ","
<< size << " }" << '\n';
// 临时诊断:每个点写完都刷新,检查实际写出是否成功。
// 定位完成后移除,避免影响保存速度。
const char* stage = "write";
if (sw) {
stage = "flush";
sw.flush();
}
// 在其他日志操作之前保存 errno。
const int savedErrno = errno;
if (!sw) {
std::cerr
<< "Write failed: stage = " << stage
<< ", line = " << line
<< ", i = " << i
<< ", lineIdx = " << lineIdx
<< ", rdstate = " << sw.rdstate()
<< ", bad = " << sw.bad()
<< ", fail = " << sw.fail()
<< ", errno = " << savedErrno
<< ", error = "
<< (savedErrno ? std::strerror(savedErrno)
: "No errno information")
<< '\n';
// 停止整个保存过程,不能只退出内层循环。
throw std::runtime_error("Point-cloud file write failed");
}
} }
} }
@ -896,13 +942,13 @@ void _outputRGBDResult_XYZ_RGBD_workpieceInfo(
poseInfo[m].center.y - poseInfo[m].z_dir.y * dirLen, poseInfo[m].center.y - poseInfo[m].z_dir.y * dirLen,
poseInfo[m].center.z - poseInfo[m].z_dir.z * dirLen }; poseInfo[m].center.z - poseInfo[m].z_dir.z * dirLen };
sw << "Poly_" << lineIdx << "_2" << std::endl; sw << "Poly_" << lineIdx << "_2" << '\n';
sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-"; sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-"; sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
lineIdx++; lineIdx++;
} }
else else
@ -914,39 +960,39 @@ void _outputRGBDResult_XYZ_RGBD_workpieceInfo(
poseInfo[m].center.y - poseInfo[m].z_dir.y * dirLen, poseInfo[m].center.y - poseInfo[m].z_dir.y * dirLen,
poseInfo[m].center.z - poseInfo[m].z_dir.z * dirLen }; poseInfo[m].center.z - poseInfo[m].z_dir.z * dirLen };
sw << "Poly_" << lineIdx << "_2" << std::endl; sw << "Poly_" << lineIdx << "_2" << '\n';
sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-"; sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-"; sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
lineIdx++; lineIdx++;
double sapcerDirLen = 200; double sapcerDirLen = 200;
dirPt1 = { poseInfo[m].center.x + poseInfo[m].x_dir.x * sapcerDirLen, dirPt1 = { poseInfo[m].center.x + poseInfo[m].x_dir.x * sapcerDirLen,
poseInfo[m].center.y + poseInfo[m].x_dir.y * sapcerDirLen, poseInfo[m].center.y + poseInfo[m].x_dir.y * sapcerDirLen,
poseInfo[m].center.z + poseInfo[m].x_dir.z * sapcerDirLen }; poseInfo[m].center.z + poseInfo[m].x_dir.z * sapcerDirLen };
sw << "Poly_" << lineIdx << "_2" << std::endl; sw << "Poly_" << lineIdx << "_2" << '\n';
sw << "{" << poseInfo[m].center.x << "," << poseInfo[m].center.y << "," << poseInfo[m].center.z << "}-"; sw << "{" << poseInfo[m].center.x << "," << poseInfo[m].center.y << "," << poseInfo[m].center.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-"; sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
lineIdx++; lineIdx++;
dirPt2 = { poseInfo[m].center.x + poseInfo[m].y_dir.x * sapcerDirLen, dirPt2 = { poseInfo[m].center.x + poseInfo[m].y_dir.x * sapcerDirLen,
poseInfo[m].center.y + poseInfo[m].y_dir.y * sapcerDirLen, poseInfo[m].center.y + poseInfo[m].y_dir.y * sapcerDirLen,
poseInfo[m].center.z + poseInfo[m].y_dir.z * sapcerDirLen }; poseInfo[m].center.z + poseInfo[m].y_dir.z * sapcerDirLen };
sw << "Poly_" << lineIdx << "_2" << std::endl; sw << "Poly_" << lineIdx << "_2" << '\n';
sw << "{" << poseInfo[m].center.x << "," << poseInfo[m].center.y << "," << poseInfo[m].center.z << "}-"; sw << "{" << poseInfo[m].center.x << "," << poseInfo[m].center.y << "," << poseInfo[m].center.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-"; sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
lineIdx++; lineIdx++;
} }
} }
@ -957,51 +1003,56 @@ void _outputRGBDResult_XYZ_RGBD_workpieceInfo(
//输出外接矩形 //输出外接矩形
SVzNL3DPoint dirPt1 = binInfo->minRectVertex[0]; SVzNL3DPoint dirPt1 = binInfo->minRectVertex[0];
SVzNL3DPoint dirPt2 = binInfo->minRectVertex[1]; SVzNL3DPoint dirPt2 = binInfo->minRectVertex[1];
sw << "Poly_" << lineIdx << "_2" << std::endl; sw << "Poly_" << lineIdx << "_2" << '\n';
sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-"; sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-"; sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
lineIdx++; lineIdx++;
dirPt1 = binInfo->minRectVertex[1]; dirPt1 = binInfo->minRectVertex[1];
dirPt2 = binInfo->minRectVertex[2]; dirPt2 = binInfo->minRectVertex[2];
sw << "Poly_" << lineIdx << "_2" << std::endl; sw << "Poly_" << lineIdx << "_2" << '\n';
sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-"; sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-"; sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
lineIdx++; lineIdx++;
dirPt1 = binInfo->minRectVertex[2]; dirPt1 = binInfo->minRectVertex[2];
dirPt2 = binInfo->minRectVertex[3]; dirPt2 = binInfo->minRectVertex[3];
sw << "Poly_" << lineIdx << "_2" << std::endl; sw << "Poly_" << lineIdx << "_2" << '\n';
sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-"; sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-"; sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
lineIdx++; lineIdx++;
dirPt1 = binInfo->minRectVertex[3]; dirPt1 = binInfo->minRectVertex[3];
dirPt2 = binInfo->minRectVertex[0]; dirPt2 = binInfo->minRectVertex[0];
sw << "Poly_" << lineIdx << "_2" << std::endl; sw << "Poly_" << lineIdx << "_2" << '\n';
sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-"; sw << "{" << dirPt1.x << "," << dirPt1.y << "," << dirPt1.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-"; sw << "{" << dirPt2.x << "," << dirPt2.y << "," << dirPt2.z << "}-";
sw << "{0,0}-{0,0}-"; sw << "{0,0}-{0,0}-";
sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << std::endl; sw << "{" << (int)rgb.r << "," << (int)rgb.g << "," << (int)rgb.b << "," << size << "}" << '\n';
lineIdx++; lineIdx++;
} }
} }
sw.close(); sw.close();
if (sw.fail()) {
std::cerr << "Failed to close output file: "
<< fileName << std::endl;
}
} }
void _outputRGBDResult_XYZ_RGBD_planningResult( void _outputRGBDResult_XYZ_RGBD_planningResult(
@ -2466,8 +2517,50 @@ void HaiRuiMa_groundCalib_test(void)
} }
// directory:由 const char* 给出的测试目录
namespace fs = std::filesystem;
bool ends_with(const std::string& str, const std::string& suffix)
{
return str.size() >= suffix.size() &&
str.compare(str.size() - suffix.size(),
suffix.size(), suffix) == 0;
}
void test_directory(const char* directory, std::vector<fs::path>& files)
{
if (directory == nullptr)
return;
try {
// 先收集文件,避免测试过程中生成结果文件影响目录遍历
for (const auto& entry : fs::directory_iterator(directory)) {
if (!entry.is_regular_file())
continue;
const fs::path& path = entry.path();
const std::string filename = path.filename().string();
if (path.extension() != ".txt")
continue;
if (ends_with(filename, "_result.txt"))
continue;
if (ends_with(filename, "_info.txt"))
continue;
files.push_back(path);
}
}
catch (const fs::filesystem_error& e) {
std::cerr << "Directory error: " << e.what() << '\n';
return;
}
// 固定测试顺序,不需要排序时可删除
std::sort(files.begin(), files.end());
}
//拓普发工件孔定位(工件定位) //拓普发工件孔定位(工件定位)
#define HRM_RotorCore_TEST_GROUP 9 #define HRM_RotorCore_TEST_GROUP 19
void HaiRuiMa_rotorCorePositioning_test(void) void HaiRuiMa_rotorCorePositioning_test(void)
{ {
const char* dataPath[HRM_RotorCore_TEST_GROUP] = { const char* dataPath[HRM_RotorCore_TEST_GROUP] = {
@ -2475,22 +2568,35 @@ void HaiRuiMa_rotorCorePositioning_test(void)
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/数据2D3D/", //0 "F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/数据2D3D/", //0
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/WorkpieceRotor/", //1 "F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/WorkpieceRotor/", //1
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/现场数据/", //2 "F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/现场数据/", //2
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/2026-09-海瑞马/09-14/", //3 "F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/定子数据/09-14/", //3
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/2026-09-海瑞马/09-14中/", //4 "F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/定子数据/09-14中/", //4
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/2026-09-海瑞马/异常数据/", //5 "F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/定子数据/异常数据_1/", //5
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/2026-09-海瑞马/10-09小/", //6 "F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/定子数据/10-09小/", //6
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/更换5mm镜头相机/", //7 "F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/定子数据/更换5mm镜头相机/", //7
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子钢芯/1019定子数据/", //8 "F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/转子数据/10.21数据/1-24中型/", //8
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/转子数据/10.21数据/25-63小型/", //9
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/转子数据/10.21数据/64-87大型/", //10
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/定子数据/20261023数据/", //11
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/定子数据/20261024数据/", //12
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/定子数据/异常数据/", //13
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/转子数据/2楼转子异常数据/", //14
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/定子数据/20261028数据/", //15
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/定子数据/20261029数据/", //16
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/转子数据/20261028数据/", //17
"F:/ShangGu/项目/冠钦项目/宁波海瑞马/转子定子抓取/转子数据/20261029数据/", //18
}; };
SVzNLRange fileIdx[HRM_RotorCore_TEST_GROUP] = { SVzNLRange fileIdx[HRM_RotorCore_TEST_GROUP] = {
{1,10}, {3,70},{9,9}, {1,54}, {1,54}, {1,6}, {1,8}, {1, 16},{4,78}, {1,10}, {3,70},{9,9}, {1,54}, {1,54},
{7,9}, {1,8}, {1, 16},{1,24}, {25,63},
{64,87},{1,80}, {1,178}, {1, 39}, {1,38},
{-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}
}; };
const char* ver = wd_hybridPositioningVersion(); const char* ver = wd_hybridPositioningVersion();
printf("ver:%s\n", ver); printf("ver:%s\n", ver);
for (int grp = 4; grp <= 8; grp++) for (int grp = 16; grp <= 18; grp++)
{ {
SSG_planeCalibPara groundCalibPara; SSG_planeCalibPara groundCalibPara;
//初始化成单位阵 //初始化成单位阵
@ -2510,11 +2616,33 @@ void HaiRuiMa_rotorCorePositioning_test(void)
sprintf_s(calibFile, "%sground_calib_para.txt", dataPath[grp]); sprintf_s(calibFile, "%sground_calib_para.txt", dataPath[grp]);
groundCalibPara = _readCalibPara(calibFile); groundCalibPara = _readCalibPara(calibFile);
for (int fidx = fileIdx[grp].nMin; fidx <= fileIdx[grp].nMax; fidx++) int fstart = fileIdx[grp].nMin;
int fend = fileIdx[grp].nMax;
std::vector<fs::path> files;
if (fstart < 0)
{
test_directory(dataPath[grp], files);
if (files.size() == 0)
continue;
fstart = 0;
fend = (int)files.size() - 1;
}
for (int fidx = 98; fidx <= fend; fidx++)
{ {
//fidx = 50; //fidx = 50;
char _scan_file[256]; char _scan_file[256];
sprintf_s(_scan_file, "%s%d_cloud.txt", dataPath[grp], fidx); if (fileIdx[grp].nMin >= 0)
{
if ((grp >= 12) && (grp <= 14))
sprintf_s(_scan_file, "%s%d.txt", dataPath[grp], fidx);
else
sprintf_s(_scan_file, "%s%d_cloud.txt", dataPath[grp], fidx);
}
else
{
sprintf_s(_scan_file, "%s", files[fidx].string().c_str());
}
std::vector<std::vector< SVzNLPositionD>> scanLines; std::vector<std::vector< SVzNLPositionD>> scanLines;
vzReadLaserScanPointFromFile_XYZUV_vector(_scan_file, scanLines); vzReadLaserScanPointFromFile_XYZUV_vector(_scan_file, scanLines);
_removeZeroLines_XYZUV(scanLines); _removeZeroLines_XYZUV(scanLines);
@ -2522,7 +2650,7 @@ void HaiRuiMa_rotorCorePositioning_test(void)
continue; continue;
#if 0 #if 0
SVzNLRangeD yRange = { -400, 300 }; SVzNLRangeD yRange = { -400, 400 };
_yRangeFilter_XYZUV(scanLines, yRange); _yRangeFilter_XYZUV(scanLines, yRange);
int headNullLines = 0; int headNullLines = 0;
sprintf_s(_scan_file, "%s%d_cloud.txt", dataPath[grp], fidx); sprintf_s(_scan_file, "%s%d_cloud.txt", dataPath[grp], fidx);
@ -2566,7 +2694,23 @@ void HaiRuiMa_rotorCorePositioning_test(void)
std::vector<WD_objArea2D> objROIs; std::vector<WD_objArea2D> objROIs;
vzReadObj2DROI(_scan_file, objROIs); vzReadObj2DROI(_scan_file, objROIs);
#else //使用掩膜 #else //使用掩膜
sprintf_s(_scan_file, "%s%d_mask.bmp", dataPath[grp], fidx); if (fileIdx[grp].nMin >= 0)
{
if (grp == 11) //20261023数据
sprintf_s(_scan_file, "%s%d_reinspection_2d_mask.bmp", dataPath[grp], fidx);
else if ((grp == 12) || (grp == 14)) ////20261024数据
sprintf_s(_scan_file, "%s%d_input_reinspection_2d_mask.bmp", dataPath[grp], fidx);
else if (grp == 13)
sprintf_s(_scan_file, "%s%d_reinspection_2d_mask.bmp", dataPath[grp], fidx);
else
sprintf_s(_scan_file, "%s%d_mask.bmp", dataPath[grp], fidx);
}
else
{
const std::string file_prefix = files[fidx].stem().string();
const fs::path maskFile_path = files[fidx].parent_path() / (file_prefix + "_2d_mask.bmp");
sprintf_s(_scan_file, "%s", maskFile_path.string().c_str());
}
// //
// 读取 BMP 文件(彩色,默认) // 读取 BMP 文件(彩色,默认)
cv::Mat img = cv::imread(_scan_file, cv::IMREAD_COLOR); cv::Mat img = cv::imread(_scan_file, cv::IMREAD_COLOR);
@ -2623,6 +2767,11 @@ void HaiRuiMa_rotorCorePositioning_test(void)
workpieceParam.height = 20.0; workpieceParam.height = 20.0;
} }
#endif #endif
EWD_WorkpieceClass workpieceClass = keWD_Class_Stator;
if ((grp >= 8) && (grp <= 10))
workpieceClass = keWD_Class_Rotor;
else if( (grp == 14) || (grp == 17) || (grp == 18))
workpieceClass = keWD_Class_Rotor;
SVzNLSizeD spacerParam; //隔板参数:长和宽 SVzNLSizeD spacerParam; //隔板参数:长和宽
spacerParam.dWidth = 720.0; spacerParam.dWidth = 720.0;
@ -2641,7 +2790,7 @@ void HaiRuiMa_rotorCorePositioning_test(void)
wd_HRM_RotorCorePositioning( wd_HRM_RotorCorePositioning(
scanLines, scanLines,
objDataMask, objDataMask,
keWD_Class_Rotor, workpieceClass,
groundCalibPara, groundCalibPara,
spacerParam, spacerParam,
workpieceParam, workpieceParam,
@ -2672,7 +2821,14 @@ void HaiRuiMa_rotorCorePositioning_test(void)
printf("%s: %d(ms), errCode=%d 结果: %d...", _scan_file, (int)(t2 - t1), errCode, num); printf("%s: %d(ms), errCode=%d 结果: %d...", _scan_file, (int)(t2 - t1), errCode, num);
} }
//输出测试结果 //输出测试结果
sprintf_s(calibFile, "%sresult/LaserLine%d_workpiece_info.txt", dataPath[grp], fidx); if (fileIdx[grp].nMin >= 0)
sprintf_s(calibFile, "%sresult/LaserLine%d_workpiece_info.txt", dataPath[grp], fidx);
else
{
const std::string file_prefix = files[fidx].stem().string();
const fs::path rsltFile_path = files[fidx].parent_path() / ("result/" + file_prefix + "_workpiece_info.txt");
sprintf_s(calibFile, "%s", rsltFile_path.string().c_str());
}
_outputWorkpieceInfo(calibFile, workpiecePositions); _outputWorkpieceInfo(calibFile, workpiecePositions);
//旋转到调平坐标系 //旋转到调平坐标系
int workpieceNum = (int)workpiecePositions.size(); int workpieceNum = (int)workpiecePositions.size();
@ -2688,10 +2844,22 @@ void HaiRuiMa_rotorCorePositioning_test(void)
rpt = wd_ptRotate(workpiecePositions[i].x_dir, groundCalibPara.planeCalib); rpt = wd_ptRotate(workpiecePositions[i].x_dir, groundCalibPara.planeCalib);
workpiecePositions[i].x_dir = rpt; workpiecePositions[i].x_dir = rpt;
} }
sprintf_s(_scan_file, "%sresult/result_%d.txt", dataPath[grp], fidx); if (fileIdx[grp].nMin >= 0)
{
sprintf_s(_scan_file, "%sresult/result_%d.txt", dataPath[grp], fidx);
sprintf_s(calibFile, "%sresult/result_%d_projection.png", dataPath[grp], fidx);
}
else
{
const std::string file_prefix = files[fidx].stem().string();
const fs::path rsltFile_path_1 = files[fidx].parent_path() / ("result/" + file_prefix + "_result.txt");
sprintf_s(_scan_file, "%s", rsltFile_path_1.string().c_str());
const fs::path rsltFile_path_2 = files[fidx].parent_path() / ("result/" + file_prefix + "_projection.png");
sprintf_s(calibFile, "%s", rsltFile_path_2.string().c_str());
}
_outputRGBDResult_XYZ_RGBD_workpieceInfo(_scan_file, debugScanLines, workpiecePositions, &binInfo, 50); _outputRGBDResult_XYZ_RGBD_workpieceInfo(_scan_file, debugScanLines, workpiecePositions, &binInfo, 50);
#if 1 #if 1
sprintf_s(calibFile, "%sresult/result_%d_projection.png", dataPath[grp], fidx);
double rpy[3] = { 0, 0, 0 }; //{ 0,-45, 0 }; // double rpy[3] = { 0, 0, 0 }; //{ 0,-45, 0 }; //
double angleDrawLen = 15; double angleDrawLen = 15;
double displayScale = 0.3; double displayScale = 0.3;