File: test_detection_swt.cpp

package info (click to toggle)
opencv 4.5.1%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 268,248 kB
  • sloc: cpp: 969,170; xml: 682,525; python: 36,732; lisp: 30,170; java: 25,155; ansic: 7,927; javascript: 5,643; objc: 2,041; sh: 935; cs: 601; perl: 494; makefile: 145
file content (49 lines) | stat: -rw-r--r-- 2,129 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

#include "test_precomp.hpp"

namespace opencv_test { namespace {

TEST (TextDetectionSWT, accuracy_light_on_dark) {
    const string dataPath = cvtest::findDataFile("cv/mser/mser_test.png");
    Mat image = imread(dataPath, IMREAD_COLOR);
    vector<Rect> components;
    detectTextSWT(image, components, false);
    /* all 5 letter candidates should be identified (R9888) */
    EXPECT_EQ(5u, components.size());
}

TEST (TextDetectionSWT, accuracy_dark_on_light) {
    const string dataPath = cvtest::findDataFile("cv/mser/mser_test2.png");
    Mat image = imread(dataPath, IMREAD_COLOR);
    vector<Rect> components;
    detectTextSWT(image, components, true);
    /* all 3 letter candidates should be identified 2, 5, 8 */
    EXPECT_EQ(3u, components.size());
}

TEST (TextDetectionSWT, accuracy_handwriting) {
    const string dataPath = cvtest::findDataFile("cv/cloning/Mixed_Cloning/source1.png");
    Mat image = imread(dataPath, IMREAD_COLOR);
    vector<Rect> components;
    detectTextSWT(image, components, true);
    /* Handwritten Text is generally more difficult to detect using SWT algorithm due to high variation in stroke width. */
    EXPECT_LT(11u, components.size());
    /* 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.*/
}

TEST (TextDetectionSWT, accuracy_chaining) {
    const string dataPath = cvtest::findDataFile("cv/mser/mser_test.png");
    Mat image = imread(dataPath, IMREAD_COLOR);
    vector<Rect> components;
    Mat out(image.size(), CV_8UC3);
    vector<Rect> chains;
    detectTextSWT(image, components, false, out, chains);
    Rect chain = chains[0];
    /* Since the word is already segmented and cropped, most of the area is covered by text. It confirms that chaining works. */
    EXPECT_LT(0.95 * image.total(), (double)chain.area());
}

}} // namespace