1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge pull request #23108 from crackwitz:issue-23107

Usage of imread(): magic number 0, unchecked result

* docs: rewrite 0/1 to IMREAD_GRAYSCALE/IMREAD_COLOR in imread()

* samples, apps: rewrite 0/1 to IMREAD_GRAYSCALE/IMREAD_COLOR in imread()

* tests: rewrite 0/1 to IMREAD_GRAYSCALE/IMREAD_COLOR in imread()

* doc/py_tutorials: check imread() result
This commit is contained in:
Christoph Rackwitz
2023-01-09 01:55:31 -08:00
committed by GitHub
parent 7b7774476e
commit a64b51dd94
57 changed files with 129 additions and 74 deletions
+1 -1
View File
@@ -216,7 +216,7 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
/* read the image */
String img_file = board_list[idx * 2];
Mat gray = imread( folder + img_file, 0);
Mat gray = imread( folder + img_file, IMREAD_GRAYSCALE);
if( gray.empty() )
{
+6 -6
View File
@@ -456,8 +456,8 @@ void CV_StereoMatchingTest::run(int)
string datasetFullDirName = dataPath + DATASETS_DIR + datasetName + "/";
Mat leftImg = imread(datasetFullDirName + LEFT_IMG_NAME);
Mat rightImg = imread(datasetFullDirName + RIGHT_IMG_NAME);
Mat trueLeftDisp = imread(datasetFullDirName + TRUE_LEFT_DISP_NAME, 0);
Mat trueRightDisp = imread(datasetFullDirName + TRUE_RIGHT_DISP_NAME, 0);
Mat trueLeftDisp = imread(datasetFullDirName + TRUE_LEFT_DISP_NAME, IMREAD_GRAYSCALE);
Mat trueRightDisp = imread(datasetFullDirName + TRUE_RIGHT_DISP_NAME, IMREAD_GRAYSCALE);
Rect calcROI;
if( leftImg.empty() || rightImg.empty() || trueLeftDisp.empty() )
@@ -835,9 +835,9 @@ TEST_P(Calib3d_StereoBM_BufferBM, memAllocsTest)
const int SADWindowSize = get<1>(get<1>(GetParam()));
String path = cvtest::TS::ptr()->get_data_path() + "cv/stereomatching/datasets/teddy/";
Mat leftImg = imread(path + "im2.png", 0);
Mat leftImg = imread(path + "im2.png", IMREAD_GRAYSCALE);
ASSERT_FALSE(leftImg.empty());
Mat rightImg = imread(path + "im6.png", 0);
Mat rightImg = imread(path + "im6.png", IMREAD_GRAYSCALE);
ASSERT_FALSE(rightImg.empty());
Mat leftDisp;
{
@@ -923,9 +923,9 @@ TEST(Calib3d_StereoSGBM, regression) { CV_StereoSGBMTest test; test.safe_run();
TEST(Calib3d_StereoSGBM_HH4, regression)
{
String path = cvtest::TS::ptr()->get_data_path() + "cv/stereomatching/datasets/teddy/";
Mat leftImg = imread(path + "im2.png", 0);
Mat leftImg = imread(path + "im2.png", IMREAD_GRAYSCALE);
ASSERT_FALSE(leftImg.empty());
Mat rightImg = imread(path + "im6.png", 0);
Mat rightImg = imread(path + "im6.png", IMREAD_GRAYSCALE);
ASSERT_FALSE(rightImg.empty());
Mat testData = imread(path + "disp2_hh4.png",-1);
ASSERT_FALSE(testData.empty());
@@ -406,7 +406,7 @@ TEST( Features2d_DescriptorExtractor, batch_ORB )
for( i = 0; i < n; i++ )
{
string imgname = format("%s/img%d.png", path.c_str(), i+1);
Mat img = imread(imgname, 0);
Mat img = imread(imgname, IMREAD_GRAYSCALE);
imgs.push_back(img);
}
@@ -434,7 +434,7 @@ TEST( Features2d_DescriptorExtractor, batch_SIFT )
for( i = 0; i < n; i++ )
{
string imgname = format("%s/img%d.png", path.c_str(), i+1);
Mat img = imread(imgname, 0);
Mat img = imread(imgname, IMREAD_GRAYSCALE);
imgs.push_back(img);
}
@@ -45,7 +45,7 @@ public class ImgcodecsTest extends OpenCVTestCase {
}
public void testImreadStringInt() {
dst = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH, 0);
dst = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH, Imgcodecs.IMREAD_GRAYSCALE);
assertFalse(dst.empty());
assertEquals(1, dst.channels());
assertTrue(512 == dst.cols());
@@ -81,7 +81,7 @@ void CV_ConnectedComponentsTest::run(int /* start_from */)
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
string exp_path = string(ts->get_data_path()) + "connectedcomponents/ccomp_exp.png";
Mat exp = imread(exp_path, 0);
Mat exp = imread(exp_path, IMREAD_GRAYSCALE);
Mat orig = imread(string(ts->get_data_path()) + "connectedcomponents/concentric_circles.png", 0);
if (orig.empty())
+1 -1
View File
@@ -53,7 +53,7 @@ protected:
void run(int)
{
string imgpath = string(ts->get_data_path()) + "shared/lena.png";
Mat img = imread(imgpath, 1), gray, smallimg, result;
Mat img = imread(imgpath, IMREAD_COLOR), gray, smallimg, result;
UMat uimg = img.getUMat(ACCESS_READ), ugray, usmallimg, uresult;
cvtColor(img, gray, COLOR_BGR2GRAY);
+1 -1
View File
@@ -59,7 +59,7 @@ CV_WatershedTest::~CV_WatershedTest() {}
void CV_WatershedTest::run( int /* start_from */)
{
string exp_path = string(ts->get_data_path()) + "watershed/wshed_exp.png";
Mat exp = imread(exp_path, 0);
Mat exp = imread(exp_path, IMREAD_GRAYSCALE);
Mat orig = imread(string(ts->get_data_path()) + "inpaint/orig.png");
FileStorage fs(string(ts->get_data_path()) + "watershed/comp.xml", FileStorage::READ);
@@ -149,7 +149,7 @@ public class OpenCVTestCase extends TestCase {
rgba128 = new Mat(matSize, matSize, CvType.CV_8UC4, Scalar.all(128));
rgbLena = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH);
grayChess = Imgcodecs.imread(OpenCVTestRunner.CHESS_PATH, 0);
grayChess = Imgcodecs.imread(OpenCVTestRunner.CHESS_PATH, Imgcodecs.IMREAD_GRAYSCALE);
gray255_32f_3d = new Mat(new int[]{matSize, matSize, matSize}, CvType.CV_32F, new Scalar(255.0));
@@ -175,7 +175,7 @@ public class OpenCVTestCase extends TestCase {
rgba128 = new Mat(matSize, matSize, CvType.CV_8UC4, Scalar.all(128));
rgbLena = Imgcodecs.imread(OpenCVTestRunner.LENA_PATH);
grayChess = Imgcodecs.imread(OpenCVTestRunner.CHESS_PATH, 0);
grayChess = Imgcodecs.imread(OpenCVTestRunner.CHESS_PATH, Imgcodecs.IMREAD_GRAYSCALE);
gray255_32f_3d = new Mat(new int[]{matSize, matSize, matSize}, CvType.CV_32F, new Scalar(255.0));
@@ -137,7 +137,7 @@ int CV_DetectorTest::prepareData( FileStorage& _fs )
String filename;
it >> filename;
imageFilenames.push_back(filename);
Mat img = imread( dataPath+filename, 1 );
Mat img = imread( dataPath+filename, IMREAD_COLOR );
images.push_back( img );
}
}
+1 -1
View File
@@ -157,7 +157,7 @@ TEST(Photo_White, issue_2646)
TEST(Photo_Denoising, speed)
{
string imgname = string(cvtest::TS::ptr()->get_data_path()) + "shared/5MP.png";
Mat src = imread(imgname, 0), dst;
Mat src = imread(imgname, IMREAD_GRAYSCALE), dst;
double t = (double)getTickCount();
fastNlMeansDenoising(src, dst, 5, 7, 21);
+1 -1
View File
@@ -194,7 +194,7 @@ public:
{
string filename = ts->get_data_path() + "readwrite/ordinary.bmp";
VideoCapture cap(filename, CAP_FFMPEG);
Mat img0 = imread(filename, 1);
Mat img0 = imread(filename, IMREAD_COLOR);
Mat img, img_next;
cap >> img;
cap >> img_next;