{"action":"created","issue":{"url":"https://api.github.com/repos/Itseez/opencv/issues/6613","repository_url":"https://api.github.com/repos/Itseez/opencv","labels_url":"https://api.github.com/repos/Itseez/opencv/issues/6613/labels{/name}","comments_url":"https://api.github.com/repos/Itseez/opencv/issues/6613/comments","events_url":"https://api.github.com/repos/Itseez/opencv/issues/6613/events","html_url":"https://github.com/Itseez/opencv/issues/6613","id":157733446,"number":6613,"title":"GoodFeaturesToTrack slow for minimumDistance of 1 pixel","user":{"login":"embeddedprogrammer","id":11321258,"avatar_url":"https://avatars.githubusercontent.com/u/11321258?v=3","gravatar_id":"","url":"https://api.github.com/users/embeddedprogrammer","html_url":"https://github.com/embeddedprogrammer","followers_url":"https://api.github.com/users/embeddedprogrammer/followers","following_url":"https://api.github.com/users/embeddedprogrammer/following{/other_user}","gists_url":"https://api.github.com/users/embeddedprogrammer/gists{/gist_id}","starred_url":"https://api.github.com/users/embeddedprogrammer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/embeddedprogrammer/subscriptions","organizations_url":"https://api.github.com/users/embeddedprogrammer/orgs","repos_url":"https://api.github.com/users/embeddedprogrammer/repos","events_url":"https://api.github.com/users/embeddedprogrammer/events{/privacy}","received_events_url":"https://api.github.com/users/embeddedprogrammer/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Itseez/opencv/labels/affected:%20master","name":"affected: master","color":"ededed"},{"url":"https://api.github.com/repos/Itseez/opencv/labels/category:%20features2d","name":"category: features2d","color":"ededed"},{"url":"https://api.github.com/repos/Itseez/opencv/labels/feature","name":"feature","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-31T18:02:23Z","updated_at":"2016-06-09T16:21:04Z","closed_at":null,"body":"On my computer (Intel i7, 2.1GHz, 8GB RAM, OpenCV 3.1, Windows 7) it takes 1120 ms to find features in a 1280x720 image when the minimumDistance is set to 1. If it is set to 0 it runs in 146ms, almost 10 times faster! Any other minimumDistance runs in less than 300 ms. Unfortunately the GFTTDetector's default minimumDistance is set to 1 in the [header](https://github.com/Itseez/opencv/blob/2f4e38c8313ff313de7c41141d56d945d91f47cf/modules/features2d/include/opencv2/features2d.hpp#L493). This makes the GFTTDetector deceptively slow, especially for new users that are testing different feature detectors.\r\n\r\nSetting the minimumDistance to 1 doesn't actually do anything. [Line 373](https://github.com/Itseez/opencv/blob/2f4e38c8313ff313de7c41141d56d945d91f47cf/modules/imgproc/src/featureselect.cpp#L373) shows that the minimumDistance is exclusive, meaning that even if two features are 1 pixel away, both will be kept. Furthermore, the dilate on [line 292](https://github.com/Itseez/opencv/blob/2f4e38c8313ff313de7c41141d56d945d91f47cf/modules/imgproc/src/featureselect.cpp#L292) searches for each maximum in a 3x3 neighborhood and [Line 308](https://github.com/Itseez/opencv/blob/2f4e38c8313ff313de7c41141d56d945d91f47cf/modules/imgproc/src/featureselect.cpp#L308) filters out any features that are not a maximum, which eliminates almost all features that are less than 2 pixels away. So even if the minimumDistance were set to 2, it would give almost exactly the same results.\r\n\r\nOne solution would be to change the header file so the minimumDistance default is 0. Perhaps the best solution would be to change line 324 to check to make sure minimumDistance > 1. The minimum distance calculations could also be optimized for small minimum distances, maybe by setting a minimum cell size of 3.\r\n\r\nExample:\r\n<pre>\r\n#include \"opencv2/highgui/highgui.hpp\"\r\n#include \"opencv2/features2d/features2d.hpp\"\r\n#include \"time.h\"\r\n\r\nusing namespace cv;\r\nusing namespace std;\r\n\r\nint main(int argc, char **argv)\r\n{\r\n\tfor (int minDist = 0; minDist < 10; minDist++)\r\n\t{\r\n\t\tstatic Ptr<GFTTDetector> gfttPtr;\r\n\t\tgfttPtr = GFTTDetector::create(1500, .03, minDist);\r\n\t\tMat img = imread(\"test.jpg\");\r\n\r\n\t\tclock_t clk = clock();\r\n\t\tvector<KeyPoint> keypoints;\r\n\t\tgfttPtr->detect(img, keypoints);\r\n\t\tprintf(\"Time to detect features with minDist = %d: %.0f ms\\n\", minDist, ((float)clock() - clk) / CLOCKS_PER_SEC * 1000);\r\n\t}\r\n\tsystem(\"pause\");\r\n}\r\n</pre>"},"comment":{"url":"https://api.github.com/repos/Itseez/opencv/issues/comments/224947770","html_url":"https://github.com/Itseez/opencv/issues/6613#issuecomment-224947770","issue_url":"https://api.github.com/repos/Itseez/opencv/issues/6613","id":224947770,"user":{"login":"embeddedprogrammer","id":11321258,"avatar_url":"https://avatars.githubusercontent.com/u/11321258?v=3","gravatar_id":"","url":"https://api.github.com/users/embeddedprogrammer","html_url":"https://github.com/embeddedprogrammer","followers_url":"https://api.github.com/users/embeddedprogrammer/followers","following_url":"https://api.github.com/users/embeddedprogrammer/following{/other_user}","gists_url":"https://api.github.com/users/embeddedprogrammer/gists{/gist_id}","starred_url":"https://api.github.com/users/embeddedprogrammer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/embeddedprogrammer/subscriptions","organizations_url":"https://api.github.com/users/embeddedprogrammer/orgs","repos_url":"https://api.github.com/users/embeddedprogrammer/repos","events_url":"https://api.github.com/users/embeddedprogrammer/events{/privacy}","received_events_url":"https://api.github.com/users/embeddedprogrammer/received_events","type":"User","site_admin":false},"created_at":"2016-06-09T16:21:04Z","updated_at":"2016-06-09T16:21:04Z","body":"Update: Somehow I didn't realize how slow OpenCV runs in Debug Mode. It's no longer a problem in Release Mode.\r\n\r\nComparison:\r\n<pre>\r\n---- Debug Mode: ----\r\nTime to detect features with minDist = 0: 191 ms\r\nTime to detect features with minDist = 1: 1239 ms\r\nTime to detect features with minDist = 2: 387 ms\r\nTime to detect features with minDist = 3: 237 ms\r\nTime to detect features with minDist = 4: 182 ms\r\nTime to detect features with minDist = 5: 154 ms\r\nTime to detect features with minDist = 6: 136 ms\r\nTime to detect features with minDist = 7: 126 ms\r\nTime to detect features with minDist = 8: 121 ms\r\nTime to detect features with minDist = 9: 116 ms\r\nPress any key to continue . . .\r\n\r\n---- Release Mode ----\r\nTime to detect features with minDist = 0: 58 ms\r\nTime to detect features with minDist = 1: 39 ms\r\nTime to detect features with minDist = 2: 30 ms\r\nTime to detect features with minDist = 3: 27 ms\r\nTime to detect features with minDist = 4: 30 ms\r\nTime to detect features with minDist = 5: 30 ms\r\nTime to detect features with minDist = 6: 31 ms\r\nTime to detect features with minDist = 7: 31 ms\r\nTime to detect features with minDist = 8: 30 ms\r\nTime to detect features with minDist = 9: 30 ms\r\nPress any key to continue . . .\r\n</pre>\r\n\r\n\r\n"}}
{"actor":{"display_login":"embeddedprogrammer"}}