test_blobdetector.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "test_precomp.hpp"
  5. namespace opencv_test { namespace {
  6. TEST(Features2d_BlobDetector, bug_6667)
  7. {
  8. cv::Mat image = cv::Mat(cv::Size(100, 100), CV_8UC1, cv::Scalar(255, 255, 255));
  9. cv::circle(image, Point(50, 50), 20, cv::Scalar(0), -1);
  10. SimpleBlobDetector::Params params;
  11. params.minThreshold = 250;
  12. params.maxThreshold = 260;
  13. params.minRepeatability = 1; // https://github.com/opencv/opencv/issues/6667
  14. std::vector<KeyPoint> keypoints;
  15. Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
  16. detector->detect(image, keypoints);
  17. ASSERT_NE((int) keypoints.size(), 0);
  18. }
  19. TEST(Features2d_BlobDetector, withContours)
  20. {
  21. cv::Mat image = cv::Mat(cv::Size(100, 100), CV_8UC1, cv::Scalar(255, 255, 255));
  22. cv::circle(image, Point(50, 50), 20, cv::Scalar(0), -1);
  23. SimpleBlobDetector::Params params;
  24. params.minThreshold = 250;
  25. params.maxThreshold = 260;
  26. params.minRepeatability = 1; // https://github.com/opencv/opencv/issues/6667
  27. params.collectContours = true;
  28. std::vector<KeyPoint> keypoints;
  29. Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
  30. detector->detect(image, keypoints);
  31. ASSERT_NE((int)keypoints.size(), 0);
  32. ASSERT_GT((int)detector->getBlobContours().size(), 0);
  33. std::vector<Point> contour = detector->getBlobContours()[0];
  34. ASSERT_TRUE(std::any_of(contour.begin(), contour.end(),
  35. [](Point p)
  36. {
  37. return abs(p.x - 30) < 2 && abs(p.y - 50) < 2;
  38. }));
  39. }
  40. }} // namespace