@ -58,10 +58,19 @@ PARAM_TEST_CASE(Scaling, cv::cuda::DeviceInfo, std::string, Size2f, Rect2f, Rect
{
} ;
struct DisplayResolution : testing : : TestWithParam < cv : : cuda : : DeviceInfo >
{
} ;
PARAM_TEST_CASE ( Video , cv : : cuda : : DeviceInfo , std : : string )
{
} ;
typedef tuple < std : : string , bool > color_conversion_params_t ;
PARAM_TEST_CASE ( ColorConversion , cv : : cuda : : DeviceInfo , cv : : cudacodec : : ColorFormat , color_conversion_params_t )
{
} ;
PARAM_TEST_CASE ( VideoReadRaw , cv : : cuda : : DeviceInfo , std : : string )
{
} ;
@ -220,7 +229,38 @@ CUDA_TEST_P(Scaling, Reader)
cv : : cuda : : resize ( frameOr ( srcRoiOut ) , frameGs , targetRoiOut . size ( ) , 0 , 0 , INTER_AREA ) ;
// assert on mean absolute error due to different resize algorithms
const double mae = cv : : cuda : : norm ( frameGs , frame ( targetRoiOut ) , NORM_L1 ) / frameGs . size ( ) . area ( ) ;
ASSERT_LT ( mae , 2.35 ) ;
ASSERT_LT ( mae , 2.75 ) ;
}
CUDA_TEST_P ( DisplayResolution , Reader )
{
cv : : cuda : : setDevice ( GetParam ( ) . deviceID ( ) ) ;
std : : string inputFile = std : : string ( cvtest : : TS : : ptr ( ) - > get_data_path ( ) ) + " ../cv/video/1920x1080.avi " ;
const Rect displayArea ( 0 , 0 , 1920 , 1080 ) ;
GpuMat frame ;
{
// verify the output frame is the diplay size (1920x1080) and not the coded size (1920x1088)
cv : : Ptr < cv : : cudacodec : : VideoReader > reader = cv : : cudacodec : : createVideoReader ( inputFile ) ;
reader - > set ( cudacodec : : ColorFormat : : GRAY ) ;
ASSERT_TRUE ( reader - > nextFrame ( frame ) ) ;
const cudacodec : : FormatInfo format = reader - > format ( ) ;
ASSERT_TRUE ( format . displayArea = = displayArea ) ;
ASSERT_TRUE ( frame . size ( ) = = displayArea . size ( ) & & frame . size ( ) = = format . targetSz ) ;
}
{
// extra check to verify display frame has not been post-processed and is just a cropped version of the coded sized frame
cudacodec : : VideoReaderInitParams params ;
params . srcRoi = Rect ( 0 , 0 , 1920 , 1088 ) ;
cv : : Ptr < cv : : cudacodec : : VideoReader > readerCodedSz = cv : : cudacodec : : createVideoReader ( inputFile , { } , params ) ;
readerCodedSz - > set ( cudacodec : : ColorFormat : : GRAY ) ;
GpuMat frameCodedSz ;
ASSERT_TRUE ( readerCodedSz - > nextFrame ( frameCodedSz ) ) ;
const cudacodec : : FormatInfo formatCodedSz = readerCodedSz - > format ( ) ;
const double err = cv : : cuda : : norm ( frame , frameCodedSz ( displayArea ) , NORM_INF ) ;
ASSERT_TRUE ( err = = 0 ) ;
}
}
CUDA_TEST_P ( Video , Reader )
@ -265,6 +305,33 @@ CUDA_TEST_P(Video, Reader)
}
}
CUDA_TEST_P ( ColorConversion , Reader )
{
cv : : cuda : : setDevice ( GET_PARAM ( 0 ) . deviceID ( ) ) ;
const cv : : cudacodec : : ColorFormat colorFormat = GET_PARAM ( 1 ) ;
const std : : string inputFile = std : : string ( cvtest : : TS : : ptr ( ) - > get_data_path ( ) ) + " ../ " + get < 0 > ( GET_PARAM ( 2 ) ) ;
const bool videoFullRangeFlag = get < 1 > ( GET_PARAM ( 2 ) ) ;
cv : : Ptr < cv : : cudacodec : : VideoReader > reader = cv : : cudacodec : : createVideoReader ( inputFile ) ;
reader - > set ( colorFormat ) ;
cv : : VideoCapture cap ( inputFile ) ;
cv : : cuda : : GpuMat frame ;
Mat frameHost , frameHostGs , frameFromDevice ;
for ( int i = 0 ; i < 10 ; i + + )
{
reader - > nextFrame ( frame ) ;
frame . download ( frameFromDevice ) ;
cap . read ( frameHost ) ;
const cv : : cudacodec : : FormatInfo fmt = reader - > format ( ) ;
ASSERT_TRUE ( fmt . valid & & fmt . videoFullRangeFlag = = videoFullRangeFlag ) ;
if ( colorFormat = = cv : : cudacodec : : ColorFormat : : BGRA )
cv : : cvtColor ( frameHost , frameHostGs , COLOR_BGR2BGRA ) ;
else
frameHostGs = frameHost ;
EXPECT_MAT_NEAR ( frameHostGs , frameFromDevice , 2.0 ) ;
}
}
CUDA_TEST_P ( VideoReadRaw , Reader )
{
cv : : cuda : : setDevice ( GET_PARAM ( 0 ) . deviceID ( ) ) ;
@ -664,6 +731,8 @@ INSTANTIATE_TEST_CASE_P(CUDA_Codec, CheckSet, testing::Combine(
INSTANTIATE_TEST_CASE_P ( CUDA_Codec , Scaling , testing : : Combine (
ALL_DEVICES , testing : : Values ( VIDEO_SRC_SCALING ) , testing : : Values ( TARGET_SZ ) , testing : : Values ( SRC_ROI ) , testing : : Values ( TARGET_ROI ) ) ) ;
INSTANTIATE_TEST_CASE_P ( CUDA_Codec , DisplayResolution , ALL_DEVICES ) ;
# define VIDEO_SRC_R "highgui / video / big_buck_bunny.mp4", "cv / video / 768x576.avi", "cv / video / 1920x1080.avi", "highgui / video / big_buck_bunny.avi", \
" highgui/video/big_buck_bunny.h264 " , " highgui/video/big_buck_bunny.h265 " , " highgui/video/big_buck_bunny.mpg " , \
" highgui/video/sample_322x242_15frames.yuv420p.libvpx-vp9.mp4 " , " highgui/video/sample_322x242_15frames.yuv420p.libaom-av1.mp4 " , \
@ -672,6 +741,18 @@ INSTANTIATE_TEST_CASE_P(CUDA_Codec, Video, testing::Combine(
ALL_DEVICES ,
testing : : Values ( VIDEO_SRC_R ) ) ) ;
const color_conversion_params_t color_conversion_params [ ] =
{
color_conversion_params_t ( " highgui/video/big_buck_bunny.h264 " , false ) ,
color_conversion_params_t ( " highgui/video/big_buck_bunny_full_color_range.h264 " , true ) ,
} ;
# define VIDEO_COLOR_OUTPUTS cv::cudacodec::ColorFormat::BGRA, cv::cudacodec::ColorFormat::BGRA
INSTANTIATE_TEST_CASE_P ( CUDA_Codec , ColorConversion , testing : : Combine (
ALL_DEVICES ,
testing : : Values ( VIDEO_COLOR_OUTPUTS ) ,
testing : : ValuesIn ( color_conversion_params ) ) ) ;
# define VIDEO_SRC_RW "highgui / video / big_buck_bunny.h264", "highgui / video / big_buck_bunny.h265"
INSTANTIATE_TEST_CASE_P ( CUDA_Codec , VideoReadRaw , testing : : Combine (
ALL_DEVICES ,