mirror of https://github.com/opencv/opencv.git
Merge pull request #8856 from mshabunin:media-tests-upgrade
commit
d27009c775
28 changed files with 1134 additions and 2316 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,180 @@ |
||||
#include "test_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
using namespace std::tr1; |
||||
|
||||
#ifdef HAVE_JPEG |
||||
|
||||
/**
|
||||
* Test for check whether reading exif orientation tag was processed successfully or not |
||||
* The test info is the set of 8 images named testExifRotate_{1 to 8}.jpg |
||||
* The test image is the square 10x10 points divided by four sub-squares: |
||||
* (R corresponds to Red, G to Green, B to Blue, W to white) |
||||
* --------- --------- |
||||
* | R | G | | G | R | |
||||
* |-------| - (tag 1) |-------| - (tag 2) |
||||
* | B | W | | W | B | |
||||
* --------- --------- |
||||
* |
||||
* --------- --------- |
||||
* | W | B | | B | W | |
||||
* |-------| - (tag 3) |-------| - (tag 4) |
||||
* | G | R | | R | G | |
||||
* --------- --------- |
||||
* |
||||
* --------- --------- |
||||
* | R | B | | G | W | |
||||
* |-------| - (tag 5) |-------| - (tag 6) |
||||
* | G | W | | R | B | |
||||
* --------- --------- |
||||
* |
||||
* --------- --------- |
||||
* | W | G | | B | R | |
||||
* |-------| - (tag 7) |-------| - (tag 8) |
||||
* | B | R | | W | G | |
||||
* --------- --------- |
||||
* |
||||
* |
||||
* Every image contains exif field with orientation tag (0x112) |
||||
* After reading each image the corresponding matrix must be read as |
||||
* --------- |
||||
* | R | G | |
||||
* |-------| |
||||
* | B | W | |
||||
* --------- |
||||
* |
||||
*/ |
||||
|
||||
typedef testing::TestWithParam<string> Imgcodecs_Jpeg_Exif; |
||||
|
||||
TEST_P(Imgcodecs_Jpeg_Exif, exif_orientation) |
||||
{ |
||||
const string root = cvtest::TS::ptr()->get_data_path(); |
||||
const string filename = root + GetParam(); |
||||
const int colorThresholdHigh = 250; |
||||
const int colorThresholdLow = 5; |
||||
|
||||
Mat m_img = imread(filename); |
||||
ASSERT_FALSE(m_img.empty()); |
||||
Vec3b vec; |
||||
|
||||
//Checking the first quadrant (with supposed red)
|
||||
vec = m_img.at<Vec3b>(2, 2); //some point inside the square
|
||||
EXPECT_LE(vec.val[0], colorThresholdLow); |
||||
EXPECT_LE(vec.val[1], colorThresholdLow); |
||||
EXPECT_GE(vec.val[2], colorThresholdHigh); |
||||
|
||||
//Checking the second quadrant (with supposed green)
|
||||
vec = m_img.at<Vec3b>(2, 7); //some point inside the square
|
||||
EXPECT_LE(vec.val[0], colorThresholdLow); |
||||
EXPECT_GE(vec.val[1], colorThresholdHigh); |
||||
EXPECT_LE(vec.val[2], colorThresholdLow); |
||||
|
||||
//Checking the third quadrant (with supposed blue)
|
||||
vec = m_img.at<Vec3b>(7, 2); //some point inside the square
|
||||
EXPECT_GE(vec.val[0], colorThresholdHigh); |
||||
EXPECT_LE(vec.val[1], colorThresholdLow); |
||||
EXPECT_LE(vec.val[2], colorThresholdLow); |
||||
} |
||||
|
||||
const string exif_files[] = |
||||
{ |
||||
"readwrite/testExifOrientation_1.jpg", |
||||
"readwrite/testExifOrientation_2.jpg", |
||||
"readwrite/testExifOrientation_3.jpg", |
||||
"readwrite/testExifOrientation_4.jpg", |
||||
"readwrite/testExifOrientation_5.jpg", |
||||
"readwrite/testExifOrientation_6.jpg", |
||||
"readwrite/testExifOrientation_7.jpg", |
||||
"readwrite/testExifOrientation_8.jpg" |
||||
}; |
||||
|
||||
INSTANTIATE_TEST_CASE_P(ExifFiles, Imgcodecs_Jpeg_Exif, |
||||
testing::ValuesIn(exif_files)); |
||||
|
||||
//==================================================================================================
|
||||
|
||||
TEST(Imgcodecs_Jpeg, encode_empty) |
||||
{ |
||||
cv::Mat img; |
||||
std::vector<uchar> jpegImg; |
||||
ASSERT_THROW(cv::imencode(".jpg", img, jpegImg), cv::Exception); |
||||
} |
||||
|
||||
TEST(Imgcodecs_Jpeg, encode_decode_progressive_jpeg) |
||||
{ |
||||
cvtest::TS& ts = *cvtest::TS::ptr(); |
||||
string input = string(ts.get_data_path()) + "../cv/shared/lena.png"; |
||||
cv::Mat img = cv::imread(input); |
||||
ASSERT_FALSE(img.empty()); |
||||
|
||||
std::vector<int> params; |
||||
params.push_back(IMWRITE_JPEG_PROGRESSIVE); |
||||
params.push_back(1); |
||||
|
||||
string output_progressive = cv::tempfile(".jpg"); |
||||
EXPECT_NO_THROW(cv::imwrite(output_progressive, img, params)); |
||||
cv::Mat img_jpg_progressive = cv::imread(output_progressive); |
||||
|
||||
string output_normal = cv::tempfile(".jpg"); |
||||
EXPECT_NO_THROW(cv::imwrite(output_normal, img)); |
||||
cv::Mat img_jpg_normal = cv::imread(output_normal); |
||||
|
||||
EXPECT_EQ(0, cvtest::norm(img_jpg_progressive, img_jpg_normal, NORM_INF)); |
||||
|
||||
remove(output_progressive.c_str()); |
||||
remove(output_normal.c_str()); |
||||
} |
||||
|
||||
TEST(Imgcodecs_Jpeg, encode_decode_optimize_jpeg) |
||||
{ |
||||
cvtest::TS& ts = *cvtest::TS::ptr(); |
||||
string input = string(ts.get_data_path()) + "../cv/shared/lena.png"; |
||||
cv::Mat img = cv::imread(input); |
||||
ASSERT_FALSE(img.empty()); |
||||
|
||||
std::vector<int> params; |
||||
params.push_back(IMWRITE_JPEG_OPTIMIZE); |
||||
params.push_back(1); |
||||
|
||||
string output_optimized = cv::tempfile(".jpg"); |
||||
EXPECT_NO_THROW(cv::imwrite(output_optimized, img, params)); |
||||
cv::Mat img_jpg_optimized = cv::imread(output_optimized); |
||||
|
||||
string output_normal = cv::tempfile(".jpg"); |
||||
EXPECT_NO_THROW(cv::imwrite(output_normal, img)); |
||||
cv::Mat img_jpg_normal = cv::imread(output_normal); |
||||
|
||||
EXPECT_EQ(0, cvtest::norm(img_jpg_optimized, img_jpg_normal, NORM_INF)); |
||||
|
||||
remove(output_optimized.c_str()); |
||||
remove(output_normal.c_str()); |
||||
} |
||||
|
||||
TEST(Imgcodecs_Jpeg, encode_decode_rst_jpeg) |
||||
{ |
||||
cvtest::TS& ts = *cvtest::TS::ptr(); |
||||
string input = string(ts.get_data_path()) + "../cv/shared/lena.png"; |
||||
cv::Mat img = cv::imread(input); |
||||
ASSERT_FALSE(img.empty()); |
||||
|
||||
std::vector<int> params; |
||||
params.push_back(IMWRITE_JPEG_RST_INTERVAL); |
||||
params.push_back(1); |
||||
|
||||
string output_rst = cv::tempfile(".jpg"); |
||||
EXPECT_NO_THROW(cv::imwrite(output_rst, img, params)); |
||||
cv::Mat img_jpg_rst = cv::imread(output_rst); |
||||
|
||||
string output_normal = cv::tempfile(".jpg"); |
||||
EXPECT_NO_THROW(cv::imwrite(output_normal, img)); |
||||
cv::Mat img_jpg_normal = cv::imread(output_normal); |
||||
|
||||
EXPECT_EQ(0, cvtest::norm(img_jpg_rst, img_jpg_normal, NORM_INF)); |
||||
|
||||
remove(output_rst.c_str()); |
||||
remove(output_normal.c_str()); |
||||
} |
||||
|
||||
#endif // HAVE_JPEG
|
@ -0,0 +1,95 @@ |
||||
#include "test_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
using namespace std::tr1; |
||||
|
||||
#ifdef HAVE_PNG |
||||
|
||||
TEST(Imgcodecs_Png, write_big) |
||||
{ |
||||
const string root = cvtest::TS::ptr()->get_data_path(); |
||||
const string filename = root + "readwrite/read.png"; |
||||
const string dst_file = cv::tempfile(".png"); |
||||
Mat img; |
||||
ASSERT_NO_THROW(img = imread(filename)); |
||||
ASSERT_FALSE(img.empty()); |
||||
EXPECT_EQ(13043, img.cols); |
||||
EXPECT_EQ(13917, img.rows); |
||||
ASSERT_NO_THROW(imwrite(dst_file, img)); |
||||
remove(dst_file.c_str()); |
||||
} |
||||
|
||||
TEST(Imgcodecs_Png, encode) |
||||
{ |
||||
vector<uchar> buff; |
||||
Mat img_gt = Mat::zeros(1000, 1000, CV_8U); |
||||
vector<int> param; |
||||
param.push_back(IMWRITE_PNG_COMPRESSION); |
||||
param.push_back(3); //default(3) 0-9.
|
||||
EXPECT_NO_THROW(imencode(".png", img_gt, buff, param)); |
||||
Mat img; |
||||
EXPECT_NO_THROW(img = imdecode(buff, IMREAD_ANYDEPTH)); // hang
|
||||
EXPECT_FALSE(img.empty()); |
||||
EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), img, img_gt); |
||||
} |
||||
|
||||
TEST(Imgcodecs_Png, regression_ImreadVSCvtColor) |
||||
{ |
||||
const string root = cvtest::TS::ptr()->get_data_path(); |
||||
const string imgName = root + "../cv/shared/lena.png"; |
||||
Mat original_image = imread(imgName); |
||||
Mat gray_by_codec = imread(imgName, IMREAD_GRAYSCALE); |
||||
Mat gray_by_cvt; |
||||
cvtColor(original_image, gray_by_cvt, CV_BGR2GRAY); |
||||
|
||||
Mat diff; |
||||
absdiff(gray_by_codec, gray_by_cvt, diff); |
||||
EXPECT_LT(cvtest::mean(diff)[0], 1.); |
||||
EXPECT_PRED_FORMAT2(cvtest::MatComparator(10, 0), gray_by_codec, gray_by_cvt); |
||||
} |
||||
|
||||
// Test OpenCV issue 3075 is solved
|
||||
TEST(Imgcodecs_Png, read_color_palette_with_alpha) |
||||
{ |
||||
const string root = cvtest::TS::ptr()->get_data_path(); |
||||
Mat img; |
||||
|
||||
// First Test : Read PNG with alpha, imread flag -1
|
||||
img = imread(root + "readwrite/color_palette_alpha.png", IMREAD_UNCHANGED); |
||||
ASSERT_FALSE(img.empty()); |
||||
ASSERT_TRUE(img.channels() == 4); |
||||
|
||||
// pixel is red in BGRA
|
||||
EXPECT_EQ(img.at<Vec4b>(0, 0), Vec4b(0, 0, 255, 255)); |
||||
EXPECT_EQ(img.at<Vec4b>(0, 1), Vec4b(0, 0, 255, 255)); |
||||
|
||||
// Second Test : Read PNG without alpha, imread flag -1
|
||||
img = imread(root + "readwrite/color_palette_no_alpha.png", IMREAD_UNCHANGED); |
||||
ASSERT_FALSE(img.empty()); |
||||
ASSERT_TRUE(img.channels() == 3); |
||||
|
||||
// pixel is red in BGR
|
||||
EXPECT_EQ(img.at<Vec3b>(0, 0), Vec3b(0, 0, 255)); |
||||
EXPECT_EQ(img.at<Vec3b>(0, 1), Vec3b(0, 0, 255)); |
||||
|
||||
// Third Test : Read PNG with alpha, imread flag 1
|
||||
img = imread(root + "readwrite/color_palette_alpha.png", IMREAD_COLOR); |
||||
ASSERT_FALSE(img.empty()); |
||||
ASSERT_TRUE(img.channels() == 3); |
||||
|
||||
// pixel is red in BGR
|
||||
EXPECT_EQ(img.at<Vec3b>(0, 0), Vec3b(0, 0, 255)); |
||||
EXPECT_EQ(img.at<Vec3b>(0, 1), Vec3b(0, 0, 255)); |
||||
|
||||
// Fourth Test : Read PNG without alpha, imread flag 1
|
||||
img = imread(root + "readwrite/color_palette_no_alpha.png", IMREAD_COLOR); |
||||
ASSERT_FALSE(img.empty()); |
||||
ASSERT_TRUE(img.channels() == 3); |
||||
|
||||
// pixel is red in BGR
|
||||
EXPECT_EQ(img.at<Vec3b>(0, 0), Vec3b(0, 0, 255)); |
||||
EXPECT_EQ(img.at<Vec3b>(0, 1), Vec3b(0, 0, 255)); |
||||
} |
||||
|
||||
#endif // HAVE_PNG
|
@ -0,0 +1,122 @@ |
||||
#include "test_precomp.hpp" |
||||
|
||||
#include <fstream> |
||||
#include <sstream> |
||||
#include <iostream> |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
using namespace cvtest; |
||||
|
||||
TEST(Imgcodecs_Image, read_write_bmp) |
||||
{ |
||||
const size_t IMAGE_COUNT = 10; |
||||
const double thresDbell = 32; |
||||
|
||||
for (size_t i = 0; i < IMAGE_COUNT; ++i) |
||||
{ |
||||
stringstream s; s << i; |
||||
const string digit = s.str(); |
||||
const string src_name = TS::ptr()->get_data_path() + "../python/images/QCIF_0" + digit + ".bmp"; |
||||
const string dst_name = cv::tempfile((digit + ".bmp").c_str()); |
||||
Mat image = imread(src_name); |
||||
ASSERT_FALSE(image.empty()); |
||||
|
||||
resize(image, image, Size(968, 757), 0.0, 0.0, INTER_CUBIC); |
||||
imwrite(dst_name, image); |
||||
Mat loaded = imread(dst_name); |
||||
ASSERT_FALSE(loaded.empty()); |
||||
|
||||
double psnr = cvtest::PSNR(loaded, image); |
||||
EXPECT_GT(psnr, thresDbell); |
||||
|
||||
vector<uchar> from_file; |
||||
|
||||
FILE *f = fopen(dst_name.c_str(), "rb"); |
||||
fseek(f, 0, SEEK_END); |
||||
long len = ftell(f); |
||||
from_file.resize((size_t)len); |
||||
fseek(f, 0, SEEK_SET); |
||||
from_file.resize(fread(&from_file[0], 1, from_file.size(), f)); |
||||
fclose(f); |
||||
|
||||
vector<uchar> buf; |
||||
imencode(".bmp", image, buf); |
||||
ASSERT_EQ(buf, from_file); |
||||
|
||||
Mat buf_loaded = imdecode(Mat(buf), 1); |
||||
ASSERT_FALSE(buf_loaded.empty()); |
||||
|
||||
psnr = cvtest::PSNR(buf_loaded, image); |
||||
EXPECT_GT(psnr, thresDbell); |
||||
|
||||
remove(dst_name.c_str()); |
||||
} |
||||
} |
||||
|
||||
//==================================================================================================
|
||||
|
||||
typedef string Ext; |
||||
typedef testing::TestWithParam<Ext> Imgcodecs_Image; |
||||
|
||||
TEST_P(Imgcodecs_Image, read_write) |
||||
{ |
||||
const string ext = this->GetParam(); |
||||
const string full_name = cv::tempfile(ext.c_str()); |
||||
const string _name = TS::ptr()->get_data_path() + "../cv/shared/baboon.png"; |
||||
const double thresDbell = 32; |
||||
|
||||
Mat image = imread(_name); |
||||
image.convertTo(image, CV_8UC3); |
||||
ASSERT_FALSE(image.empty()); |
||||
|
||||
imwrite(full_name, image); |
||||
Mat loaded = imread(full_name); |
||||
ASSERT_FALSE(loaded.empty()); |
||||
|
||||
double psnr = cvtest::PSNR(loaded, image); |
||||
EXPECT_GT(psnr, thresDbell); |
||||
|
||||
vector<uchar> from_file; |
||||
FILE *f = fopen(full_name.c_str(), "rb"); |
||||
fseek(f, 0, SEEK_END); |
||||
long len = ftell(f); |
||||
from_file.resize((size_t)len); |
||||
fseek(f, 0, SEEK_SET); |
||||
from_file.resize(fread(&from_file[0], 1, from_file.size(), f)); |
||||
fclose(f); |
||||
vector<uchar> buf; |
||||
imencode("." + ext, image, buf); |
||||
ASSERT_EQ(buf, from_file); |
||||
|
||||
Mat buf_loaded = imdecode(Mat(buf), 1); |
||||
ASSERT_FALSE(buf_loaded.empty()); |
||||
|
||||
psnr = cvtest::PSNR(buf_loaded, image); |
||||
EXPECT_GT(psnr, thresDbell); |
||||
|
||||
remove(full_name.c_str()); |
||||
} |
||||
|
||||
const string exts[] = { |
||||
#ifdef HAVE_PNG |
||||
"png", |
||||
#endif |
||||
#ifdef HAVE_TIFF |
||||
"tiff", |
||||
#endif |
||||
#ifdef HAVE_JPEG |
||||
"jpg", |
||||
#endif |
||||
#ifdef HAVE_JASPER |
||||
"jp2", |
||||
#endif |
||||
#if 0 /*defined HAVE_OPENEXR && !defined __APPLE__*/
|
||||
"exr", |
||||
#endif |
||||
"bmp", |
||||
"ppm", |
||||
"ras" |
||||
}; |
||||
|
||||
INSTANTIATE_TEST_CASE_P(imgcodecs, Imgcodecs_Image, testing::ValuesIn(exts)); |
@ -0,0 +1,202 @@ |
||||
#include "test_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
using namespace std::tr1; |
||||
|
||||
#ifdef HAVE_TIFF |
||||
|
||||
// these defines are used to resolve conflict between tiff.h and opencv2/core/types_c.h
|
||||
#define uint64 uint64_hack_ |
||||
#define int64 int64_hack_ |
||||
#include "tiff.h" |
||||
|
||||
#ifdef ANDROID |
||||
// Test disabled as it uses a lot of memory.
|
||||
// It is killed with SIGKILL by out of memory killer.
|
||||
TEST(Imgcodecs_Tiff, DISABLED_decode_tile16384x16384) |
||||
#else |
||||
TEST(Imgcodecs_Tiff, decode_tile16384x16384) |
||||
#endif |
||||
{ |
||||
// see issue #2161
|
||||
cv::Mat big(16384, 16384, CV_8UC1, cv::Scalar::all(0)); |
||||
string file3 = cv::tempfile(".tiff"); |
||||
string file4 = cv::tempfile(".tiff"); |
||||
|
||||
std::vector<int> params; |
||||
params.push_back(TIFFTAG_ROWSPERSTRIP); |
||||
params.push_back(big.rows); |
||||
EXPECT_NO_THROW(cv::imwrite(file4, big, params)); |
||||
EXPECT_NO_THROW(cv::imwrite(file3, big.colRange(0, big.cols - 1), params)); |
||||
big.release(); |
||||
|
||||
try |
||||
{ |
||||
cv::imread(file3, IMREAD_UNCHANGED); |
||||
EXPECT_NO_THROW(cv::imread(file4, IMREAD_UNCHANGED)); |
||||
} |
||||
catch(const std::bad_alloc&) |
||||
{ |
||||
// not enough memory
|
||||
} |
||||
|
||||
remove(file3.c_str()); |
||||
remove(file4.c_str()); |
||||
} |
||||
|
||||
TEST(Imgcodecs_Tiff, write_read_16bit_big_little_endian) |
||||
{ |
||||
// see issue #2601 "16-bit Grayscale TIFF Load Failures Due to Buffer Underflow and Endianness"
|
||||
|
||||
// Setup data for two minimal 16-bit grayscale TIFF files in both endian formats
|
||||
uchar tiff_sample_data[2][86] = { { |
||||
// Little endian
|
||||
0x49, 0x49, 0x2a, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xad, 0xde, 0xef, 0xbe, 0x06, 0x00, 0x00, 0x01, |
||||
0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x00, 0x01, 0x00, |
||||
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, |
||||
0x00, 0x00, 0x06, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, |
||||
0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x17, 0x01, 0x04, 0x00, 0x01, 0x00, |
||||
0x00, 0x00, 0x04, 0x00, 0x00, 0x00 }, { |
||||
// Big endian
|
||||
0x4d, 0x4d, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x0c, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x06, 0x01, 0x00, |
||||
0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x00, |
||||
0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, |
||||
0x00, 0x00, 0x01, 0x06, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x11, |
||||
0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x17, 0x00, 0x04, 0x00, 0x00, |
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x04 } |
||||
}; |
||||
|
||||
// Test imread() for both a little endian TIFF and big endian TIFF
|
||||
for (int i = 0; i < 2; i++) |
||||
{ |
||||
string filename = cv::tempfile(".tiff"); |
||||
|
||||
// Write sample TIFF file
|
||||
FILE* fp = fopen(filename.c_str(), "wb"); |
||||
ASSERT_TRUE(fp != NULL); |
||||
ASSERT_EQ((size_t)1, fwrite(tiff_sample_data, 86, 1, fp)); |
||||
fclose(fp); |
||||
|
||||
Mat img = imread(filename, IMREAD_UNCHANGED); |
||||
|
||||
EXPECT_EQ(1, img.rows); |
||||
EXPECT_EQ(2, img.cols); |
||||
EXPECT_EQ(CV_16U, img.type()); |
||||
EXPECT_EQ(sizeof(ushort), img.elemSize()); |
||||
EXPECT_EQ(1, img.channels()); |
||||
EXPECT_EQ(0xDEAD, img.at<ushort>(0,0)); |
||||
EXPECT_EQ(0xBEEF, img.at<ushort>(0,1)); |
||||
|
||||
remove(filename.c_str()); |
||||
} |
||||
} |
||||
|
||||
TEST(Imgcodecs_Tiff, decode_tile_remainder) |
||||
{ |
||||
/* see issue #3472 - dealing with tiled images where the tile size is
|
||||
* not a multiple of image size. |
||||
* The tiled images were created with 'convert' from ImageMagick, |
||||
* using the command 'convert <input> -define tiff:tile-geometry=128x128 -depth [8|16] <output> |
||||
* Note that the conversion to 16 bits expands the range from 0-255 to 0-255*255, |
||||
* so the test converts back but rounding errors cause small differences. |
||||
*/ |
||||
const string root = cvtest::TS::ptr()->get_data_path(); |
||||
cv::Mat img = imread(root + "readwrite/non_tiled.tif",-1); |
||||
ASSERT_FALSE(img.empty()); |
||||
ASSERT_TRUE(img.channels() == 3); |
||||
cv::Mat tiled8 = imread(root + "readwrite/tiled_8.tif", -1); |
||||
ASSERT_FALSE(tiled8.empty()); |
||||
ASSERT_PRED_FORMAT2(cvtest::MatComparator(0, 0), img, tiled8); |
||||
cv::Mat tiled16 = imread(root + "readwrite/tiled_16.tif", -1); |
||||
ASSERT_FALSE(tiled16.empty()); |
||||
ASSERT_TRUE(tiled16.elemSize() == 6); |
||||
tiled16.convertTo(tiled8, CV_8UC3, 1./256.); |
||||
ASSERT_PRED_FORMAT2(cvtest::MatComparator(2, 0), img, tiled8); |
||||
// What about 32, 64 bit?
|
||||
} |
||||
|
||||
TEST(Imgcodecs_Tiff, decode_infinite_rowsperstrip) |
||||
{ |
||||
const uchar sample_data[142] = { |
||||
0x49, 0x49, 0x2a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x56, 0x54, |
||||
0x56, 0x5a, 0x59, 0x55, 0x5a, 0x00, 0x0a, 0x00, 0x00, 0x01, |
||||
0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, |
||||
0x01, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, |
||||
0x00, 0x00, 0x02, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, |
||||
0x08, 0x00, 0x00, 0x00, 0x03, 0x01, 0x03, 0x00, 0x01, 0x00, |
||||
0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x01, 0x03, 0x00, |
||||
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01, |
||||
0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, |
||||
0x15, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, |
||||
0x00, 0x00, 0x16, 0x01, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, |
||||
0xff, 0xff, 0xff, 0xff, 0x17, 0x01, 0x04, 0x00, 0x01, 0x00, |
||||
0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x1c, 0x01, 0x03, 0x00, |
||||
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00 |
||||
}; |
||||
|
||||
const string filename = cv::tempfile(".tiff"); |
||||
std::ofstream outfile(filename.c_str(), std::ofstream::binary); |
||||
outfile.write(reinterpret_cast<const char *>(sample_data), sizeof sample_data); |
||||
outfile.close(); |
||||
|
||||
EXPECT_NO_THROW(cv::imread(filename, IMREAD_UNCHANGED)); |
||||
|
||||
remove(filename.c_str()); |
||||
} |
||||
|
||||
//==================================================================================================
|
||||
|
||||
typedef testing::TestWithParam<int> Imgcodecs_Tiff_Modes; |
||||
|
||||
TEST_P(Imgcodecs_Tiff_Modes, decode_multipage) |
||||
{ |
||||
const int mode = GetParam(); |
||||
const string root = cvtest::TS::ptr()->get_data_path(); |
||||
const string filename = root + "readwrite/multipage.tif"; |
||||
const string page_files[] = { |
||||
"readwrite/multipage_p1.tif", |
||||
"readwrite/multipage_p2.tif", |
||||
"readwrite/multipage_p3.tif", |
||||
"readwrite/multipage_p4.tif", |
||||
"readwrite/multipage_p5.tif", |
||||
"readwrite/multipage_p6.tif" |
||||
}; |
||||
const size_t page_count = sizeof(page_files)/sizeof(page_files[0]); |
||||
vector<Mat> pages; |
||||
bool res = imreadmulti(filename, pages, mode); |
||||
ASSERT_TRUE(res == true); |
||||
ASSERT_EQ(page_count, pages.size()); |
||||
for (size_t i = 0; i < page_count; i++) |
||||
{ |
||||
const Mat page = imread(root + page_files[i], mode); |
||||
EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), page, pages[i]); |
||||
} |
||||
} |
||||
|
||||
const int all_modes[] = |
||||
{ |
||||
IMREAD_UNCHANGED, |
||||
IMREAD_GRAYSCALE, |
||||
IMREAD_COLOR, |
||||
IMREAD_ANYDEPTH, |
||||
IMREAD_ANYCOLOR |
||||
}; |
||||
|
||||
INSTANTIATE_TEST_CASE_P(AllModes, Imgcodecs_Tiff_Modes, testing::ValuesIn(all_modes)); |
||||
|
||||
//==================================================================================================
|
||||
|
||||
TEST(Imgcodecs_Tiff, imdecode_no_exception_temporary_file_removed) |
||||
{ |
||||
const string root = cvtest::TS::ptr()->get_data_path(); |
||||
const string filename = root + "../cv/shared/lena.png"; |
||||
cv::Mat img = cv::imread(filename); |
||||
ASSERT_FALSE(img.empty()); |
||||
std::vector<uchar> buf; |
||||
EXPECT_NO_THROW(cv::imencode(".tiff", img, buf)); |
||||
EXPECT_NO_THROW(cv::imdecode(buf, IMREAD_UNCHANGED)); |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,106 @@ |
||||
#include "test_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
using namespace std::tr1; |
||||
|
||||
#ifdef HAVE_WEBP |
||||
|
||||
TEST(Imgcodecs_WebP, encode_decode_lossless_webp) |
||||
{ |
||||
const string root = cvtest::TS::ptr()->get_data_path(); |
||||
string filename = root + "../cv/shared/lena.png"; |
||||
cv::Mat img = cv::imread(filename); |
||||
ASSERT_FALSE(img.empty()); |
||||
|
||||
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); |
||||
} |
||||
} |
||||
|
||||
remove(output.c_str()); |
||||
|
||||
cv::Mat decode = cv::imdecode(buf, IMREAD_COLOR); |
||||
ASSERT_FALSE(decode.empty()); |
||||
EXPECT_TRUE(cvtest::norm(decode, img_webp, NORM_INF) == 0); |
||||
|
||||
ASSERT_FALSE(img_webp.empty()); |
||||
|
||||
EXPECT_TRUE(cvtest::norm(img, img_webp, NORM_INF) == 0); |
||||
} |
||||
|
||||
TEST(Imgcodecs_WebP, encode_decode_lossy_webp) |
||||
{ |
||||
const string root = cvtest::TS::ptr()->get_data_path(); |
||||
std::string input = root + "../cv/shared/lena.png"; |
||||
cv::Mat img = cv::imread(input); |
||||
ASSERT_FALSE(img.empty()); |
||||
|
||||
for(int q = 100; q>=0; q-=20) |
||||
{ |
||||
std::vector<int> params; |
||||
params.push_back(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); |
||||
remove(output.c_str()); |
||||
EXPECT_FALSE(img_webp.empty()); |
||||
EXPECT_EQ(3, img_webp.channels()); |
||||
EXPECT_EQ(512, img_webp.cols); |
||||
EXPECT_EQ(512, img_webp.rows); |
||||
} |
||||
} |
||||
|
||||
TEST(Imgcodecs_WebP, encode_decode_with_alpha_webp) |
||||
{ |
||||
const string root = cvtest::TS::ptr()->get_data_path(); |
||||
std::string input = root + "../cv/shared/lena.png"; |
||||
cv::Mat img = cv::imread(input); |
||||
ASSERT_FALSE(img.empty()); |
||||
|
||||
std::vector<cv::Mat> imgs; |
||||
cv::split(img, imgs); |
||||
imgs.push_back(cv::Mat(imgs[0])); |
||||
imgs[imgs.size() - 1] = cv::Scalar::all(128); |
||||
cv::merge(imgs, img); |
||||
|
||||
string output = cv::tempfile(".webp"); |
||||
|
||||
EXPECT_NO_THROW(cv::imwrite(output, img)); |
||||
cv::Mat img_webp = cv::imread(output); |
||||
remove(output.c_str()); |
||||
EXPECT_FALSE(img_webp.empty()); |
||||
EXPECT_EQ(4, img_webp.channels()); |
||||
EXPECT_EQ(512, img_webp.cols); |
||||
EXPECT_EQ(512, img_webp.rows); |
||||
} |
||||
|
||||
#endif // HAVE_WEBP
|
@ -1,157 +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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., 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 the copyright holders 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/videoio.hpp" |
||||
#include "opencv2/ts.hpp" |
||||
#include <stdio.h> |
||||
|
||||
#if BUILD_WITH_VIDEO_INPUT_SUPPORT |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
using namespace cvtest; |
||||
|
||||
#ifdef HAVE_GSTREAMER |
||||
const string ext[] = {"avi"}; |
||||
#else |
||||
const string ext[] = {"avi", "mov", "mp4"}; |
||||
#endif |
||||
|
||||
TEST(Videoio_Video, prop_resolution) |
||||
{ |
||||
const size_t n = sizeof(ext)/sizeof(ext[0]); |
||||
const string src_dir = TS::ptr()->get_data_path(); |
||||
|
||||
TS::ptr()->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str()); |
||||
|
||||
for (size_t i = 0; i < n; ++i) |
||||
{ |
||||
string file_path = src_dir+"video/big_buck_bunny."+ext[i]; |
||||
VideoCapture cap(file_path); |
||||
if (!cap.isOpened()) |
||||
{ |
||||
TS::ptr()->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str()); |
||||
TS::ptr()->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n"); |
||||
TS::ptr()->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
|
||||
ASSERT_EQ(672, cap.get(CAP_PROP_FRAME_WIDTH)); |
||||
ASSERT_EQ(384, cap.get(CAP_PROP_FRAME_HEIGHT)); |
||||
} |
||||
} |
||||
|
||||
TEST(Videoio_Video, actual_resolution) |
||||
{ |
||||
const size_t n = sizeof(ext)/sizeof(ext[0]); |
||||
const string src_dir = TS::ptr()->get_data_path(); |
||||
|
||||
TS::ptr()->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str()); |
||||
|
||||
for (size_t i = 0; i < n; ++i) |
||||
{ |
||||
string file_path = src_dir+"video/big_buck_bunny."+ext[i]; |
||||
VideoCapture cap(file_path); |
||||
if (!cap.isOpened()) |
||||
{ |
||||
TS::ptr()->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str()); |
||||
TS::ptr()->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n"); |
||||
TS::ptr()->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
|
||||
Mat frame; |
||||
cap >> frame; |
||||
|
||||
ASSERT_EQ(672, frame.cols); |
||||
ASSERT_EQ(384, frame.rows); |
||||
} |
||||
} |
||||
|
||||
TEST(Videoio_Video, DISABLED_prop_fps) |
||||
{ |
||||
const size_t n = sizeof(ext)/sizeof(ext[0]); |
||||
const string src_dir = TS::ptr()->get_data_path(); |
||||
|
||||
TS::ptr()->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str()); |
||||
|
||||
for (size_t i = 0; i < n; ++i) |
||||
{ |
||||
string file_path = src_dir+"video/big_buck_bunny."+ext[i]; |
||||
VideoCapture cap(file_path); |
||||
if (!cap.isOpened()) |
||||
{ |
||||
TS::ptr()->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str()); |
||||
TS::ptr()->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n"); |
||||
TS::ptr()->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
|
||||
ASSERT_EQ(24, cap.get(CAP_PROP_FPS)); |
||||
} |
||||
} |
||||
|
||||
TEST(Videoio_Video, prop_framecount) |
||||
{ |
||||
const size_t n = sizeof(ext)/sizeof(ext[0]); |
||||
const string src_dir = TS::ptr()->get_data_path(); |
||||
|
||||
TS::ptr()->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str()); |
||||
|
||||
for (size_t i = 0; i < n; ++i) |
||||
{ |
||||
string file_path = src_dir+"video/big_buck_bunny."+ext[i]; |
||||
VideoCapture cap(file_path); |
||||
if (!cap.isOpened()) |
||||
{ |
||||
TS::ptr()->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str()); |
||||
TS::ptr()->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n"); |
||||
TS::ptr()->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
|
||||
ASSERT_EQ(125, cap.get(CAP_PROP_FRAME_COUNT)); |
||||
} |
||||
} |
||||
|
||||
#endif |
@ -1,114 +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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., 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 the copyright holders 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/videoio/videoio_c.h" |
||||
#include <stdio.h> |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
|
||||
class CV_FramecountTest: public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
void run(int); |
||||
}; |
||||
|
||||
void CV_FramecountTest::run(int) |
||||
{ |
||||
const int time_sec = 5, fps = 25; |
||||
|
||||
const string ext[] = {"avi", "mov", "mp4"}; |
||||
|
||||
const size_t n = sizeof(ext)/sizeof(ext[0]); |
||||
|
||||
const string src_dir = ts->get_data_path(); |
||||
|
||||
ts->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str()); |
||||
|
||||
Ptr<CvCapture> cap; |
||||
|
||||
for (size_t i = 0; i < n; ++i) |
||||
{ |
||||
string file_path = src_dir+"video/big_buck_bunny."+ext[i]; |
||||
|
||||
cap.reset(cvCreateFileCapture(file_path.c_str())); |
||||
if (!cap) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str()); |
||||
ts->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
|
||||
//cvSetCaptureProperty(cap, CV_CAP_PROP_POS_FRAMES, 0);
|
||||
IplImage* frame; int FrameCount = 0; |
||||
|
||||
for(;;) |
||||
{ |
||||
frame = cvQueryFrame(cap); |
||||
if( !frame ) |
||||
break; |
||||
FrameCount++; |
||||
} |
||||
|
||||
int framecount = (int)cvGetCaptureProperty(cap, CAP_PROP_FRAME_COUNT); |
||||
|
||||
ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n"\
|
||||
"\nName: big_buck_bunny.%s\nActual frame count: %d\n"\
|
||||
"Frame count computed in the cycle of queries of frames: %d\n"\
|
||||
"Frame count returned by cvGetCaptureProperty function: %d\n", |
||||
i+1, ext[i].c_str(), time_sec*fps, FrameCount, framecount); |
||||
|
||||
if( (FrameCount != cvRound(time_sec*fps) || |
||||
FrameCount != framecount) && ext[i] != "mpg" ) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "FAILED\n"); |
||||
ts->printf(cvtest::TS::LOG, "\nError: actual frame count and returned frame count are not matched.\n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
#if BUILD_WITH_VIDEO_INPUT_SUPPORT && defined HAVE_FFMPEG |
||||
TEST(Videoio_Video, framecount) {CV_FramecountTest test; test.safe_run();} |
||||
#endif |
@ -1,223 +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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., 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 the copyright holders 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/videoio/videoio_c.h" |
||||
#include <stdio.h> |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
|
||||
class CV_VideoPositioningTest: public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
enum {PROGRESSIVE, RANDOM}; |
||||
|
||||
CV_VideoPositioningTest(); |
||||
~CV_VideoPositioningTest(); |
||||
virtual void run(int) = 0; |
||||
|
||||
protected: |
||||
vector <int> idx; |
||||
void run_test(int method); |
||||
|
||||
private: |
||||
void generate_idx_seq(CvCapture *cap, int method); |
||||
}; |
||||
|
||||
class CV_VideoProgressivePositioningTest: public CV_VideoPositioningTest |
||||
{ |
||||
public: |
||||
CV_VideoProgressivePositioningTest() : CV_VideoPositioningTest() { } |
||||
~CV_VideoProgressivePositioningTest(); |
||||
void run(int); |
||||
}; |
||||
|
||||
class CV_VideoRandomPositioningTest: public CV_VideoPositioningTest |
||||
{ |
||||
public: |
||||
CV_VideoRandomPositioningTest(): CV_VideoPositioningTest() { } |
||||
~CV_VideoRandomPositioningTest(); |
||||
void run(int); |
||||
}; |
||||
|
||||
CV_VideoPositioningTest::CV_VideoPositioningTest() {} |
||||
CV_VideoPositioningTest::~CV_VideoPositioningTest() {} |
||||
CV_VideoProgressivePositioningTest::~CV_VideoProgressivePositioningTest() {} |
||||
CV_VideoRandomPositioningTest::~CV_VideoRandomPositioningTest() {} |
||||
|
||||
void CV_VideoPositioningTest::generate_idx_seq(CvCapture* cap, int method) |
||||
{ |
||||
idx.clear(); |
||||
int N = (int)cvGetCaptureProperty(cap, CAP_PROP_FRAME_COUNT); |
||||
switch(method) |
||||
{ |
||||
case PROGRESSIVE: |
||||
{ |
||||
int pos = 1, step = 20; |
||||
do |
||||
{ |
||||
idx.push_back(pos); |
||||
pos += step; |
||||
} |
||||
while (pos <= N); |
||||
break; |
||||
} |
||||
case RANDOM: |
||||
{ |
||||
RNG rng(N); |
||||
idx.clear(); |
||||
for( int i = 0; i >= 0 && i < N-1; i++ ) |
||||
idx.push_back(rng.uniform(0, N)); |
||||
idx.push_back(N-1); |
||||
std::swap(idx.at(rng.uniform(0, N-1)), idx.at(N-1)); |
||||
break; |
||||
} |
||||
default:break; |
||||
} |
||||
} |
||||
|
||||
void CV_VideoPositioningTest::run_test(int method) |
||||
{ |
||||
const string& src_dir = ts->get_data_path(); |
||||
|
||||
ts->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str()); |
||||
|
||||
const string ext[] = {"avi", "mov", "mp4", "mpg"}; |
||||
|
||||
int n = (int)(sizeof(ext)/sizeof(ext[0])); |
||||
|
||||
int failed_videos = 0; |
||||
|
||||
for (int i = 0; i < n; ++i) |
||||
{ |
||||
// skip random positioning test in plain mpegs
|
||||
if( method == RANDOM && ext[i] == "mpg" ) |
||||
continue; |
||||
string file_path = src_dir + "video/big_buck_bunny." + ext[i]; |
||||
|
||||
ts->printf(cvtest::TS::LOG, "\nReading video file in %s...\n", file_path.c_str()); |
||||
|
||||
CvCapture* cap = cvCreateFileCapture(file_path.c_str()); |
||||
|
||||
if (!cap) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str()); |
||||
ts->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); |
||||
failed_videos++; continue; |
||||
} |
||||
|
||||
cvSetCaptureProperty(cap, CAP_PROP_POS_FRAMES, 0); |
||||
|
||||
generate_idx_seq(cap, method); |
||||
|
||||
int N = (int)idx.size(), failed_frames = 0, failed_positions = 0, failed_iterations = 0; |
||||
|
||||
for (int j = 0; j < N; ++j) |
||||
{ |
||||
bool flag = false; |
||||
|
||||
cvSetCaptureProperty(cap, CAP_PROP_POS_FRAMES, idx.at(j)); |
||||
|
||||
/* IplImage* frame = cvRetrieveFrame(cap);
|
||||
|
||||
if (!frame) |
||||
{ |
||||
if (!failed_frames) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\n", i+1, ext[i].c_str()); |
||||
} |
||||
failed_frames++; |
||||
ts->printf(cvtest::TS::LOG, "\nIteration: %d\n\nError: cannot read a frame with index %d.\n", j, idx.at(j)); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION); |
||||
flag = !flag; |
||||
} */ |
||||
|
||||
int val = (int)cvGetCaptureProperty(cap, CAP_PROP_POS_FRAMES); |
||||
|
||||
if (idx.at(j) != val) |
||||
{ |
||||
if (!(failed_frames||failed_positions)) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\n", i+1, ext[i].c_str()); |
||||
} |
||||
failed_positions++; |
||||
if (!failed_frames) |
||||
{ |
||||
ts->printf(cvtest::TS::LOG, "\nIteration: %d\n", j); |
||||
} |
||||
ts->printf(cvtest::TS::LOG, "Required pos: %d\nReturned pos: %d\n", idx.at(j), val); |
||||
ts->printf(cvtest::TS::LOG, "Error: required and returned positions are not matched.\n"); |
||||
ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT); |
||||
flag = true; |
||||
} |
||||
|
||||
if (flag) |
||||
{ |
||||
failed_iterations++; |
||||
failed_videos++; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
cvReleaseCapture(&cap); |
||||
} |
||||
|
||||
ts->printf(cvtest::TS::LOG, "\nSuccessfull experiments: %d (%d%%)\n", n-failed_videos, 100*(n-failed_videos)/n); |
||||
ts->printf(cvtest::TS::LOG, "Failed experiments: %d (%d%%)\n", failed_videos, 100*failed_videos/n); |
||||
} |
||||
|
||||
void CV_VideoProgressivePositioningTest::run(int) |
||||
{ |
||||
run_test(PROGRESSIVE); |
||||
} |
||||
|
||||
void CV_VideoRandomPositioningTest::run(int) |
||||
{ |
||||
run_test(RANDOM); |
||||
} |
||||
|
||||
#if BUILD_WITH_VIDEO_INPUT_SUPPORT && defined HAVE_FFMPEG |
||||
TEST (Videoio_Video, seek_progressive) { CV_VideoProgressivePositioningTest test; test.safe_run(); } |
||||
TEST (Videoio_Video, seek_random) { CV_VideoRandomPositioningTest test; test.safe_run(); } |
||||
#endif |
@ -1,179 +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.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., 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 the copyright holders 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/videoio.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
|
||||
class CV_PositioningTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
CV_PositioningTest() |
||||
{ |
||||
framesize = Size(640, 480); |
||||
} |
||||
|
||||
Mat drawFrame(int i) |
||||
{ |
||||
Mat mat = Mat::zeros(framesize, CV_8UC3); |
||||
|
||||
mat = Scalar(fabs(cos(i*0.08)*255), fabs(sin(i*0.05)*255), i); |
||||
putText(mat, format("%03d", i), Point(10, 350), 0, 10, Scalar(128, 255, 255), 15); |
||||
return mat; |
||||
} |
||||
|
||||
string getFilename(const cvtest::VideoFormat& fmt) |
||||
{ |
||||
return cv::tempfile((cvtest::fourccToString(fmt.fourcc) + "." + fmt.ext).c_str()); |
||||
} |
||||
|
||||
bool CreateTestVideo(const cvtest::VideoFormat& fmt, int framecount, string filename) |
||||
{ |
||||
VideoWriter writer(filename, fmt.fourcc, 25, framesize, true); |
||||
if( !writer.isOpened() ) |
||||
return false; |
||||
|
||||
for (int i = 0; i < framecount; ++i) |
||||
{ |
||||
Mat img = drawFrame(i); |
||||
writer << img; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
void run(int) |
||||
{ |
||||
int n_frames = 100; |
||||
|
||||
for( int testcase = 0; ; testcase++ ) |
||||
{ |
||||
const cvtest::VideoFormat& fmt = cvtest::g_specific_fmt_list[testcase]; |
||||
if( fmt.empty() ) |
||||
break; |
||||
string filename = getFilename(fmt); |
||||
ts->printf(ts->LOG, "\nFile: %s\n", filename.c_str()); |
||||
|
||||
if( !CreateTestVideo(fmt, n_frames, filename) ) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: cannot create video file"); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
|
||||
VideoCapture cap(filename); |
||||
|
||||
if (!cap.isOpened()) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: cannot read video file."); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
|
||||
int N0 = (int)cap.get(CAP_PROP_FRAME_COUNT); |
||||
cap.set(CAP_PROP_POS_FRAMES, 0); |
||||
int N = (int)cap.get(CAP_PROP_FRAME_COUNT); |
||||
|
||||
// See the same hack in CV_VideoIOTest::SpecificVideoTest for explanation.
|
||||
int allowed_extra_frames = 0; |
||||
if (fmt.fourcc == VideoWriter::fourcc('M', 'P', 'E', 'G') && fmt.ext == "mkv") |
||||
allowed_extra_frames = 1; |
||||
|
||||
if (N < n_frames || N > n_frames + allowed_extra_frames || N != N0) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: returned frame count (N0=%d, N=%d) is different from the reference number %d\n", N0, N, n_frames); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
|
||||
for (int k = 0; k < n_frames; ++k) |
||||
{ |
||||
int idx = theRNG().uniform(0, n_frames); |
||||
|
||||
if( !cap.set(CAP_PROP_POS_FRAMES, idx) ) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: cannot seek to frame %d.\n", idx); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
|
||||
int idx1 = (int)cap.get(CAP_PROP_POS_FRAMES); |
||||
|
||||
Mat img; cap >> img; |
||||
Mat img0 = drawFrame(idx); |
||||
|
||||
if( idx != idx1 ) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: the current position (%d) after seek is different from specified (%d)\n", |
||||
idx1, idx); |
||||
ts->printf(ts->LOG, "Saving both frames ...\n"); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
|
||||
if (img.empty()) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: cannot read a frame at position %d.\n", idx); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
|
||||
double err = cvtest::PSNR(img, img0); |
||||
|
||||
if( err < 20 ) |
||||
{ |
||||
ts->printf(ts->LOG, "The frame read after positioning to %d is incorrect (PSNR=%g)\n", idx, err); |
||||
ts->printf(ts->LOG, "Saving both frames ...\n"); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
Size framesize; |
||||
}; |
||||
|
||||
#if BUILD_WITH_VIDEO_INPUT_SUPPORT && BUILD_WITH_VIDEO_OUTPUT_SUPPORT && defined HAVE_FFMPEG |
||||
TEST(Videoio_Video, seek_random_synthetic) { CV_PositioningTest test; test.safe_run(); } |
||||
#endif |
Loading…
Reference in new issue