test_detection_swt.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 (TextDetectionSWT, accuracy_light_on_dark) {
  7. const string dataPath = cvtest::findDataFile("cv/mser/mser_test.png");
  8. Mat image = imread(dataPath, IMREAD_COLOR);
  9. vector<Rect> components;
  10. detectTextSWT(image, components, false);
  11. /* all 5 letter candidates should be identified (R9888) */
  12. EXPECT_EQ(5u, components.size());
  13. }
  14. TEST (TextDetectionSWT, accuracy_dark_on_light) {
  15. const string dataPath = cvtest::findDataFile("cv/mser/mser_test2.png");
  16. Mat image = imread(dataPath, IMREAD_COLOR);
  17. vector<Rect> components;
  18. detectTextSWT(image, components, true);
  19. /* all 3 letter candidates should be identified 2, 5, 8 */
  20. EXPECT_EQ(3u, components.size());
  21. }
  22. TEST (TextDetectionSWT, accuracy_handwriting) {
  23. const string dataPath = cvtest::findDataFile("cv/cloning/Mixed_Cloning/source1.png");
  24. Mat image = imread(dataPath, IMREAD_COLOR);
  25. vector<Rect> components;
  26. detectTextSWT(image, components, true);
  27. /* Handwritten Text is generally more difficult to detect using SWT algorithm due to high variation in stroke width. */
  28. EXPECT_LT(11u, components.size());
  29. /* Although the text contains 15 characters, the current implementation of algorithm outputs 14, including three wrong guesses. So, we check at least 11 (14 - 3) letters are detected.*/
  30. }
  31. TEST (TextDetectionSWT, accuracy_chaining) {
  32. const string dataPath = cvtest::findDataFile("cv/mser/mser_test.png");
  33. Mat image = imread(dataPath, IMREAD_COLOR);
  34. vector<Rect> components;
  35. Mat out(image.size(), CV_8UC3);
  36. vector<Rect> chains;
  37. detectTextSWT(image, components, false, out, chains);
  38. Rect chain = chains[0];
  39. /* Since the word is already segmented and cropped, most of the area is covered by text. It confirms that chaining works. */
  40. EXPECT_LT(0.95 * image.total(), (double)chain.area());
  41. }
  42. }} // namespace