OpenCvSharp4.6 编写的 C# 代码版本 // 求取极值点 void Caliper::FindExtremePoint() { // 1. 检查搜索路径像素数据是否为空 if(pathPixelValueAfterFilter.empty()) return; // 2. 遍历滤波后的数据,查找极值点 extremePoints.clear(); switch (polarity) { // 不考虑极性 case 0 : for(size_t i = 1; i < pathPixelValueAfterFilter.size() - 1; ++i) { // 两边异号为极值点 if (size_t(std::abs(pathPixelValueAfterFilter.at(i))) >= contrastThreshold && (0 > (pathPixelValueAfterFilter.at(i) - pathPixelValueAfterFilter.at(i - 1)) * (pathPixelValueAfterFilter.at(i + 1) - pathPixelValueAfterFilter.at(i))) ) { extremePoints.push_back(ExtremPointInfo(path.at(i), static_cast<int>(i), static_cast<int>(pathPixelValueAfterFilter.at(i)))); } } break; // 黑到白 case 1 : for(size_t i = 1; i < pathPixelValueAfterFilter.size() - 1; ++i) { // 两边异号为极值点 if (pathPixelValueAfterFilter.at(i) > 0 && size_t(std::abs(pathPixelValueAfterFilter.at(i))) >= contrastThreshold && (0 > (pathPixelValueAfterFilter.at(i) - pathPixelValueAfterFilter.at(i - 1)) * (pathPixelValueAfterFilter.at(i + 1) - pathPixelValueAfterFilter.at(i))) ) { extremePoints.push_back(ExtremPointInfo(path.at(i), static_cast<int>(i), static_cast<int>(pathPixelValueAfterFilter.at(i)))); } } break; // 白到黑 case -1: for(size_t i = 1; i < pathPixelValueAfterFilter.size() - 1; ++i) { // 两边异号为极值点 if (pathPixelValueAfterFilter.at(i) < 0 && size_t(std::abs(pathPixelValueAfterFilter.at(i))) >= contrastThreshold && (0 > (pathPixelValueAfterFilter.at(i) - pathPixelValueAfterFilter.at(i - 1)) * (pathPixelValueAfterFilter.at(i + 1) - pathPixelValueAfterFilter.at(i))) ) { extremePoints.push_back(ExtremPointInfo(path.at(i), static_cast<int>(i), static_cast<int>(pathPixelValueAfterFilter.at(i)))); } } break; default: assert(false); break; }
时间: 2024-04-26 12:22:55 浏览: 137
这段代码是用于在图像中搜索极值点的,主要包括以下步骤:
1. 检查搜索路径像素数据是否为空;
2. 遍历滤波后的数据,查找极值点;
3. 根据极性类型分别处理不同的情况,包括不考虑极性、黑到白和白到黑;
4. 找到极值点后将其信息保存到 `extremePoints` 中。
其中,`pathPixelValueAfterFilter` 是经过滤波后的搜索路径像素数据,`contrastThreshold` 是对比度的阈值,`path` 是搜索路径的像素坐标,`polarity` 是极性类型。
阅读全文