1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
43 #include "test_precomp.hpp"
44 #include "opencv2/highgui/highgui.hpp"
50 class CV_GrfmtWriteBigImageTest : public cvtest::BaseTest
57 ts->printf(cvtest::TS::LOG, "start reading big image\n");
58 Mat img = imread(string(ts->get_data_path()) + "readwrite/read.png");
59 ts->printf(cvtest::TS::LOG, "finish reading big image\n");
60 if (img.empty()) ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
61 ts->printf(cvtest::TS::LOG, "start writing big image\n");
62 imwrite(string(ts->get_data_path()) + "readwrite/write.png", img);
63 ts->printf(cvtest::TS::LOG, "finish writing big image\n");
67 ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION);
69 ts->set_failed_test_info(cvtest::TS::OK);
73 string ext_from_int(int ext)
75 if (ext == 0) return ".png";
76 if (ext == 1) return ".bmp";
77 if (ext == 2) return ".pgm";
78 if (ext == 3) return ".tiff";
82 class CV_GrfmtWriteSequenceImageTest : public cvtest::BaseTest
89 const int img_r = 640;
90 const int img_c = 480;
92 for (int k = 1; k <= 5; ++k)
94 for (int ext = 0; ext < 4; ++ext) // 0 - png, 1 - bmp, 2 - pgm, 3 - tiff
95 for (int num_channels = 1; num_channels <= 3; num_channels+=2)
97 ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_8U, num_channels, ext_from_int(ext).c_str());
98 Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_8U, num_channels), Scalar::all(0));
99 circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), cv::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255));
100 ts->printf(ts->LOG, "writing image : %s\n", string(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext)).c_str());
101 imwrite(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext), img);
102 ts->printf(ts->LOG, "reading test image : %s\n", string(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext)).c_str());
104 Mat img_test = imread(string(ts->get_data_path()) + "readwrite/test" + ext_from_int(ext), CV_LOAD_IMAGE_UNCHANGED);
106 if (img_test.empty()) ts->set_failed_test_info(ts->FAIL_MISMATCH);
108 CV_Assert(img.size() == img_test.size());
109 CV_Assert(img.type() == img_test.type());
111 double n = norm(img, img_test);
114 ts->printf(ts->LOG, "norm = %f \n", n);
115 ts->set_failed_test_info(ts->FAIL_MISMATCH);
119 for (int num_channels = 1; num_channels <= 3; num_channels+=2)
122 ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_8U, num_channels, ".jpg");
123 Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_8U, num_channels), Scalar::all(0));
124 circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), cv::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255));
125 string filename = string(ts->get_data_path() + "readwrite/test_" + char(k + 48) + "_c" + char(num_channels + 48) + "_.jpg");
126 imwrite(filename, img);
127 img = imread(filename, CV_LOAD_IMAGE_UNCHANGED);
129 filename = string(ts->get_data_path() + "readwrite/test_" + char(k + 48) + "_c" + char(num_channels + 48) + ".jpg");
130 ts->printf(ts->LOG, "reading test image : %s\n", filename.c_str());
131 Mat img_test = imread(filename, CV_LOAD_IMAGE_UNCHANGED);
133 if (img_test.empty()) ts->set_failed_test_info(ts->FAIL_MISMATCH);
135 CV_Assert(img.size() == img_test.size());
136 CV_Assert(img.type() == img_test.type());
138 double n = norm(img, img_test);
141 ts->printf(ts->LOG, "norm = %f \n", n);
142 ts->set_failed_test_info(ts->FAIL_MISMATCH);
146 for (int num_channels = 1; num_channels <= 3; num_channels+=2)
149 ts->printf(ts->LOG, "image type depth:%d channels:%d ext: %s\n", CV_16U, num_channels, ".tiff");
150 Mat img(img_r * k, img_c * k, CV_MAKETYPE(CV_16U, num_channels), Scalar::all(0));
151 circle(img, Point2i((img_c * k) / 2, (img_r * k) / 2), cv::min((img_r * k), (img_c * k)) / 4 , Scalar::all(255));
152 string filename = string(ts->get_data_path() + "readwrite/test.tiff");
153 imwrite(filename, img);
154 ts->printf(ts->LOG, "reading test image : %s\n", filename.c_str());
155 Mat img_test = imread(filename, CV_LOAD_IMAGE_UNCHANGED);
157 if (img_test.empty()) ts->set_failed_test_info(ts->FAIL_MISMATCH);
159 CV_Assert(img.size() == img_test.size());
161 ts->printf(ts->LOG, "img : %d ; %d \n", img.channels(), img.depth());
162 ts->printf(ts->LOG, "img_test : %d ; %d \n", img_test.channels(), img_test.depth());
164 CV_Assert(img.type() == img_test.type());
167 double n = norm(img, img_test);
170 ts->printf(ts->LOG, "norm = %f \n", n);
171 ts->set_failed_test_info(ts->FAIL_MISMATCH);
176 catch(const cv::Exception & e)
178 ts->printf(ts->LOG, "Exception: %s\n" , e.what());
179 ts->set_failed_test_info(ts->FAIL_MISMATCH);
184 TEST(Highgui_Grfmt_WriteBigImage, regression) { CV_GrfmtWriteBigImageTest test; test.safe_run(); }
185 TEST(Highgui_Grfmt_WriteSequenceImage, regression) { CV_GrfmtWriteSequenceImageTest test; test.safe_run(); }