added tests for WebP

This commit is contained in:
AoD314 2013-03-07 19:26:44 +04:00
parent 63d9ee9523
commit eb012a5993

View File

@ -332,3 +332,94 @@ TEST(Highgui_Tiff, decode_tile16384x16384)
remove(file4.c_str());
}
#endif
#ifdef HAVE_WEBP
TEST(Highgui_WebP, encode_decode_lossless_webp)
{
cvtest::TS& ts = *cvtest::TS::ptr();
std::string input = std::string(ts.get_data_path()) + "../cv/shared/lena.png";
cv::Mat img = cv::imread(input);
ASSERT_FALSE(img.empty());
std::string output = cv::tempfile(".webp");
EXPECT_NO_THROW(cv::imwrite(output, img)); // lossless
cv::Mat img_webp = cv::imread(output);
std::vector<unsigned char> buf;
FILE * wfile = NULL;
wfile = fopen(output.c_str(), "rb");
if (wfile != NULL)
{
fseek(wfile, 0, SEEK_END);
size_t wfile_size = ftell(wfile);
fseek(wfile, 0, SEEK_SET);
buf.resize(wfile_size);
size_t data_size = fread(&buf[0], 1, wfile_size, wfile);
if(wfile)
{
fclose(wfile);
}
if (data_size != wfile_size)
{
EXPECT_TRUE(false);
}
}
cv::Mat decode = cv::imdecode(buf, CV_LOAD_IMAGE_COLOR);
ASSERT_FALSE(decode.empty());
EXPECT_TRUE(cv::norm(decode, img_webp, NORM_INF) == 0);
ASSERT_FALSE(img_webp.empty());
EXPECT_TRUE(cv::norm(img, img_webp, NORM_INF) == 0);
}
TEST(Highgui_WebP, encode_decode_lossy_webp)
{
cvtest::TS& ts = *cvtest::TS::ptr();
std::string input = std::string(ts.get_data_path()) + "/../cv/shared/lena.png";
cv::Mat img = cv::imread(input);
ASSERT_FALSE(img.empty());
for(int q = 100; q>=0; q-=5)
{
std::vector<int> params;
params.push_back(CV_IMWRITE_WEBP_QUALITY);
params.push_back(q);
string output = cv::tempfile(".webp");
EXPECT_NO_THROW(cv::imwrite(output, img, params));
cv::Mat img_webp = cv::imread(output);
EXPECT_FALSE(img_webp.empty());
}
}
TEST(Highgui_WebP, encode_big_image_webp)
{
cvtest::TS& ts = *cvtest::TS::ptr();
std::string input = std::string(ts.get_data_path()) + "/../cv/shared/lena.png";
cv::Mat img = cv::imread(input);
cv::resize(img, img, cv::Size(8192, 8192));
std::vector<int> params;
params.push_back(CV_IMWRITE_WEBP_QUALITY);
params.push_back(95);
std::string output = cv::tempfile(".webp");
EXPECT_NO_THROW(cv::imwrite(output, img, params));
img.create(10000, 10000, CV_8UC3);
cv::randu(img, 0, 256);
output = cv::tempfile(".webp");
EXPECT_NO_THROW(cv::imwrite(output, img));
}
#endif