Merge pull request #29741 from varun-jaiswal17:objdetect_cleanup

Objdetect test cleanup - #29741

co-authored by: @Prasadayus

### Given real assertions

| change | reason |
|---|---|
| new `Objdetect_CheckChessboard.accuracy` (`test_checkchessboard.cpp`) | `cv::checkChessboard`'s only validation lived inside a test named `timing`, which aborted at the first of 19 images. The new test iterates all 19 from `chessboard_timing_list.dat` with `SCOPED_TRACE` and `EXPECT_EQ`, so every image is reported instead of stopping at the first mismatch |
| deleted `test_chesscorners_timing.cpp` | what remained after extracting the assertions was a stopwatch — it measured `findChessboardCorners` and asserted nothing about the result |

### Re-enabled - the reason for disabling no longer holds

| test | reason |
|---|---|
| `Charuco.testSeveralBoardsWithCustomIds` (`test_charucodetection.cpp:922`) | disabled by #24338 because 5.x returns charuco corners as `32FC2` rather than `2×32FC1` (#23473). The test never compares shapes: it asserts `expected_corners.total() == c_corners.total() * c_corners.channels()` and then compares `expected_corners.reshape(1, 1)` against `c_corners.reshape(1, 1)` — both flattened to one row, so the channel layout cannot affect the result. The comparison was already made shape-agnostic; only the `DISABLED_` prefix was never removed |


### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Varun Jaiswal
2026-08-26 10:05:11 +03:00
committed by GitHub
parent 8e3e271d86
commit 9b60166420
3 changed files with 48 additions and 163 deletions
@@ -917,9 +917,7 @@ TEST_P(CharucoBoardGenerate, issue_24806)
}
}
// Temporary disabled in https://github.com/opencv/opencv/pull/24338
// 5.x version produces conrnes with different shape than 4.x (32F_C2 instead of 2x 32FC1)
TEST(Charuco, DISABLED_testSeveralBoardsWithCustomIds)
TEST(Charuco, testSeveralBoardsWithCustomIds)
{
Size res{500, 500};
Mat K = (Mat_<double>(3,3) <<
@@ -957,5 +957,52 @@ TEST(Calib3d_CornerOrdering, issue_26830) {
ASSERT_EQ(cornersMinimumSizeMatchesPatternSize, cornersMinimumSizeSmallerThanPatternSize);
}
// findChessboardCorners() falls back to checkChessboard() under CALIB_CB_FAST_CHECK
// (calibinit.cpp), so a false negative here costs a detection.
//
// checkChessboard() is deliberately not required to agree with findChessboardCorners():
// it is a permissive pre-filter, and the two legitimately differ on
// chessboard-artificial2.png, where checkChessboard() is the one that gets it right.
TEST(Calib3d_CheckChessboard, accuracy)
{
const string folder = string(cvtest::TS::ptr()->get_data_path()) + "cameracalibration/";
const string listname = folder + "chessboard_timing_list.dat";
FileStorage fs(listname, FileStorage::READ);
ASSERT_TRUE(fs.isOpened()) << "Could not read " << listname;
FileNode boards = fs["boards"];
ASSERT_TRUE(boards.isSeq()) << listname << " does not contain a 'boards' sequence";
ASSERT_EQ(size_t(0), boards.size() % 4) << listname << " is malformed";
const int count = (int)boards.size() / 4;
ASSERT_GT(count, 0) << listname << " lists no images";
FileNodeIterator it = boards.begin();
for (int i = 0; i < count; i++)
{
string imgname;
int isChessboard = 0;
Size patternSize;
read(*it++, imgname, "dummy.txt");
read(*it++, isChessboard, 0);
read(*it++, patternSize.width, -1);
read(*it++, patternSize.height, -1);
SCOPED_TRACE(cv::format("image %d/%d: %s", i + 1, count, imgname.c_str()));
Mat img = imread(folder + imgname);
ASSERT_FALSE(img.empty()) << "Could not read " << folder << imgname;
ASSERT_GT(patternSize.width, 0);
ASSERT_GT(patternSize.height, 0);
Mat gray;
cvtColor(img, gray, COLOR_BGR2GRAY);
// EXPECT, not ASSERT: report every image rather than stopping at the first.
EXPECT_EQ(isChessboard != 0, checkChessboard(gray, patternSize));
}
}
}} // namespace
/* End of file. */
@@ -1,160 +0,0 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "test_precomp.hpp"
#include "opencv2/imgproc.hpp"
namespace opencv_test { namespace {
class CV_ChessboardDetectorTimingTest : public cvtest::BaseTest
{
public:
CV_ChessboardDetectorTimingTest();
protected:
void run(int);
};
CV_ChessboardDetectorTimingTest::CV_ChessboardDetectorTimingTest()
{
}
/* ///////////////////// chess_corner_test ///////////////////////// */
void CV_ChessboardDetectorTimingTest::run( int start_from )
{
int code = cvtest::TS::OK;
/* test parameters */
std::string filepath;
std::string filename;
std::vector<Point2f> v;
Mat img, gray, thresh;
int idx, max_idx;
int progress = 0;
filepath = cv::format("%scameracalibration/", ts->get_data_path().c_str() );
filename = cv::format("%schessboard_timing_list.dat", filepath.c_str() );
cv::FileStorage fs( filename, FileStorage::READ );
cv::FileNode board_list = fs["boards"];
cv::FileNodeIterator bl_it = board_list.begin();
if( !fs.isOpened() || !board_list.isSeq() || board_list.size() % 4 != 0 )
{
ts->printf( cvtest::TS::LOG, "chessboard_timing_list.dat can not be read or is not valid" );
code = cvtest::TS::FAIL_MISSING_TEST_DATA;
goto _exit_;
}
max_idx = (int)(board_list.size()/4);
for( idx = 0; idx < start_from; idx++ )
{
bl_it += 4;
}
for( idx = start_from; idx < max_idx; idx++ )
{
Size pattern_size;
std::string imgname; read(*bl_it++, imgname, "dummy.txt");
int is_chessboard = 0;
read(*bl_it++, is_chessboard, 0);
read(*bl_it++, pattern_size.width, -1);
read(*bl_it++, pattern_size.height, -1);
ts->update_context( this, idx-1, true );
/* read the image */
filename = cv::format("%s%s", filepath.c_str(), imgname.c_str() );
img = cv::imread( filename );
if( img.empty() )
{
ts->printf( cvtest::TS::LOG, "one of chessboard images can't be read: %s\n", filename.c_str() );
code = cvtest::TS::FAIL_MISSING_TEST_DATA;
continue;
}
ts->printf(cvtest::TS::LOG, "%s: chessboard %d:\n", imgname.c_str(), is_chessboard);
cvtColor(img, gray, COLOR_BGR2GRAY);
int64 _time0 = cv::getTickCount();
bool result = cv::checkChessboard(gray, pattern_size);
int64 _time01 = cv::getTickCount();
bool result1 = findChessboardCorners(gray, pattern_size, v, 15);
int64 _time1 = cv::getTickCount();
if( result != (is_chessboard != 0))
{
ts->printf( cvtest::TS::LOG, "Error: chessboard was %sdetected in the image %s\n",
result ? "" : "not ", imgname.c_str() );
code = cvtest::TS::FAIL_INVALID_OUTPUT;
goto _exit_;
}
if(result != result1)
{
ts->printf( cvtest::TS::LOG, "Warning: results differ cvCheckChessboard %d, cvFindChessboardCorners %d\n",
(int)result, (int)result1);
}
int num_pixels = gray.cols*gray.rows;
float check_chessboard_time = float(_time01 - _time0)/(float)cv::getTickFrequency(); // in s
ts->printf(cvtest::TS::LOG, " cvCheckChessboard time s: %f, us per pixel: %f\n",
check_chessboard_time, check_chessboard_time*1e6/num_pixels);
float find_chessboard_time = float(_time1 - _time01)/(float)cv::getTickFrequency();
ts->printf(cvtest::TS::LOG, " cvFindChessboard time s: %f, us per pixel: %f\n",
find_chessboard_time, find_chessboard_time*1e6/num_pixels);
progress = update_progress( progress, idx-1, max_idx, 0 );
}
_exit_:
if( code < 0 )
ts->set_failed_test_info( code );
}
TEST(Calib3d_ChessboardDetector, timing) { CV_ChessboardDetectorTimingTest test; test.safe_run(); }
}} // namespace
/* End of file. */