mirror of
https://github.com/opencv/opencv.git
synced 2024-12-18 19:38:02 +08:00
Make objdetect/test C++11-compliant and reproducible
- Add conditional compilation directives to replace deprecated std::random_shuffle with new std::shuffle when C++11 is available. - Set random seed to a fixed value before shuffling containers to ensure reproducibility. Resolves opencv/opencv#22209.
This commit is contained in:
parent
0a88f84847
commit
3135063100
@ -8,4 +8,10 @@
|
|||||||
#include "opencv2/objdetect.hpp"
|
#include "opencv2/objdetect.hpp"
|
||||||
#include "opencv2/objdetect/objdetect_c.h"
|
#include "opencv2/objdetect/objdetect_c.h"
|
||||||
|
|
||||||
|
#if defined CV_CXX11
|
||||||
|
#include <random>
|
||||||
|
#else
|
||||||
|
#include <cstdlib>
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,6 +5,16 @@
|
|||||||
#include "test_precomp.hpp"
|
#include "test_precomp.hpp"
|
||||||
namespace opencv_test { namespace {
|
namespace opencv_test { namespace {
|
||||||
|
|
||||||
|
#if !defined CV_CXX11
|
||||||
|
// Wrapper for generating seeded random number via std::rand.
|
||||||
|
template<unsigned Seed>
|
||||||
|
class SeededRandFunctor {
|
||||||
|
public:
|
||||||
|
SeededRandFunctor() { std::srand(Seed); }
|
||||||
|
int operator()(int i) { return std::rand() % (i + 1); }
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string encode_qrcode_images_name[] = {
|
std::string encode_qrcode_images_name[] = {
|
||||||
"version1_mode1.png", "version1_mode2.png", "version1_mode4.png",
|
"version1_mode1.png", "version1_mode2.png", "version1_mode4.png",
|
||||||
"version2_mode1.png", "version2_mode2.png", "version2_mode4.png",
|
"version2_mode1.png", "version2_mode2.png", "version2_mode4.png",
|
||||||
@ -381,8 +391,15 @@ TEST(Objdetect_QRCode_Encode_Decode_Structured_Append, DISABLED_regression)
|
|||||||
std::string symbol_set = config["symbols_set"];
|
std::string symbol_set = config["symbols_set"];
|
||||||
|
|
||||||
std::string input_info = symbol_set;
|
std::string input_info = symbol_set;
|
||||||
std::random_shuffle(input_info.begin(), input_info.end());
|
#if defined CV_CXX11
|
||||||
|
// std::random_shuffle is deprecated since C++11 and removed in C++17.
|
||||||
|
// Use manually constructed RNG with a fixed seed and std::shuffle instead.
|
||||||
|
std::mt19937 rand_gen {1};
|
||||||
|
std::shuffle(input_info.begin(), input_info.end(), rand_gen);
|
||||||
|
#else
|
||||||
|
SeededRandFunctor<1> rand_gen;
|
||||||
|
std::random_shuffle(input_info.begin(), input_info.end(), rand_gen);
|
||||||
|
#endif
|
||||||
for (int j = min_stuctures_num; j < max_stuctures_num; j++)
|
for (int j = min_stuctures_num; j < max_stuctures_num; j++)
|
||||||
{
|
{
|
||||||
QRCodeEncoder::Params params;
|
QRCodeEncoder::Params params;
|
||||||
|
Loading…
Reference in New Issue
Block a user