我需要一些关于增强现实的帮助。我开发了一个小应用程序。现在我想使用形状检测算法或特别是圆形检测算法。我希望在我的相机打开后它应该只检测圆形,如果它得到圆形,它应该被一些相应的图像替换。我希望你明白我想做什么。
问问题
2396 次
1 回答
0
要为(圆形)添加形状检测算法,您可以考虑使用 OpenCV 中的 Hough 变换进行圆形检测。取自 OpenCV 教程网站,以下是一些片段:
// Loads an image
cv::Mat src = cv::imread( filename, cv::IMREAD_COLOR );
cv::Mat gray;
cv::cvtColor(src, gray, cv::COLOR_BGR2GRAY);
cv::medianBlur(gray, gray, 5);
cv::vector<Vec3f> circles;
cv::HoughCircles(gray, circles, cv::HOUGH_GRADIENT, 1,
gray.rows/16, // change this value to detect circles with different distances to each other
100, 30, 1, 30 // change the last two parameters
// (min_radius & max_radius) to detect larger circles
);
for( size_t i = 0; i < circles.size(); i++ )
{
cv::Vec3i c = circles[i];
cv::Point center = cv::Point(c[0], c[1]);
// circle center
cv::circle( src, center, 1, cv::Scalar(0,100,100), 3, cv::LINE_AA);
// circle outline
int radius = c[2];
cv::circle( src, center, radius, cv::Scalar(255,0,255), 3, cv::LINE_AA);
}
OpenCV 可以完成您提到的任务,并且与 AR 应用程序兼容。
于 2019-10-05T10:47:07.300 回答