Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/videoio/test/test_gstreamer.cpp
16344 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
5
#include "test_precomp.hpp"
6
#ifdef HAVE_GSTREAMER
7
8
namespace opencv_test
9
{
10
11
typedef tuple< string, Size, Size, int > Param;
12
typedef testing::TestWithParam< Param > Videoio_Gstreamer_Test;
13
14
TEST_P(Videoio_Gstreamer_Test, test_object_structure)
15
{
16
string format = get<0>(GetParam());
17
Size frame_size = get<1>(GetParam());
18
Size mat_size = get<2>(GetParam());
19
int convertToRGB = get<3>(GetParam());
20
int count_frames = 10;
21
std::ostringstream pipeline;
22
pipeline << "videotestsrc pattern=ball num-buffers=" << count_frames << " ! " << format;
23
pipeline << ", width=" << frame_size.width << ", height=" << frame_size.height << " ! appsink";
24
VideoCapture cap;
25
ASSERT_NO_THROW(cap.open(pipeline.str(), CAP_GSTREAMER));
26
ASSERT_TRUE(cap.isOpened());
27
28
Mat buffer, decode_frame, gray_frame, rgb_frame;
29
for (int i = 0; i < count_frames; ++i)
30
{
31
cap >> buffer;
32
decode_frame = (format == "jpegenc ! image/jpeg") ? imdecode(buffer, IMREAD_UNCHANGED) : buffer;
33
EXPECT_EQ(mat_size, decode_frame.size());
34
35
cvtColor(decode_frame, rgb_frame, convertToRGB);
36
cvtColor(rgb_frame, gray_frame, COLOR_RGB2GRAY);
37
38
vector<Vec3f> circles;
39
HoughCircles(gray_frame, circles, HOUGH_GRADIENT, 1, gray_frame.rows/16, 100, 30, 1, 30 );
40
if (circles.size() == 1)
41
{
42
EXPECT_NEAR(18.5, circles[0][2], 1.0);
43
}
44
else
45
{
46
ADD_FAILURE() << "Found " << circles.size() << " on frame " << i ;
47
}
48
}
49
{
50
Mat frame;
51
cap >> frame;
52
EXPECT_TRUE(frame.empty());
53
}
54
cap.release();
55
ASSERT_FALSE(cap.isOpened());
56
}
57
58
Param test_data[] = {
59
make_tuple("video/x-raw, format=BGR" , Size(640, 480), Size(640, 480), COLOR_BGR2RGB),
60
make_tuple("video/x-raw, format=GRAY8", Size(640, 480), Size(640, 480), COLOR_GRAY2RGB),
61
make_tuple("video/x-raw, format=UYVY" , Size(640, 480), Size(640, 480), COLOR_YUV2RGB_UYVY),
62
make_tuple("video/x-raw, format=YUY2" , Size(640, 480), Size(640, 480), COLOR_YUV2RGB_YUY2),
63
make_tuple("video/x-raw, format=YVYU" , Size(640, 480), Size(640, 480), COLOR_YUV2RGB_YVYU),
64
make_tuple("video/x-raw, format=NV12" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_NV12),
65
make_tuple("video/x-raw, format=NV21" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_NV21),
66
make_tuple("video/x-raw, format=YV12" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_YV12),
67
make_tuple("video/x-raw, format=I420" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_I420),
68
make_tuple("video/x-bayer" , Size(640, 480), Size(640, 480), COLOR_BayerBG2RGB),
69
make_tuple("jpegenc ! image/jpeg" , Size(640, 480), Size(640, 480), COLOR_BGR2RGB)
70
};
71
72
INSTANTIATE_TEST_CASE_P(videoio, Videoio_Gstreamer_Test, testing::ValuesIn(test_data));
73
74
} // namespace
75
76
#endif
77
78