test_orb.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // Intel License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000, Intel Corporation, all rights reserved.
  14. // Third party copyrights are property of their respective owners.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistribution's of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. //
  22. // * Redistribution's in binary form must reproduce the above copyright notice,
  23. // this list of conditions and the following disclaimer in the documentation
  24. // and/or other materials provided with the distribution.
  25. //
  26. // * The name of Intel Corporation may not be used to endorse or promote products
  27. // derived from this software without specific prior written permission.
  28. //
  29. // This software is provided by the copyright holders and contributors "as is" and
  30. // any express or implied warranties, including, but not limited to, the implied
  31. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  32. // In no event shall the Intel Corporation or contributors be liable for any direct,
  33. // indirect, incidental, special, exemplary, or consequential damages
  34. // (including, but not limited to, procurement of substitute goods or services;
  35. // loss of use, data, or profits; or business interruption) however caused
  36. // and on any theory of liability, whether in contract, strict liability,
  37. // or tort (including negligence or otherwise) arising in any way out of
  38. // the use of this software, even if advised of the possibility of such damage.
  39. //
  40. //M*/
  41. #include "test_precomp.hpp"
  42. namespace opencv_test { namespace {
  43. TEST(Features2D_ORB, _1996)
  44. {
  45. Ptr<FeatureDetector> fd = ORB::create(10000, 1.2f, 8, 31, 0, 2, ORB::HARRIS_SCORE, 31, 20);
  46. Ptr<DescriptorExtractor> de = fd;
  47. Mat image = imread(string(cvtest::TS::ptr()->get_data_path()) + "shared/lena.png");
  48. ASSERT_FALSE(image.empty());
  49. Mat roi(image.size(), CV_8UC1, Scalar(0));
  50. Point poly[] = {Point(100, 20), Point(300, 50), Point(400, 200), Point(10, 500)};
  51. fillConvexPoly(roi, poly, int(sizeof(poly) / sizeof(poly[0])), Scalar(255));
  52. std::vector<KeyPoint> keypoints;
  53. fd->detect(image, keypoints, roi);
  54. Mat descriptors;
  55. de->compute(image, keypoints, descriptors);
  56. //image.setTo(Scalar(255,255,255), roi);
  57. int roiViolations = 0;
  58. for(std::vector<KeyPoint>::const_iterator kp = keypoints.begin(); kp != keypoints.end(); ++kp)
  59. {
  60. int x = cvRound(kp->pt.x);
  61. int y = cvRound(kp->pt.y);
  62. ASSERT_LE(0, x);
  63. ASSERT_LE(0, y);
  64. ASSERT_GT(image.cols, x);
  65. ASSERT_GT(image.rows, y);
  66. // if (!roi.at<uchar>(y,x))
  67. // {
  68. // roiViolations++;
  69. // circle(image, kp->pt, 3, Scalar(0,0,255));
  70. // }
  71. }
  72. // if(roiViolations)
  73. // {
  74. // imshow("img", image);
  75. // waitKey();
  76. // }
  77. ASSERT_EQ(0, roiViolations);
  78. }
  79. TEST(Features2D_ORB, crash_5031)
  80. {
  81. cv::Mat image = cv::Mat::zeros(cv::Size(1920, 1080), CV_8UC3);
  82. int nfeatures = 8000;
  83. float orbScaleFactor = 1.2f;
  84. int nlevels = 18;
  85. int edgeThreshold = 4;
  86. int firstLevel = 0;
  87. int WTA_K = 2;
  88. ORB::ScoreType scoreType = cv::ORB::HARRIS_SCORE;
  89. int patchSize = 47;
  90. int fastThreshold = 20;
  91. Ptr<ORB> orb = cv::ORB::create(nfeatures, orbScaleFactor, nlevels, edgeThreshold, firstLevel, WTA_K, scoreType, patchSize, fastThreshold);
  92. std::vector<cv::KeyPoint> keypoints;
  93. cv::Mat descriptors;
  94. cv::KeyPoint kp;
  95. kp.pt.x = 443;
  96. kp.pt.y = 5;
  97. kp.size = 47;
  98. kp.angle = 53.4580612f;
  99. kp.response = 0.0000470733867f;
  100. kp.octave = 0;
  101. kp.class_id = -1;
  102. keypoints.push_back(kp);
  103. ASSERT_NO_THROW(orb->compute(image, keypoints, descriptors));
  104. }
  105. TEST(Features2D_ORB, regression_16197)
  106. {
  107. Mat img(Size(72, 72), CV_8UC1, Scalar::all(0));
  108. Ptr<ORB> orbPtr = ORB::create();
  109. orbPtr->setNLevels(5);
  110. orbPtr->setFirstLevel(3);
  111. orbPtr->setScaleFactor(1.8);
  112. orbPtr->setPatchSize(8);
  113. orbPtr->setEdgeThreshold(8);
  114. std::vector<KeyPoint> kps;
  115. Mat fv;
  116. // exception in debug mode, crash in release
  117. ASSERT_NO_THROW(orbPtr->detectAndCompute(img, noArray(), kps, fv));
  118. }
  119. // https://github.com/opencv/opencv-python/issues/537
  120. BIGDATA_TEST(Features2D_ORB, regression_opencv_python_537) // memory usage: ~3 Gb
  121. {
  122. applyTestTag(
  123. CV_TEST_TAG_LONG,
  124. CV_TEST_TAG_DEBUG_VERYLONG,
  125. CV_TEST_TAG_MEMORY_6GB
  126. );
  127. const int width = 25000;
  128. const int height = 25000;
  129. Mat img(Size(width, height), CV_8UC1, Scalar::all(0));
  130. const int border = 23, num_lines = 23;
  131. for (int i = 0; i < num_lines; i++)
  132. {
  133. cv::Point2i point1(border + i * 100, border + i * 100);
  134. cv::Point2i point2(width - border - i * 100, height - border * i * 100);
  135. cv::line(img, point1, point2, 255, 1, LINE_AA);
  136. }
  137. Ptr<ORB> orbPtr = ORB::create(31);
  138. std::vector<KeyPoint> kps;
  139. Mat fv;
  140. ASSERT_NO_THROW(orbPtr->detectAndCompute(img, noArray(), kps, fv));
  141. }
  142. }} // namespace