Repository: sz3/libcimbar
File: src/lib/extractor/test/ScannerTest.cpp (C++)

Code before:

	std::vector<Anchor> candidates;
	int cutoff = sc.scan_primary(candidates);
	assertEquals( 1541, cutoff );
	assertEquals(
	    "56+-24,166+-25 870+-23,133+-25 136+-18,910+-19",
	    turbo::str::join(candidates)
	);

	assertTrue( sc.add_bottom_right_corner(candidates, cutoff) );
	assertEquals(
	    "56+-24,166+-25 870+-23,133+-25 136+-18,910+-19 837+-18,898+-19",
	    turbo::str::join(candidates)
	);
}

TEST_CASE( "ScannerTest/testBottomRightCorner.4", "[unit]" )
{
	cv::Mat img = cv::imread(TestCimbar::getSample("6bit/4_30_f2_246.jpg"));
	Scanner sc(img);

	std::vector<Anchor> candidates;
	int cutoff = sc.scan_primary(candidates);
	assertEquals( 1461, cutoff );
	assertEquals(
	    "189+-20,899+-23 156+-25,79+-25 924+-17,811+-19",
	    turbo::str::join(candidates)
	);

	assertTrue( sc.add_bottom_right_corner(candidates, cutoff) );
	assertEquals(
	    "189+-20,899+-23 156+-25,79+-25 924+-17,811+-19 911+-18,122+-20",
	    turbo::str::join(candidates)
	);
}


TEST_CASE( "ScannerTest/testExampleScan", "[unit]" )
{
	cv::Mat img = cv::imread(TestCimbar::getSample("6bit/4_30_f0_627.jpg"));
	Scanner sc(img);

	std::vector<Anchor> candidates = sc.scan();
	// order is top-left, top-right, bottom-left, bottom-right
	assertEquals(
	    "210+-24,914+-24 195+-25,61+-25 1039+-22,887+-23 1035+-23,67+-24",
	    turbo::str::join(candidates)
	);
}

TEST_CASE( "ScannerTest/testExampleScan.2", "[unit]" )

Review comment (refactor):
The `189+-20` -> `189+-25` is maybe the most instructive change, when looking at the sample images. The anchor is indeed about 50px wide, but when extracting, we only really care that the average is correct. So there's not much benefit for this particular example (the 1px offsets for `157` and `810` are much more relevant), but the general idea is that it's more likely that we end up with the "real" center point given the additional fidelity.

Code after:

	std::vector<Anchor> candidates;
	int cutoff = sc.scan_primary(candidates);
	assertEquals( 1607, cutoff );
	assertEquals(
	    "56+-24,166+-25 870+-24,133+-26 137+-20,910+-19",
	    turbo::str::join(candidates)
	);

	assertTrue( sc.add_bottom_right_corner(candidates, cutoff) );
	assertEquals(
	    "56+-24,166+-25 870+-24,133+-26 137+-20,910+-19 837+-18,898+-19",
	    turbo::str::join(candidates)
	);
}

TEST_CASE( "ScannerTest/testBottomRightCorner.4", "[unit]" )
{
	cv::Mat img = cv::imread(TestCimbar::getSample("6bit/4_30_f2_246.jpg"));
	Scanner sc(img);

	std::vector<Anchor> candidates;
	int cutoff = sc.scan_primary(candidates);
	assertEquals( 1616, cutoff );
	assertEquals(
	    "189+-25,899+-23 157+-26,79+-25 924+-18,810+-19",
	    turbo::str::join(candidates)
	);

	assertTrue( sc.add_bottom_right_corner(candidates, cutoff) );
	assertEquals(
	    "189+-25,899+-23 157+-26,79+-25 924+-18,810+-19 911+-18,122+-20",
	    turbo::str::join(candidates)
	);
}


TEST_CASE( "ScannerTest/testExampleScan", "[unit]" )
{
	cv::Mat img = cv::imread(TestCimbar::getSample("6bit/4_30_f0_627.jpg"));
	Scanner sc(img);

	std::vector<Anchor> candidates = sc.scan();
	// order is top-left, top-right, bottom-left, bottom-right
	assertEquals(
	    "210+-25,914+-24 195+-25,61+-25 1039+-23,887+-23 1035+-23,67+-24",
	    turbo::str::join(candidates)
	);
}

TEST_CASE( "ScannerTest/testExampleScan.2", "[unit]" )