我正在尝试将 opencv 的调用groupRectangles()从 python转换为 c++,并且注意到 python 绑定的输出与 c++ 调用的输出不匹配。
我已经编辑了下面的输出以反映在 ubuntu 18.04 上使用 opencv 3.2 重现这个
库版本
我在 Ubuntu 18.04 上运行 opencv。
C++ 程序链接到 opencv 3.2.0(据 ldd 报告)。
python 模块报告版本 3.2.0
C++代码
我编写了以下程序来获取一组 (x1, y1, x2, y2) 输入并将它们传递给groupRectangles()组阈值为 3 和 epsilon 为 0.02 的值。为了便于比较,输出以python的列表格式打印。
#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
// display in python format
std::ostream& operator<<(std::ostream& out, std::vector<cv::Rect>& rectangles)
{
out << '[';
for (auto i = 0u; i<rectangles.size(); ++i)
{
if (i)
out << ',';
out << '[' << rectangles[i].tl().x << ',' << rectangles[i].tl().y << ',' << rectangles[i].br().x << ',' << rectangles[i].br().y << ']';
}
return out << ']';
}
// inputs are x1,y1,x2,y2
int main()
{
std::vector<cv::Rect> candidates;
std::transform(std::begin(inputs), std::end(inputs), std::back_inserter(candidates),
[](const float coord[4]) {
return cv::Rect(cv::Point((int)coord[0], (int)coord[1]), cv::Point((int)coord[2], (int)coord[3]));
});
std::cout << "input:\n" << candidates << '\n';
std::vector<int> weights(candidates.size());
cv::groupRectangles(candidates, weights, 3, 0.02);
std::cout << "output:\n" << candidates << '\n';
return EXIT_SUCCESS;
}
这是我转换为cv::Rect,非确定性groupRectangles()或其他方面的问题吗?
相关分类