Path: blob/master/modules/videoio/test/test_gstreamer.cpp
16344 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.34#include "test_precomp.hpp"5#ifdef HAVE_GSTREAMER67namespace opencv_test8{910typedef tuple< string, Size, Size, int > Param;11typedef testing::TestWithParam< Param > Videoio_Gstreamer_Test;1213TEST_P(Videoio_Gstreamer_Test, test_object_structure)14{15string format = get<0>(GetParam());16Size frame_size = get<1>(GetParam());17Size mat_size = get<2>(GetParam());18int convertToRGB = get<3>(GetParam());19int count_frames = 10;20std::ostringstream pipeline;21pipeline << "videotestsrc pattern=ball num-buffers=" << count_frames << " ! " << format;22pipeline << ", width=" << frame_size.width << ", height=" << frame_size.height << " ! appsink";23VideoCapture cap;24ASSERT_NO_THROW(cap.open(pipeline.str(), CAP_GSTREAMER));25ASSERT_TRUE(cap.isOpened());2627Mat buffer, decode_frame, gray_frame, rgb_frame;28for (int i = 0; i < count_frames; ++i)29{30cap >> buffer;31decode_frame = (format == "jpegenc ! image/jpeg") ? imdecode(buffer, IMREAD_UNCHANGED) : buffer;32EXPECT_EQ(mat_size, decode_frame.size());3334cvtColor(decode_frame, rgb_frame, convertToRGB);35cvtColor(rgb_frame, gray_frame, COLOR_RGB2GRAY);3637vector<Vec3f> circles;38HoughCircles(gray_frame, circles, HOUGH_GRADIENT, 1, gray_frame.rows/16, 100, 30, 1, 30 );39if (circles.size() == 1)40{41EXPECT_NEAR(18.5, circles[0][2], 1.0);42}43else44{45ADD_FAILURE() << "Found " << circles.size() << " on frame " << i ;46}47}48{49Mat frame;50cap >> frame;51EXPECT_TRUE(frame.empty());52}53cap.release();54ASSERT_FALSE(cap.isOpened());55}5657Param test_data[] = {58make_tuple("video/x-raw, format=BGR" , Size(640, 480), Size(640, 480), COLOR_BGR2RGB),59make_tuple("video/x-raw, format=GRAY8", Size(640, 480), Size(640, 480), COLOR_GRAY2RGB),60make_tuple("video/x-raw, format=UYVY" , Size(640, 480), Size(640, 480), COLOR_YUV2RGB_UYVY),61make_tuple("video/x-raw, format=YUY2" , Size(640, 480), Size(640, 480), COLOR_YUV2RGB_YUY2),62make_tuple("video/x-raw, format=YVYU" , Size(640, 480), Size(640, 480), COLOR_YUV2RGB_YVYU),63make_tuple("video/x-raw, format=NV12" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_NV12),64make_tuple("video/x-raw, format=NV21" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_NV21),65make_tuple("video/x-raw, format=YV12" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_YV12),66make_tuple("video/x-raw, format=I420" , Size(640, 480), Size(640, 720), COLOR_YUV2RGB_I420),67make_tuple("video/x-bayer" , Size(640, 480), Size(640, 480), COLOR_BayerBG2RGB),68make_tuple("jpegenc ! image/jpeg" , Size(640, 480), Size(640, 480), COLOR_BGR2RGB)69};7071INSTANTIATE_TEST_CASE_P(videoio, Videoio_Gstreamer_Test, testing::ValuesIn(test_data));7273} // namespace7475#endif767778