instruction
stringclasses
9 values
input
stringlengths
279
5.47k
output
stringlengths
6
9.58k
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_jpeg.cpp **Change Type:** modified **Context:** PR #27583: Jpeg Metadata (iccp and xmp) **Code Changes:** ```diff @@ -247,8 +247,43 @@ bool JpegDecoder::readHeader() if (state->cinfo.src != 0) { jpeg_save_markers(&state->cinfo, APP1, 0xffff); + jpeg_save_markers(&state->cinfo, APP2, 0xffff); jpeg_read_header( &state->cinfo, TRUE ); + const std::streamsize EXIF_HEADER_SIZE = 6; // "Exif\0\0" + const std::streamsize XMP_HEADER_SIZE = 29; // "http://ns.adobe.com/xap/1.0/" + const std::streamsize ICC_HEADER_SIZE = 14; // "ICC_PROFILE\0" + seq/total ```
I propose to create named constant for 29 like EXIF_HEADER_SIZE
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9 **Code Changes:** ```diff @@ -388,8 +388,13 @@ macro(ocv_nvcc_flags) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only) endif() - if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2")) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + if(WIN32) + if (NOT (CUDA_VERSION VERSION_LESS "11.2")) + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + endif() ```
Which compilation errors do you get with this version of CUDA without the `--expt-relaxed-constexpr` flag? I'm interested because I can build against CUDA 12.8 on windows without this experimental flag.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9 **Code Changes:** ```diff @@ -388,8 +388,13 @@ macro(ocv_nvcc_flags) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only) endif() - if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2")) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + if(WIN32) + if (NOT (CUDA_VERSION VERSION_LESS "11.2")) + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + endif() ```
I can get a lot of errors like : ``` D:\github\chacha21\opencv_contrib\modules\cudev\include\opencv2\cudev/warp/reduce.hpp(140): error : calling a constexpr __host__ function("make_tuple") from a __device__ function("smem_tuple") is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this. 5> return make_tuple((volatile T0*) t0, (volatile T1*) t1); 5> ^ 5> detected during: 5> instantiation of "cuda::std::__4::tuple<volatile T0 *, volatile T1 *> cv::cudev::smem_tuple(T0 *, T1 *) [with T0=float, T1=float]" at line 379 of D:\github\chacha21\opencv_contrib\modules\cudev\include\opencv2\cudev\grid\detail/reduce.hpp 5> instantiation of "void cv::cudev::grid_reduce_detail::MinMaxReductor<cv::cudev::grid_reduce_detail::both, src_type, work_type>::reduceGrid<BLOCK_SIZE>(work_type *, int) [with src_type=uchar, work_type=float, BLOCK_SIZE=256]" at line 412 of D:\github\chacha21\opencv_contrib\modules\cudev\include\opencv2\cudev\grid\detail/reduce.hpp 5> instantiation of "void cv::cudev::grid_reduce_detail::reduce<Reductor,BLOCK_SIZE,PATCH_X,PATCH_Y,SrcPtr,ResType,MaskPtr>(SrcPtr, ResType *, MaskPtr, int, int) [with Reductor=cv::cudev::grid_reduce_detail::MinMaxReductor<cv::cudev::grid_reduce_detail::both, uchar, float>, BLOCK_SIZE=256, PATCH_X=4, PATCH_Y=4, SrcPtr=cv::cudev::GlobPtr<uchar>, ResType=float, MaskPtr=cv::cudev::WithOutMask]" at line 421 of D:\github\chacha21\opencv_contrib\modules\cudev\include\opencv2\cudev\grid\detail/reduce.hpp 5> instantiation of "void cv::cudev::grid_reduce_detail::reduce<Reductor,Policy,SrcPtr,ResType,MaskPtr>(const SrcPtr &, ResType *, const MaskPtr &, int, int, cudaStream_t) [with Reductor=cv::cudev::grid_reduce_detail::MinMaxReductor<cv::cudev::grid_reduce_detail::both, uchar, float>, Policy=cv::cudev::DefaultGlobReducePolicy, SrcPtr=cv::cudev::GlobPtr<uchar>, ResType=float, MaskPtr=cv::cudev::WithOutMask]" at line 460 of D:\github\chacha21\opencv_contrib\modules\cudev\include\opencv2\cudev\grid\detail/reduce.hpp 5> instantiation of "void cv::cudev::grid_reduce_detail::minMaxVal<Policy,SrcPtr,ResType,MaskPtr>(const SrcPtr &, ResType *, const MaskPtr &, int, int, cudaStream_t) [with Policy=cv::cudev::DefaultGlobReducePolicy, SrcPtr=cv::cudev::GlobPtr<uchar>, ResType=float, MaskPtr=cv::cudev::WithOutMask]" at line 206 of D:\github\chacha21\opencv_contrib\modules\cudev\include\opencv2\cudev/grid/reduce.hpp 5> instantiation of "void cv::cudev::gridFindMinMaxVal_<Policy,SrcPtr,ResType>(const SrcPtr &, cv::cudev::GpuMat_<ResType> &, cv::cuda::Stream &) [with Policy=cv::cudev::DefaultGlobReducePolicy, SrcPtr=cv::cudev::GpuMat_<uchar>, ResType=float]" at line 349 of D:\github\chacha21\opencv_contrib\modules\cudev\include\opencv2\cudev/grid/reduce.hpp 5> instantiation of "void cv::cudev::gridFindMinMaxVal(const SrcPtr &, cv::cudev::GpuMat_<ResType> &, cv::cuda::Stream &) [with SrcPtr=cv::cudev::GpuMat_<uchar>, ResType=float]" at line 137 of D:\github\chacha21\opencv_contrib\modules\cudev\include\opencv2\cudev/expr/reduction.hpp 5> instantiation of "void cv::cudev::FindMinMaxValExprBody<SrcPtr>::assignTo(cv::cudev::GpuMat_<T> &, cv::cuda::Stream &) const [with SrcPtr=cv::cudev::GpuMat_<uchar>, T=float]" at line 325 of D:\github\chacha21\opencv_contrib\modules\cudev\include\opencv2\cudev\ptr2d\detail/gpumat.hpp 5> instantiation of "cv::cudev::GpuMat_<T> &cv::cudev::GpuMat_<T>::operator=(const cv::cudev::Expr<Body> &) [with T=float, Body=cv::cudev::FindMinMaxValExprBody<cv::cudev::GpuMat_<uchar>>]" at line 319 of D:\github\chacha21\opencv_contrib\modules\cudev\include\opencv2\cudev\ptr2d\detail/gpumat.hpp 5> instantiation of "cv::cudev::GpuMat_<T>::GpuMat_(const cv::cudev::Expr<Body> &) [with T=float, Body=cv::cudev::FindMinMaxValExprBody<cv::cudev::GpuMat_<uchar>>]" at line 130 of D:\github\chacha21\opencv_contrib\modules\cudev\test\test_reduction.cu ```
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9 **Code Changes:** ```diff @@ -388,8 +388,13 @@ macro(ocv_nvcc_flags) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only) endif() - if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2")) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + if(WIN32) + if (NOT (CUDA_VERSION VERSION_LESS "11.2")) + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + endif() ```
You get this with CUDA 12.8 and the latest version of Visual Studio 2022? I only see those errors with CUDA 12.9 without the addition of `-Xcompiler /Zc:preprocessor`. I'm building with Ninja are you building directly in VS? <hr> **Update:** I can't recreate this, can you provide your CMake arguments, the version of VS, CUDA and CMake you are using please. I can build OpenCV without the `--expt-relaxed-constexpr` flag in VS 17.14.7 with CUDA 12.8, and CMake 4.01 using both the Ninja and VS generator.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9 **Code Changes:** ```diff @@ -388,8 +388,13 @@ macro(ocv_nvcc_flags) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only) endif() - if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2")) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + if(WIN32) + if (NOT (CUDA_VERSION VERSION_LESS "11.2")) + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + endif() ```
You are right, I can't reproduce it either with 12.8. I must have fooled myself among my different experiments. I will update the PR.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9 **Code Changes:** ```diff @@ -388,8 +388,13 @@ macro(ocv_nvcc_flags) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only) endif() - if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2")) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + if(WIN32) + if (NOT (CUDA_VERSION VERSION_LESS "11.2")) + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + endif() ```
For consistency with the rest of the file I would use `-Xcompiler=/Zc:preprocessor`
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9 **Code Changes:** ```diff @@ -388,8 +388,13 @@ macro(ocv_nvcc_flags) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only) endif() - if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2")) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + if(WIN32) + if (NOT (CUDA_VERSION VERSION_LESS "11.2")) + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + endif() ```
I confirm that on my build system, I do need "--expt-relaxed-constexpr", otherwise the first compilation errors start with opencv_test_cudev ``` D:\opencv_contrib-4.12.0\modules\cudev\include\opencv2\cudev/warp/reduce.hpp(140): error : calling a constexpr __host__ function("make_tuple") from a __device__ function("smem_tuple") is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this. 5> return make_tuple((volatile T0*) t0, (volatile T1*) t1); 5> ^ 5> detected during: 5> instantiation of "cuda::std::__4::tuple<volatile T0 *, volatile T1 *> cv::cudev::smem_tuple(T0 *, T1 *) [with T0=float, T1=float]" at line 379 of D:\opencv_contrib-4.12.0\modules\cudev\include\opencv2\cudev\grid\detail/reduce.hpp 5> instantiation of "void cv::cudev::grid_reduce_detail::MinMaxReductor<cv::cudev::grid_reduce_detail::both, src_type, work_type>::reduceGrid<BLOCK_SIZE>(work_type *, int) [with src_type=uchar, work_type=float, BLOCK_SIZE=256]" at line 412 of D:\opencv_contrib-4.12.0\modules\cudev\include\opencv2\cudev\grid\detail/reduce.hpp 5> instantiation of "void cv::cudev::grid_reduce_detail::reduce<Reductor,BLOCK_SIZE,PATCH_X,PATCH_Y,SrcPtr,ResType,MaskPtr>(SrcPtr, ResType *, MaskPtr, int, int) [with Reductor=cv::cudev::grid_reduce_detail::MinMaxReductor<cv::cudev::grid_reduce_detail::both, uchar, float>, BLOCK_SIZE=256, PATCH_X=4, PATCH_Y=4, SrcPtr=cv::cudev::GlobPtr<uchar>, ResType=float, MaskPtr=cv::cudev::WithOutMask]" at line 421 of D:\opencv_contrib-4.12.0\modules\cudev\include\opencv2\cudev\grid\detail/reduce.hpp 5> instantiation of "void cv::cudev::grid_reduce_detail::reduce<Reductor,Policy,SrcPtr,ResType,MaskPtr>(const SrcPtr &, ResType *, const MaskPtr &, int, int, cudaStream_t) [with Reductor=cv::cudev::grid_reduce_detail::MinMaxReductor<cv::cudev::grid_reduce_detail::both, uchar, float>, Policy=cv::cudev::DefaultGlobReducePolicy, SrcPtr=cv::cudev::GlobPtr<uchar>, ResType=float, MaskPtr=cv::cudev::WithOutMask]" at line 460 of D:\opencv_contrib-4.12.0\modules\cudev\include\opencv2\cudev\grid\detail/reduce.hpp 5> instantiation of "void cv::cudev::grid_reduce_detail::minMaxVal<Policy,SrcPtr,ResType,MaskPtr>(const SrcPtr &, ResType *, const MaskPtr &, int, int, cudaStream_t) [with Policy=cv::cudev::DefaultGlobReducePolicy, SrcPtr=cv::cudev::GlobPtr<uchar>, ResType=float, MaskPtr=cv::cudev::WithOutMask]" at line 206 of D:\opencv_contrib-4.12.0\modules\cudev\include\opencv2\cudev/grid/reduce.hpp 5> instantiation of "void cv::cudev::gridFindMinMaxVal_<Policy,SrcPtr,ResType>(const SrcPtr &, cv::cudev::GpuMat_<ResType> &, cv::cuda::Stream &) [with Policy=cv::cudev::DefaultGlobReducePolicy, SrcPtr=cv::cudev::GpuMat_<uchar>, ResType=float]" at line 349 of D:\opencv_contrib-4.12.0\modules\cudev\include\opencv2\cudev/grid/reduce.hpp 5> instantiation of "void cv::cudev::gridFindMinMaxVal(const SrcPtr &, cv::cudev::GpuMat_<ResType> &, cv::cuda::Stream &) [with SrcPtr=cv::cudev::GpuMat_<uchar>, ResType=float]" at line 137 of D:\opencv_contrib-4.12.0\modules\cudev\include\opencv2\cudev/expr/reduction.hpp 5> instantiation of "void cv::cudev::FindMinMaxValExprBody<SrcPtr>::assignTo(cv::cudev::GpuMat_<T> &, cv::cuda::Stream &) const [with SrcPtr=cv::cudev::GpuMat_<uchar>, T=float]" at line 325 of D:\opencv_contrib-4.12.0\modules\cudev\include\opencv2\cudev\ptr2d\detail/gpumat.hpp 5> instantiation of "cv::cudev::GpuMat_<T> &cv::cudev::GpuMat_<T>::operator=(const cv::cudev::Expr<Body> &) [with T=float, Body=cv::cudev::FindMinMaxValExprBody<cv::cudev::GpuMat_<uchar>>]" at line 319 of D:\opencv_contrib-4.12.0\modules\cudev\include\opencv2\cudev\ptr2d\detail/gpumat.hpp 5> instantiation of "cv::cudev::GpuMat_<T>::GpuMat_(const cv::cudev::Expr<Body> &) [with T=float, Body=cv::cudev::FindMinMaxValExprBody<cv::cudev::GpuMat_<uchar>>]" at line 130 of D:\opencv_contrib-4.12.0\modules\cudev\test\test_reduction.cu 5> ``` [CMakeCache.txt](https://github.com/user-attachments/files/21229053/CMakeCache.txt)
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9 **Code Changes:** ```diff @@ -388,8 +388,13 @@ macro(ocv_nvcc_flags) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only) endif() - if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2")) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + if(WIN32) + if (NOT (CUDA_VERSION VERSION_LESS "11.2")) + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + endif() ```
It is with ``` if(WIN32) if (NOT (CUDA_VERSION VERSION_LESS "11.2")) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) endif() if(CUDA_VERSION GREATER "12.8") #set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --expt-relaxed-constexpr) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=/Zc:preprocessor) endif() endif() ```
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9 **Code Changes:** ```diff @@ -388,8 +388,13 @@ macro(ocv_nvcc_flags) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only) endif() - if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2")) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + if(WIN32) + if (NOT (CUDA_VERSION VERSION_LESS "11.2")) + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + endif() ```
To fix the **cudev** error you need to apply the PR I linked to. Without it I get the errors you mentioned above even with the experimental flag (`--expt-relaxed-constexpr`).
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVDetectCUDAUtils.cmake **Change Type:** modified **Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9 **Code Changes:** ```diff @@ -388,8 +388,13 @@ macro(ocv_nvcc_flags) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only) endif() - if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2")) - set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + if(WIN32) + if (NOT (CUDA_VERSION VERSION_LESS "11.2")) + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) + endif() ```
Indending the inner if statements will make it easier to read.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/loadsave.cpp **Change Type:** modified **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -148,14 +148,18 @@ struct ImageCodecInitializer */ ImageCodecInitializer() { -#ifdef HAVE_AVIF - decoders.push_back(makePtr<AvifDecoder>()); - encoders.push_back(makePtr<AvifEncoder>()); -#endif /// BMP Support decoders.push_back( makePtr<BmpDecoder>() ); ```
You need to guard that code with an `#ifdef HAVE_GIF`
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_gif.cpp **Change Type:** added **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -0,0 +1,1144 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level +// directory of this distribution and at http://opencv.org/license.html + +#include "precomp.hpp" +#include "grfmt_gif.hpp" + +#ifdef HAVE_IMGCODEC_GIF +namespace cv ```
Please add signature check.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_gif.cpp **Change Type:** added **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -0,0 +1,1144 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level +// directory of this distribution and at http://opencv.org/license.html + +#include "precomp.hpp" +#include "grfmt_gif.hpp" + +#ifdef HAVE_IMGCODEC_GIF +namespace cv ```
cv::Mat::zeros()
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_gif.cpp **Change Type:** added **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -0,0 +1,357 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html +#include "test_precomp.hpp" + +#ifdef HAVE_IMGCODEC_GIF + +namespace opencv_test { namespace { + ```
The solution is very inefficient in terms of OpenCV Extra repository. I propose the following: - Cherry pick several key images for regular unit testing, convert the reference xmls to png and put pngs to extra - Add disabled test with all cases and describe how to get/generate data for it in the test comments. As alternative, you can put it to https://github.com/opencv/opencv_benchmarks as dedicated app with instruction
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_gif.cpp **Change Type:** added **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -0,0 +1,357 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html +#include "test_precomp.hpp" + +#ifdef HAVE_IMGCODEC_GIF + +namespace opencv_test { namespace { + ```
Please use png for reference frames. 161 is to much. I propose to check some key frames and sequence size only.
You are an expert OpenCV code reviewer specializing in memory management. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_gif.cpp **Change Type:** added **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -0,0 +1,1144 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level +// directory of this distribution and at http://opencv.org/license.html + +#include "precomp.hpp" +#include "grfmt_gif.hpp" + +#ifdef HAVE_IMGCODEC_GIF +namespace cv ```
please use std::vector, std::array or cv::AutoBuffer to prevent memory leaks in cases of parser failrue.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/loadsave.cpp **Change Type:** modified **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -148,14 +148,18 @@ struct ImageCodecInitializer */ ImageCodecInitializer() { -#ifdef HAVE_AVIF - decoders.push_back(makePtr<AvifDecoder>()); - encoders.push_back(makePtr<AvifEncoder>()); -#endif /// BMP Support decoders.push_back( makePtr<BmpDecoder>() ); ```
done, i set that initially on
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_gif.cpp **Change Type:** added **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -0,0 +1,357 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html +#include "test_precomp.hpp" + +#ifdef HAVE_IMGCODEC_GIF + +namespace opencv_test { namespace { + ```
here the testing data is converted from the testing images under `pngsuite` in extra via ffmpeg, thus we directly reference to the xmls that the png test uses. would this solution be fine?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_gif.cpp **Change Type:** added **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -0,0 +1,1144 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level +// directory of this distribution and at http://opencv.org/license.html + +#include "precomp.hpp" +#include "grfmt_gif.hpp" + +#ifdef HAVE_IMGCODEC_GIF +namespace cv ```
why do you need a try/catch here?
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_gif.hpp **Change Type:** added **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -0,0 +1,183 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level +// directory of this distribution and at http://opencv.org/license.html + +#ifndef OPENCV_GRFMT_GIF_HPP +#define OPENCV_GRFMT_GIF_HPP +#ifdef HAVE_IMGCODEC_GIF + +#include "grfmt_base.hpp" ```
No need to make that struct public
You are an expert OpenCV code reviewer specializing in memory management. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_gif.cpp **Change Type:** added **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -0,0 +1,1144 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level +// directory of this distribution and at http://opencv.org/license.html + +#include "precomp.hpp" +#include "grfmt_gif.hpp" + +#ifdef HAVE_IMGCODEC_GIF +namespace cv ```
at first i think i need to deal with some potential memory leak, as using vector and autobuffer this is not needed but i forgot to delete it. in the newest version i deleted it.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_gif.cpp **Change Type:** added **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -0,0 +1,1144 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level +// directory of this distribution and at http://opencv.org/license.html + +#include "precomp.hpp" +#include "grfmt_gif.hpp" + +#ifdef HAVE_IMGCODEC_GIF +namespace cv ```
```cpp std::vector<Mat> img_vec(1, img); ``` to avoid push_back overhead
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_gif.cpp **Change Type:** added **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -0,0 +1,1144 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level +// directory of this distribution and at http://opencv.org/license.html + +#include "precomp.hpp" +#include "grfmt_gif.hpp" + +#ifdef HAVE_IMGCODEC_GIF +namespace cv ```
```cpp std::vector<Mat> img_vec(1, img); ```
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** CMakeLists.txt **Change Type:** modified **Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs **Code Changes:** ```diff @@ -464,6 +464,9 @@ OCV_OPTION(WITH_ITT "Include Intel ITT support" ON OCV_OPTION(WITH_PROTOBUF "Enable libprotobuf" ON VISIBLE_IF TRUE VERIFY HAVE_PROTOBUF) +OCV_OPTION(WITH_IMGCODEC_GIF "Include GIF support" OFF + VISIBLE_IF TRUE + VERIFY HAVE_IMGCODEC_GIF) OCV_OPTION(WITH_IMGCODEC_HDR "Include HDR support" ON VISIBLE_IF TRUE VERIFY HAVE_IMGCODEC_HDR) ```
I believe we should disable it by default at least for now to allow users test it in safe environment and our OSS-Fuzz builds.
You are an expert OpenCV code reviewer specializing in memory management. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_graph_simplifier.cpp **Change Type:** modified **Context:** PR #27449: Onnx multifile import **Code Changes:** ```diff @@ -10,6 +10,8 @@ #ifdef HAVE_PROTOBUF #include "../graph_simplifier.hpp" #include "onnx_graph_simplifier.hpp" +#include <opencv2/core/utils/filesystem.hpp> +#include "opencv2/core/utils/filesystem.private.hpp" #include <opencv2/core/utils/logger.hpp> #include <queue> @@ -1704,30 +1706,82 @@ void simplifySubgraphs(opencv_onnx::GraphProto& net) ```
I'd suggest to modify this function (and probably rename it) to return `Mat` instead of plain pointer. This way we can track memory allocations properly. Currently, I suspect, there are memory leaks.
You are an expert OpenCV code reviewer specializing in documentation and code clarity. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_importer2.cpp **Change Type:** modified **Context:** PR #27449: Onnx multifile import **Code Changes:** ```diff @@ -7,7 +7,7 @@ #include <opencv2/dnn/shape_utils.hpp> #include <opencv2/dnn/layer_reg.private.hpp> - +#include <opencv2/core/utils/filesystem.hpp> #include <opencv2/core/utils/fp_control_utils.hpp> #include <opencv2/core/utils/logger.defines.hpp> #undef CV_LOG_STRIP_LEVEL @@ -58,7 +58,9 @@ static T getScalarFromMat(Mat m) ```
can probably just remove the unused function instead of commenting it off; if we need it later, we can restore it from the git history.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_importer2.cpp **Change Type:** modified **Context:** PR #27449: Onnx multifile import **Review Line:** 106 **Code Changes:** ```diff @@ -100,9 +103,9 @@ static std::string dataType2str(opencv_onnx::TensorProto_DataType dt) return std::string(str); } -static Mat getMatFromTensor2(const opencv_onnx::TensorProto& tensor_proto) +static Mat getMatFromTensor2(const opencv_onnx::TensorProto& tensor_proto, const std::string base_path="") { - Mat m = getMatFromTensor(tensor_proto, false); + Mat m = getMatFromTensor(tensor_proto, false, base_path); m.dims = (int)tensor_proto.dims_size(); return m; ```
`const std::string&`
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_graph_simplifier.cpp **Change Type:** modified **Context:** PR #27449: Onnx multifile import **Code Changes:** ```diff @@ -10,6 +10,8 @@ #ifdef HAVE_PROTOBUF #include "../graph_simplifier.hpp" #include "onnx_graph_simplifier.hpp" +#include <opencv2/core/utils/filesystem.hpp> +#include "opencv2/core/utils/filesystem.private.hpp" #include <opencv2/core/utils/logger.hpp> #include <queue> @@ -1704,30 +1706,82 @@ void simplifySubgraphs(opencv_onnx::GraphProto& net) ```
There are platforms, where filesystem is not available. You need to handle it like here: https://github.com/opencv/opencv/blob/d1b4b46dc61e3552b03bd440c39283a75d89f0a2/modules/core/src/utils/filesystem.cpp#L102.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_graph_simplifier.cpp **Change Type:** modified **Context:** PR #27449: Onnx multifile import **Code Changes:** ```diff @@ -10,6 +10,8 @@ #ifdef HAVE_PROTOBUF #include "../graph_simplifier.hpp" #include "onnx_graph_simplifier.hpp" +#include <opencv2/core/utils/filesystem.hpp> +#include "opencv2/core/utils/filesystem.private.hpp" #include <opencv2/core/utils/logger.hpp> #include <queue> @@ -1704,30 +1706,82 @@ void simplifySubgraphs(opencv_onnx::GraphProto& net) ```
Most probably it's a bug. I'll take a look.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_graph_simplifier.cpp **Change Type:** modified **Context:** PR #27449: Onnx multifile import **Code Changes:** ```diff @@ -10,6 +10,8 @@ #ifdef HAVE_PROTOBUF #include "../graph_simplifier.hpp" #include "onnx_graph_simplifier.hpp" +#include <opencv2/core/utils/filesystem.hpp> +#include "opencv2/core/utils/filesystem.private.hpp" #include <opencv2/core/utils/logger.hpp> #include <queue> @@ -1704,30 +1706,82 @@ void simplifySubgraphs(opencv_onnx::GraphProto& net) ```
redundant empty lines.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_graph_simplifier.cpp **Change Type:** modified **Context:** PR #27449: Onnx multifile import **Code Changes:** ```diff @@ -10,6 +10,8 @@ #ifdef HAVE_PROTOBUF #include "../graph_simplifier.hpp" #include "onnx_graph_simplifier.hpp" +#include <opencv2/core/utils/filesystem.hpp> +#include "opencv2/core/utils/filesystem.private.hpp" #include <opencv2/core/utils/logger.hpp> #include <queue> @@ -1704,30 +1706,82 @@ void simplifySubgraphs(opencv_onnx::GraphProto& net) ```
I propose to use CV_check with verbose error message. It's not useful for production usage, but may be practical for development.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_graph_simplifier.cpp **Change Type:** modified **Context:** PR #27449: Onnx multifile import **Code Changes:** ```diff @@ -10,6 +10,8 @@ #ifdef HAVE_PROTOBUF #include "../graph_simplifier.hpp" #include "onnx_graph_simplifier.hpp" +#include <opencv2/core/utils/filesystem.hpp> +#include "opencv2/core/utils/filesystem.private.hpp" #include <opencv2/core/utils/logger.hpp> #include <queue> @@ -1704,30 +1706,82 @@ void simplifySubgraphs(opencv_onnx::GraphProto& net) ```
I have changed this to `CV_CheckTrue`
You are an expert OpenCV code reviewer specializing in performance optimization. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/cuda.hpp **Change Type:** modified **Context:** PR #27379: cuda: Fix GpuMat::convertTo issues described in 27373 **Code Changes:** ```diff @@ -240,6 +240,10 @@ class CV_EXPORTS_W GpuMat //! converts GpuMat to another datatype (Blocking call) void convertTo(OutputArray dst, int rtype) const; + //! bindings overload which converts GpuMat to another datatype (Blocking call) + CV_WRAP void convertTo(CV_OUT GpuMat& dst, int rtype) const { + convertTo(static_cast<OutputArray>(dst), rtype); + } //! converts GpuMat to another datatype (Non-Blocking call) ```
Hm.. It changes Python and Java bindings logic. It requires scale now. Looking on more efficient solution.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/include/opencv2/core/cuda.hpp **Change Type:** modified **Context:** PR #27379: cuda: Fix GpuMat::convertTo issues described in 27373 **Code Changes:** ```diff @@ -240,6 +240,10 @@ class CV_EXPORTS_W GpuMat //! converts GpuMat to another datatype (Blocking call) void convertTo(OutputArray dst, int rtype) const; + //! bindings overload which converts GpuMat to another datatype (Blocking call) + CV_WRAP void convertTo(CV_OUT GpuMat& dst, int rtype) const { + convertTo(static_cast<OutputArray>(dst), rtype); + } //! converts GpuMat to another datatype (Non-Blocking call) ```
Its confusing I can't remember why but looking at it now I must have added `double alpha = 1.0` on purpose. I just can't think why I would have done that instead of just adding a bindings overloading to the first function definition. I've added a bindings overload now and all the tests seem to pass but I'm not satisfied!
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** hal/ipp/src/warp_ipp.cpp **Change Type:** modified **Context:** PR #27519: Move IPP Remap to HAL **Review Line:** 449 **Code Changes:** ```diff + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //8S + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //16U + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //16S + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //32S + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //32F + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}}; //64F + + if (impl[CV_TYPE(src_type)][CV_MAT_CN(src_type) - 1][interpolation] == 0) + { + return CV_HAL_ERROR_NOT_IMPLEMENTED; + } ```
It's disabled everywhere. Is it expected behaviour?
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** hal/ipp/src/warp_ipp.cpp **Change Type:** modified **Context:** PR #27519: Move IPP Remap to HAL **Review Line:** 449 **Code Changes:** ```diff + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //8S + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //16U + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //16S + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //32S + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, //32F + {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}}; //64F + + if (impl[CV_TYPE(src_type)][CV_MAT_CN(src_type) - 1][interpolation] == 0) + { + return CV_HAL_ERROR_NOT_IMPLEMENTED; + } ```
Yes, there functional test fails for all cases. I investigate it now, and will enable some cases later.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVBindingsPreprocessorDefinitions.cmake **Change Type:** added **Context:** PR #27325: feat: add conditional inclusion support to header parser **Review Line:** 50 **Code Changes:** ```diff + ocv_add_definition(CV_ENABLE_UNROLLED 0) + ocv_add_definition(CV__EXCEPTION_PTR 0) + ocv_add_definition(CV_NEON 0) + ocv_add_definition(TBB_INTERFACE_VERSION 0) + ocv_add_definition(CV_SSE2 0) + ocv_add_definition(CV_VSX 0) + ocv_add_definition(OPENCV_SUPPORTS_FP_DENORMALS_HINT 0) + ocv_add_definition(CV_LOG_STRIP_LEVEL 0) + ocv_add_definition(CV_LOG_LEVEL_SILENT 0) + ocv_add_definition(CV_LOG_LEVEL_FATAL 1) + ocv_add_definition(CV_LOG_LEVEL_ERROR 2) ```
I propose to drop it.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/python/src2/hdr_parser.py **Change Type:** modified **Context:** PR #27325: feat: add conditional inclusion support to header parser **Code Changes:** ```diff @@ -31,11 +31,160 @@ original_return_type is None if the original_return_type is the same as return_value_type """ +def evaluate_conditional_inclusion_directive(directive, preprocessor_definitions): + """Evaluates C++ conditional inclusion directive. + Reference: https://en.cppreference.com/w/cpp/preprocessor/conditional + + Args: + directive(str): input C++ conditional directive. ```
```python >>> 'www.example.com'.strip('cmowz.') 'example' ``` What do you want to strip?
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVBindingsPreprocessorDefinitions.cmake **Change Type:** added **Context:** PR #27325: feat: add conditional inclusion support to header parser **Review Line:** 50 **Code Changes:** ```diff + ocv_add_definition(CV_ENABLE_UNROLLED 0) + ocv_add_definition(CV__EXCEPTION_PTR 0) + ocv_add_definition(CV_NEON 0) + ocv_add_definition(TBB_INTERFACE_VERSION 0) + ocv_add_definition(CV_SSE2 0) + ocv_add_definition(CV_VSX 0) + ocv_add_definition(OPENCV_SUPPORTS_FP_DENORMALS_HINT 0) + ocv_add_definition(CV_LOG_STRIP_LEVEL 0) + ocv_add_definition(CV_LOG_LEVEL_SILENT 0) + ocv_add_definition(CV_LOG_LEVEL_FATAL 1) + ocv_add_definition(CV_LOG_LEVEL_ERROR 2) ```
It is not possible to drop it, because header parser parsers "implementation" headers and bumps into lines like: ```cpp #if CV_VSX // something #else // something #endif ```
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/python/src2/hdr_parser.py **Change Type:** modified **Context:** PR #27325: feat: add conditional inclusion support to header parser **Code Changes:** ```diff @@ -31,11 +31,160 @@ original_return_type is None if the original_return_type is the same as return_value_type """ +def evaluate_conditional_inclusion_directive(directive, preprocessor_definitions): + """Evaluates C++ conditional inclusion directive. + Reference: https://en.cppreference.com/w/cpp/preprocessor/conditional + + Args: + directive(str): input C++ conditional directive. ```
what if `#ifdef HAVE_XXX`
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVBindingsPreprocessorDefinitions.cmake **Change Type:** added **Context:** PR #27325: feat: add conditional inclusion support to header parser **Review Line:** 50 **Code Changes:** ```diff + ocv_add_definition(CV_ENABLE_UNROLLED 0) + ocv_add_definition(CV__EXCEPTION_PTR 0) + ocv_add_definition(CV_NEON 0) + ocv_add_definition(TBB_INTERFACE_VERSION 0) + ocv_add_definition(CV_SSE2 0) + ocv_add_definition(CV_VSX 0) + ocv_add_definition(OPENCV_SUPPORTS_FP_DENORMALS_HINT 0) + ocv_add_definition(CV_LOG_STRIP_LEVEL 0) + ocv_add_definition(CV_LOG_LEVEL_SILENT 0) + ocv_add_definition(CV_LOG_LEVEL_FATAL 1) + ocv_add_definition(CV_LOG_LEVEL_ERROR 2) ```
hm.. need to check.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/python/src2/hdr_parser.py **Change Type:** modified **Context:** PR #27325: feat: add conditional inclusion support to header parser **Review Line:** 154 **Code Changes:** ```diff + except Exception as e: + raise ValueError( + "Failed to evaluate '{}' directive, stripped down to '{}'".format( + input_directive, directive + ) + ) from e + + if not isinstance(eval_directive, (bool, int)): + raise TypeError( + "'{}' directive is evaluated to unexpected type: {}".format( + input_directive, type(eval_directive).__name__ ```
It requires Python update. I notified Alexander about it.
You are an expert OpenCV code reviewer specializing in code quality and best practices. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/OpenCVFindLibsPerf.cmake **Change Type:** modified **Context:** PR #27536: eigen: fix to get version from eigen after v3.4.0 **Code Changes:** ```diff @@ -84,7 +84,13 @@ if(WITH_EIGEN AND NOT HAVE_EIGEN) set(EIGEN_WORLD_VERSION ${EIGEN3_WORLD_VERSION}) set(EIGEN_MAJOR_VERSION ${EIGEN3_MAJOR_VERSION}) set(EIGEN_MINOR_VERSION ${EIGEN3_MINOR_VERSION}) - else() # Eigen config file + elseif(DEFINED Eigen3_VERSION_MAJOR) # Recommended package config variables + # see https://github.com/opencv/opencv/issues/27530 + set(EIGEN_WORLD_VERSION ${Eigen3_VERSION_MAJOR}) + set(EIGEN_MAJOR_VERSION ${Eigen3_VERSION_MINOR}) + set(EIGEN_MINOR_VERSION ${Eigen3_VERSION_PATCH}) ```
It'll be great to add pointer to Eigen commit or MR instead of just date.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_png.cpp **Change Type:** modified **Context:** PR #27551: Add enum IMWRITE_PNG_ZLIBBUFFER_SIZE **Code Changes:** ```diff @@ -947,26 +947,36 @@ bool PngEncoder::write( const Mat& img, const std::vector<int>& params ) for( size_t i = 0; i < params.size(); i += 2 ) { - if( params[i] == IMWRITE_PNG_COMPRESSION ) + switch (params[i]) { + case IMWRITE_PNG_COMPRESSION: m_compression_strategy = IMWRITE_PNG_STRATEGY_DEFAULT; // Default strategy m_compression_level = params[i+1]; ```
It's invalid imwrite option. I propose CV_Error here instead of silent ignore.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_png.cpp **Change Type:** modified **Context:** PR #27551: Add enum IMWRITE_PNG_ZLIBBUFFER_SIZE **Code Changes:** ```diff @@ -12,14 +12,15 @@ 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); ```
Does ZLIB buffer size affects output size? I expect - no. I do not think we can efficiently test the option.
You are an expert OpenCV code reviewer specializing in memory management. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_png.cpp **Change Type:** modified **Context:** PR #27551: Add enum IMWRITE_PNG_ZLIBBUFFER_SIZE **Code Changes:** ```diff @@ -12,14 +12,15 @@ 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); ```
Increasing the zlib buffer size can reduce the number of IDAT chunks in large PNG images, resulting in slightly smaller output file sizes. `imencode(".png", img, buff));` result buff.size() will be **817407** `imencode(".png", img, buff, { IMWRITE_PNG_ZLIBBUFFER_SIZE, 2 << 15 })` result buff.size() will be **816363** `imencode(".png", img, buff, { IMWRITE_PNG_ZLIBBUFFER_SIZE, 4096 })` result buff.size() will be **818607**
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_png.cpp **Change Type:** modified **Context:** PR #27551: Add enum IMWRITE_PNG_ZLIBBUFFER_SIZE **Review Line:** 979 **Code Changes:** ```diff + png_set_compression_buffer_size(png_ptr, params[i+1]); + break; + + default: + CV_LOG_WARNING(NULL, "An unknown or unsupported ImwriteFlags value was specified and has been ignored."); + break; } } ```
The error is user input error in code and definitely means some bug. The common rule in OpenCV is to use CV_Assert and throw exceptions for the developer mistakes, but not ignore it. I propose to return back CV_Error and merge it.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_png.cpp **Change Type:** modified **Context:** PR #27551: Add enum IMWRITE_PNG_ZLIBBUFFER_SIZE **Review Line:** 979 **Code Changes:** ```diff + png_set_compression_buffer_size(png_ptr, params[i+1]); + break; + + default: + CV_LOG_WARNING(NULL, "An unknown or unsupported ImwriteFlags value was specified and has been ignored."); + break; } } ```
i propose creating an issue and plan to change this behavior in OpenCV 5
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/trilu_layer.cpp **Change Type:** added **Context:** PR #27527: Trilu layer **Code Changes:** ```diff @@ -0,0 +1,85 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include <opencv2/dnn/shape_utils.hpp> +using namespace std; +namespace cv { namespace dnn { + ```
extra empty line.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/trilu_layer.cpp **Change Type:** added **Context:** PR #27527: Trilu layer **Code Changes:** ```diff @@ -0,0 +1,85 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include <opencv2/dnn/shape_utils.hpp> +using namespace std; +namespace cv { namespace dnn { + ```
`uppertri` -> `upperTri`
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/init.cpp **Change Type:** modified **Context:** PR #27527: Trilu layer **Code Changes:** ```diff @@ -186,6 +186,7 @@ void initializeLayerFactory() CV_DNN_REGISTER_LAYER_CLASS(DepthToSpaceInt8, DepthToSpaceLayer) CV_DNN_REGISTER_LAYER_CLASS(SpaceToDepthInt8, SpaceToDepthLayer) + CV_DNN_REGISTER_LAYER_CLASS(Trilu, TriluLayer); CV_DNN_REGISTER_LAYER_CLASS(Crop, CropLayer); CV_DNN_REGISTER_LAYER_CLASS(Eltwise, EltwiseLayer); CV_DNN_REGISTER_LAYER_CLASS(NaryEltwise, NaryEltwiseLayer); ```
Not needed most probably.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/trilu_layer.cpp **Change Type:** added **Context:** PR #27527: Trilu layer **Code Changes:** ```diff @@ -0,0 +1,85 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "../precomp.hpp" +#include <opencv2/dnn/shape_utils.hpp> +using namespace std; +namespace cv { namespace dnn { + ```
Please remove. It's not needed.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/onnx/onnx_importer2.cpp **Change Type:** modified **Context:** PR #27527: Trilu layer **Code Changes:** ```diff @@ -204,6 +204,7 @@ class ONNXImporter2 void parseRange (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto); void parseReduce (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto); void parseRelu (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto); + void parseTrilu (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto); void parseResize (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto); void parseReshape (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto); void parseScatter (LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto); @@ -1554,6 +1555,14 @@ void ONNXImporter2::parseResize(LayerParams& layerParams, const opencv_onnx::Nod addLayer(layerParams, node_proto, ninputs); ```
Please remove redundant empty lines.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/exif.hpp **Change Type:** modified **Context:** PR #27499: Extend image I/O API with metadata support **Review Line:** 181 **Code Changes:** ```diff ExifEntry_t getTag( const ExifTagName tag ) const; + /** + * @brief Get the whole exif buffer + */ + const std::vector<unsigned char>& getData() const; private: std::vector<unsigned char> m_data; ```
m.b. `getRaw()`. Semantic is not clear now.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_base.cpp **Change Type:** modified **Context:** PR #27499: Extend image I/O API with metadata support **Code Changes:** ```diff @@ -58,11 +58,30 @@ BaseImageDecoder::BaseImageDecoder() m_frame_count = 1; } +bool BaseImageDecoder::haveMetadata(ImageMetadataType type) const +{ + if (type == IMAGE_METADATA_EXIF) + return !m_exif.getData().empty(); + return false; +} ```
The function does not return false in any branch. Is it expected? Is the return value redundant?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/loadsave.cpp **Change Type:** modified **Context:** PR #27499: Extend image I/O API with metadata support **Review Line:** 501 **Code Changes:** ```diff ImageDecoder decoder; + if (metadata_types) + metadata_types->clear(); + #ifdef HAVE_GDAL if(flags != IMREAD_UNCHANGED && (flags & IMREAD_LOAD_GDAL) == IMREAD_LOAD_GDAL ){ decoder = GdalDecoder().newDecoder(); @@ -509,6 +583,8 @@ imread_( const String& filename, int flags, OutputArray mat ) CV_CheckTrue(original_ptr == real_mat.data, "Internal imread issue"); success = true; ```
Need a warning, that GDAL does not support metadata for now.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_base.cpp **Change Type:** modified **Context:** PR #27499: Extend image I/O API with metadata support **Review Line:** 77 **Code Changes:** ```diff + if (!exif.empty()) { + Mat exifmat(1, (int)exif.size(), CV_8U, (void*)exif.data()); + return exifmat; + } + } + return Mat(); +} ExifEntry_t BaseImageDecoder::getExifTag(const ExifTagName tag) const { return m_exif.getTag(tag); ```
I propose to add warning to the else branch that metadata of the type other than EXIF is not supported.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/exif.hpp **Change Type:** modified **Context:** PR #27499: Extend image I/O API with metadata support **Review Line:** 181 **Code Changes:** ```diff ExifEntry_t getTag( const ExifTagName tag ) const; + /** + * @brief Get the whole exif buffer + */ + const std::vector<unsigned char>& getData() const; private: std::vector<unsigned char> m_data; ```
it's inside ExifReader, so getData() is quite good name
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_base.cpp **Change Type:** modified **Context:** PR #27499: Extend image I/O API with metadata support **Code Changes:** ```diff @@ -58,11 +58,30 @@ BaseImageDecoder::BaseImageDecoder() m_frame_count = 1; } +bool BaseImageDecoder::haveMetadata(ImageMetadataType type) const +{ + if (type == IMAGE_METADATA_EXIF) + return !m_exif.getData().empty(); + return false; +} ```
added checks in the new commits
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 77 **Code Changes:** ```diff +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); + Mat img(sz, CV_32FC7); + img.at<cv::Vec<float, 7>>(0, 0)[0] = 101.125; + img.at<cv::Vec<float, 7>>(2, 1)[3] = 203.500; ```
How will it work in case of BGR or GRAYSCALE input?
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 77 **Code Changes:** ```diff +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); + Mat img(sz, CV_32FC7); + img.at<cv::Vec<float, 7>>(0, 0)[0] = 101.125; + img.at<cv::Vec<float, 7>>(2, 1)[3] = 203.500; ```
The message looks cryptic. I propose to use CV_CheckXXX macro and add meaningful error message.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 77 **Code Changes:** ```diff +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); + Mat img(sz, CV_32FC7); + img.at<cv::Vec<float, 7>>(0, 0)[0] = 101.125; + img.at<cv::Vec<float, 7>>(2, 1)[3] = 203.500; ```
> How will it work in case of BGR or GRAYSCALE input? It leaves it on previous implementation when channels <= 4
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 77 **Code Changes:** ```diff +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); + Mat img(sz, CV_32FC7); + img.at<cv::Vec<float, 7>>(0, 0)[0] = 101.125; + img.at<cv::Vec<float, 7>>(2, 1)[3] = 203.500; ```
Took a bit more time :-( I probably found a bug in previous code. In ExrDecoder::readData(); when m_native_depth != justcopy, it produce some non-initialized values in the matrix. I will publish that bug later with more details.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 77 **Code Changes:** ```diff +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); + Mat img(sz, CV_32FC7); + img.at<cv::Vec<float, 7>>(0, 0)[0] = 101.125; + img.at<cv::Vec<float, 7>>(2, 1)[3] = 203.500; ```
I propose some change in calcType but it change some behaviour with 2/4-channel images and IMREAD_ANYCOLOR so left it commented out. I did some imread tests with several mode combinations for 1-5 channels. Commited version had the same results for <5 channels as the previous code.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 77 **Code Changes:** ```diff +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); + Mat img(sz, CV_32FC7); + img.at<cv::Vec<float, 7>>(0, 0)[0] = 101.125; + img.at<cv::Vec<float, 7>>(2, 1)[3] = 203.500; ```
I won't do anything new in this request. It works as intended. The found bug I will publish as an issue.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 77 **Code Changes:** ```diff +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); + Mat img(sz, CV_32FC7); + img.at<cv::Vec<float, 7>>(0, 0)[0] = 101.125; + img.at<cv::Vec<float, 7>>(2, 1)[3] = 203.500; ```
I believe we need to test BGR and grayscale modes too. Even if expected behavior is an exception.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 77 **Code Changes:** ```diff +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); + Mat img(sz, CV_32FC7); + img.at<cv::Vec<float, 7>>(0, 0)[0] = 101.125; + img.at<cv::Vec<float, 7>>(2, 1)[3] = 203.500; ```
I did tests with several mode combinations (IMREAD_GRAYSCALE, IMREAD_COLOR, IMREAD_ANYCOLOR, IMREAD_ANYCOLOR | cv::IMREAD_COLOR, IMREAD_ANYDEPTH, IMREAD_ANYDEPTH | cv::IMREAD_COLOR, IMREAD_ANYDEPTH | cv::IMREAD_ANYCOLOR, IMREAD_ANYDEPTH | cv::IMREAD_ANYCOLOR | cv::IMREAD_COLOR, IMREAD_UNCHANGED), up to four channels it behaves as previous version; from five channels it supports only CV_32F and more channels, so IMREAD_UNCHANGED is suggested to use.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 77 **Code Changes:** ```diff +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); + Mat img(sz, CV_32FC7); + img.at<cv::Vec<float, 7>>(0, 0)[0] = 101.125; + img.at<cv::Vec<float, 7>>(2, 1)[3] = 203.500; ```
I can add tests for IMREAD_GRAYSCALE, IMREAD_COLOR.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Code Changes:** ```diff @@ -68,6 +68,36 @@ TEST(Imgcodecs_EXR, readWrite_32FC3) EXPECT_EQ(0, remove(filenameOutput.c_str())); } +TEST(Imgcodecs_EXR, readWrite_32FC7) +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA ```
Temporary file will not be removed if test fail on this or previous asserts. We need to use `EXPECT`.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Code Changes:** ```diff @@ -68,6 +68,36 @@ TEST(Imgcodecs_EXR, readWrite_32FC3) EXPECT_EQ(0, remove(filenameOutput.c_str())); } +TEST(Imgcodecs_EXR, readWrite_32FC7) +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA ```
I am new to gtest so I don't know that EXPECT should be used. I copied the pattern which was in previous tests: readWrite_32FC1, readWrite_32FC3.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Code Changes:** ```diff @@ -68,6 +68,36 @@ TEST(Imgcodecs_EXR, readWrite_32FC3) EXPECT_EQ(0, remove(filenameOutput.c_str())); } +TEST(Imgcodecs_EXR, readWrite_32FC7) +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA ```
``` EXPECT_EQ(img2.type(), img.type()); EXPECT_EQ(img2.size(), img.size()); ```
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Code Changes:** ```diff @@ -68,6 +68,36 @@ TEST(Imgcodecs_EXR, readWrite_32FC3) EXPECT_EQ(0, remove(filenameOutput.c_str())); } +TEST(Imgcodecs_EXR, readWrite_32FC7) +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA ```
I changed that only in my test readWrite_32FC7, but the same is in several other tests.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 74 **Code Changes:** ```diff } +TEST(Imgcodecs_EXR, readWrite_32FC7) +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); ```
imho using a generated cv::Mat here instead of adding an extra test file to opencv_extra is better.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 74 **Code Changes:** ```diff } +TEST(Imgcodecs_EXR, readWrite_32FC7) +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); ```
> ``` > EXPECT_EQ(0, remove(filename.c_str())); > const Mat img3 = cv::imread(filename, IMREAD_GRAYSCALE); > ASSERT_TRUE(img3.empty()); > const Mat img4 = cv::imread(filename, IMREAD_COLOR); > ASSERT_TRUE(img4.empty()); > } > ``` Removing file is before testing grayscale and color in current branch. It prints error message as you can't load multispectral image as GRAYSCALE or COLOR.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 74 **Code Changes:** ```diff } +TEST(Imgcodecs_EXR, readWrite_32FC7) +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); ```
> > ``` > > EXPECT_EQ(0, remove(filename.c_str())); > > const Mat img3 = cv::imread(filename, IMREAD_GRAYSCALE); > > ASSERT_TRUE(img3.empty()); > > const Mat img4 = cv::imread(filename, IMREAD_COLOR); > > ASSERT_TRUE(img4.empty()); > > } > > ``` > > Removing file is before testing grayscale and color in current branch. It prints error message as you can't load multispectral image as GRAYSCALE or COLOR. i fixed it on my code
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 74 **Code Changes:** ```diff } +TEST(Imgcodecs_EXR, readWrite_32FC7) +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); ```
i suggest using this ``` TEST(Imgcodecs_EXR, readWrite_32FC7) { // 0-6 channels (multispectral) const string filename = cv::tempfile(".exr"); const Size sz(3, 5); Mat img = Mat::zeros(sz, CV_MAKETYPE(CV_32F, 7)); img.at<cv::Vec<float, 7>>(0, 0)[0] = 101.125; img.at<cv::Vec<float, 7>>(2, 1)[3] = 203.500; img.at<cv::Vec<float, 7>>(4, 2)[6] = 305.875; ASSERT_TRUE(cv::imwrite(filename, img)); const Mat img2 = cv::imread(filename, IMREAD_UNCHANGED); EXPECT_EQ(img2.type(), img.type()); EXPECT_EQ(img2.size(), img.size()); EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 1e-3); const Mat img3 = cv::imread(filename, IMREAD_GRAYSCALE); ASSERT_TRUE(img3.empty()); const Mat img4 = cv::imread(filename, IMREAD_COLOR); ASSERT_TRUE(img4.empty()); EXPECT_EQ(0, remove(filename.c_str())); } ```
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 74 **Code Changes:** ```diff } +TEST(Imgcodecs_EXR, readWrite_32FC7) +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); ```
``` const Size sz(3, 5); Mat img = Mat::zeros(sz, CV_MAKETYPE(CV_32F, 7)); img.at<cv::Vec<float, 7>>(0, 0)[0] = 101.125; img.at<cv::Vec<float, 7>>(2, 1)[3] = 203.500; img.at<cv::Vec<float, 7>>(4, 2)[6] = 305.875; ASSERT_TRUE(cv::imwrite(filename, img)); ``` generates the same file at https://github.com/opencv/opencv_extra/pull/1262
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_exr.impl.hpp **Change Type:** modified **Context:** PR #27485: imgcodecs: OpenEXR multispectral read/write support **Review Line:** 74 **Code Changes:** ```diff } +TEST(Imgcodecs_EXR, readWrite_32FC7) +{ // 0-6 channels (multispectral) + const string root = cvtest::TS::ptr()->get_data_path(); + const string filenameInput = root + "readwrite/test32FC7.exr"; + const string filenameOutput = cv::tempfile(".exr"); +#ifndef GENERATE_DATA + const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED); +#else + const Size sz(3, 5); ```
I use the same pattern as tests readWrite_32FC1, readWrite_32FC3, readWrite_32FC1_half, readWrite_32FC3_half. It's generate image file upon GENERATE_DATA define. I don't know when it was called with this define so I do the new test readWrite_32FC7 same way.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** apps/interactive-calibration/main.cpp **Change Type:** modified **Context:** PR #27546: Added command line option to select VideoCapture backend **Review Line:** 29 **Code Changes:** ```diff -const std::string keys = +static std::string getVideoIoBackendsString() +{ + std::string result; + auto backs = cv::videoio_registry::getBackends(); + for (const auto& b: backs) + { + if (!result.empty()) + result += ", "; + ```
Not all backends support cameras.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** apps/interactive-calibration/main.cpp **Change Type:** modified **Context:** PR #27546: Added command line option to select VideoCapture backend **Code Changes:** ```diff @@ -6,7 +6,7 @@ #include <opencv2/calib3d.hpp> #include <opencv2/cvconfig.h> #include <opencv2/highgui.hpp> - +#include <opencv2/videoio/registry.hpp> #include <string> #include <vector> @@ -23,9 +23,25 @@ ```
There are backends for video files too. `cb` => `vb`
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** apps/interactive-calibration/main.cpp **Change Type:** modified **Context:** PR #27546: Added command line option to select VideoCapture backend **Review Line:** 29 **Code Changes:** ```diff -const std::string keys = +static std::string getVideoIoBackendsString() +{ + std::string result; + auto backs = cv::videoio_registry::getBackends(); + for (const auto& b: backs) + { + if (!result.empty()) + result += ", "; + ```
I renamed the command line parameter to `vb` and added it to video branch too. Some It could be useful for real videos and cameras available with gstreamer, e.g. pipeline string, IP cameras (ffmpeg rtsp), etc.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_spng.cpp **Change Type:** modified **Context:** PR #27113: Fixing imread() function 16 bit reading png problem with libspng **Review Line:** 648 **Code Changes:** ```diff - for (i = 0; i < size.width; i++, bgr += 3) + for (i = 0; i < size.width; i++, bgr += ncn) { - int t = static_cast<int>(cBGR0 * bgr[0] + 0.5869750977 * bgr[1] + cBGR2 * bgr[2]); - gray[i] = (uchar)t; + if (bgr[0] != bgr[1] || bgr[0] != bgr[2]) + { + gray[i] = (uchar)((cBGR0 * bgr[0] + cBGR1 * bgr[1] + cBGR2 * bgr[2]) >> 15); + } + else + { ```
libpng code is like ``` if (red != green || red != blue) { rgb_error |= 1; /* NOTE: this is the historical approach which simply * truncates the results. */ *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15); } else *(dp++) = red; ``` let me check any performans difference with `gray[i] = (uchar)((cBGR0 * bgr[0] + cBGR1 * bgr[1] + cBGR2 * bgr[2]) >> 15);`
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_animation.cpp **Change Type:** modified **Context:** PR #27113: Fixing imread() function 16 bit reading png problem with libspng **Code Changes:** ```diff @@ -676,7 +676,7 @@ TEST(Imgcodecs_APNG, imread_animation_16u) img = imread(filename, IMREAD_ANYDEPTH); ASSERT_FALSE(img.empty()); EXPECT_TRUE(img.type() == CV_16UC1); - EXPECT_EQ(19519, img.at<ushort>(0, 0)); + EXPECT_EQ(19517, img.at<ushort>(0, 0)); img = imread(filename, IMREAD_COLOR | IMREAD_ANYDEPTH); ASSERT_FALSE(img.empty()); ```
Sounds like wrong rounding somewhere in libspng.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_animation.cpp **Change Type:** modified **Context:** PR #27113: Fixing imread() function 16 bit reading png problem with libspng **Code Changes:** ```diff @@ -676,7 +676,7 @@ TEST(Imgcodecs_APNG, imread_animation_16u) img = imread(filename, IMREAD_ANYDEPTH); ASSERT_FALSE(img.empty()); EXPECT_TRUE(img.type() == CV_16UC1); - EXPECT_EQ(19519, img.at<ushort>(0, 0)); + EXPECT_EQ(19517, img.at<ushort>(0, 0)); img = imread(filename, IMREAD_COLOR | IMREAD_ANYDEPTH); ASSERT_FALSE(img.empty()); ```
last commit is temporarily to show that the spng conversion code is the same as libpng. i temporarily used `if (m_frame_count > 5)` that means the difference caused by cvtColor which i used in apng decoding. ``` [ RUN ] Imgcodecs_APNG.imread_animation_16u /build/precommit_linux64/4.x/opencv/modules/imgcodecs/test/test_animation.cpp:680: Failure Expected equality of these values: 19519 img.at<ushort>(0, 0) Which is: 19517 [ FAILED ] Imgcodecs_APNG.imread_animation_16u (2 ms) ```
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_animation.cpp **Change Type:** modified **Context:** PR #27113: Fixing imread() function 16 bit reading png problem with libspng **Code Changes:** ```diff @@ -676,7 +676,7 @@ TEST(Imgcodecs_APNG, imread_animation_16u) img = imread(filename, IMREAD_ANYDEPTH); ASSERT_FALSE(img.empty()); EXPECT_TRUE(img.type() == CV_16UC1); - EXPECT_EQ(19519, img.at<ushort>(0, 0)); + EXPECT_EQ(19517, img.at<ushort>(0, 0)); img = imread(filename, IMREAD_COLOR | IMREAD_ANYDEPTH); ASSERT_FALSE(img.empty()); ```
If you find it appropriate, I can add a to-do note and let's merge this. I'll work on apng and try to find a solution for this difference later.
You are an expert OpenCV code reviewer specializing in documentation and code clarity. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_png.cpp **Change Type:** modified **Context:** PR #27113: Fixing imread() function 16 bit reading png problem with libspng **Review Line:** 197 **Code Changes:** ```diff + EXPECT_PRED_FORMAT2(cvtest::MatComparator(1, 0), imread(filename, IMREAD_COLOR_RGB), gt_256); + EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), imread(filename, IMREAD_COLOR_RGB | IMREAD_ANYDEPTH), gt_258); + +// Uncomment this block to write out the decoded images for visual/manual inspection +// or for regenerating expected ground truth PNGs (for example, after changing decoder logic). +#if 0 + imwrite(filename + "_0.png", imread(filename, IMREAD_GRAYSCALE)); + imwrite(filename + "_1.png", imread(filename, IMREAD_COLOR)); + imwrite(filename + "_2.png", imread(filename, IMREAD_ANYDEPTH)); + imwrite(filename + "_3.png", imread(filename, IMREAD_COLOR | IMREAD_ANYDEPTH)); + imwrite(filename + "_256.png", imread(filename, IMREAD_COLOR_RGB)); ```
I forgot to mention that i used this commented blocks to be sure libspng and libpng loads exact same data. first i set 1 the upper block with OpenCV compiled with libpng. and for each pngsuite file saved what loaded with each flag. then set 0 the upper block and set 1 the lower block with OpenCV compiled with libspng...
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_avif.cpp **Change Type:** modified **Context:** PR #27506: Fix XMP write and discarded return value. **Code Changes:** ```diff @@ -116,12 +116,27 @@ AvifImageUniquePtr ConvertToAvif(const cv::Mat &img, bool lossless, int bit_dept const std::vector<uchar>& metadata_exif = metadata[IMAGE_METADATA_EXIF]; const std::vector<uchar>& metadata_xmp = metadata[IMAGE_METADATA_XMP]; const std::vector<uchar>& metadata_iccp = metadata[IMAGE_METADATA_ICCP]; +#if AVIF_VERSION_MAJOR >= 1 + if ((!metadata_exif.empty() && + avifImageSetMetadataExif(result, (const uint8_t *)metadata_exif.data(), + metadata_exif.size()) != AVIF_RESULT_OK) || + (!metadata_xmp.empty() && + avifImageSetMetadataXMP(result, (const uint8_t *)metadata_xmp.data(), ```
Looks like a typo: metadata_xmp.data() should be used
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_avif.cpp **Change Type:** modified **Context:** PR #27506: Fix XMP write and discarded return value. **Code Changes:** ```diff @@ -116,12 +116,27 @@ AvifImageUniquePtr ConvertToAvif(const cv::Mat &img, bool lossless, int bit_dept const std::vector<uchar>& metadata_exif = metadata[IMAGE_METADATA_EXIF]; const std::vector<uchar>& metadata_xmp = metadata[IMAGE_METADATA_XMP]; const std::vector<uchar>& metadata_iccp = metadata[IMAGE_METADATA_ICCP]; +#if AVIF_VERSION_MAJOR >= 1 + if ((!metadata_exif.empty() && + avifImageSetMetadataExif(result, (const uint8_t *)metadata_exif.data(), + metadata_exif.size()) != AVIF_RESULT_OK) || + (!metadata_xmp.empty() && + avifImageSetMetadataXMP(result, (const uint8_t *)metadata_xmp.data(), ```
Looks like a typo: metadata_iccp.data() should be used
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/src/geometry.cpp **Change Type:** modified **Context:** PR #26974: Issue 26972: Proper treatment of float values in intersectConvexConvex **Code Changes:** ```diff @@ -330,20 +330,20 @@ static LineSegmentIntersection parallelInt( Point2f a, Point2f b, Point2f c, Poi static LineSegmentIntersection intersectLineSegments( Point2f a, Point2f b, Point2f c, Point2f d, Point2f& p, Point2f& q ) { - double denom = (a.x - b.x) * (double)(d.y - c.y) - (a.y - b.y) * (double)(d.x - c.x); + double denom = ((double)a.x - b.x) * ((double)d.y - c.y) - ((double)a.y - b.y) * ((double)d.x - c.x); // If denom is zero, then segments are parallel: handle separately. if( denom == 0. ) return parallelInt(a, b, c, d, p, q); ```
I agree that it's not correct to compare floats/doubles on equality, but why do you change the first line of conditions? I would say that the correct check is: ``` return s < 0. || s > 1. || t < 0. || t > 1. ? LS_NO_INTERSECTION : fabs(num) < eps || fabs(s-1.) < eps || fabs(t) < eps || fabs(t-1.) < eps ? LS_ENDPOINT_INTERSECTION : LS_SINGLE_INTERSECTION; ```
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/src/geometry.cpp **Change Type:** modified **Context:** PR #26974: Issue 26972: Proper treatment of float values in intersectConvexConvex **Code Changes:** ```diff @@ -330,20 +330,20 @@ static LineSegmentIntersection parallelInt( Point2f a, Point2f b, Point2f c, Poi static LineSegmentIntersection intersectLineSegments( Point2f a, Point2f b, Point2f c, Point2f d, Point2f& p, Point2f& q ) { - double denom = (a.x - b.x) * (double)(d.y - c.y) - (a.y - b.y) * (double)(d.x - c.x); + double denom = ((double)a.x - b.x) * ((double)d.y - c.y) - ((double)a.y - b.y) * ((double)d.x - c.x); // If denom is zero, then segments are parallel: handle separately. if( denom == 0. ) return parallelInt(a, b, c, d, p, q); ```
The numerical error can happen on both sides, and in particular the one "outside" the line actually caused the problem that the polygon intersection was not detected (see unit test). The one on the inside is probably harmless and could be treated either way, as endpoint and single intersection are "intersections". For symmetry reasons I also updated the second check.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgproc/src/geometry.cpp **Change Type:** modified **Context:** PR #26974: Issue 26972: Proper treatment of float values in intersectConvexConvex **Code Changes:** ```diff @@ -330,20 +330,20 @@ static LineSegmentIntersection parallelInt( Point2f a, Point2f b, Point2f c, Poi static LineSegmentIntersection intersectLineSegments( Point2f a, Point2f b, Point2f c, Point2f d, Point2f& p, Point2f& q ) { - double denom = (a.x - b.x) * (double)(d.y - c.y) - (a.y - b.y) * (double)(d.x - c.x); + double denom = ((double)a.x - b.x) * ((double)d.y - c.y) - ((double)a.y - b.y) * ((double)d.x - c.x); // If denom is zero, then segments are parallel: handle separately. if( denom == 0. ) return parallelInt(a, b, c, d, p, q); ```
With 1e-5 the unit test was still failing, so I went up to 1e-4. To keep it as small as possible, not more than that.
You are an expert OpenCV code reviewer specializing in header file design and interface. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/include/opencv2/imgcodecs.hpp **Change Type:** modified **Context:** PR #27127: Changes about when APNG has a hidden frame **Code Changes:** ```diff @@ -277,6 +277,8 @@ struct CV_EXPORTS_W_SIMPLE Animation CV_PROP_RW std::vector<int> durations; //! Vector of frames, where each Mat represents a single frame. CV_PROP_RW std::vector<Mat> frames; + //! image that can be used for the format in addition to the animation or if animation is not supported in the reader (like in PNG). + CV_PROP_RW Mat still_image; /** @brief Constructs an Animation object with optional loop count and background color. ```
Maybe: ``` //! image that can be used for the format in addition to the animation or if animation is not supported in the reader (like in PNG). CV_PROP_RW cv::Mat still_image; ```
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_png.cpp **Change Type:** modified **Context:** PR #27127: Changes about when APNG has a hidden frame **Review Line:** 1653 **Code Changes:** ```diff + APNGFrame apngFrame; + Mat tmp; + if (animation.still_image.depth() == CV_16U) + { + animation.still_image.convertTo(tmp, CV_8U, 1.0 / 255); + } + else + tmp = animation.still_image; + + cvtColor(tmp, tmp, COLOR_BGRA2RGBA); + apngFrame.setMat(tmp); ```
Most probably the conversion is not needed, if the animation patch in 16-bit too.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_animation.cpp **Change Type:** modified **Context:** PR #27127: Changes about when APNG has a hidden frame **Code Changes:** ```diff @@ -636,6 +636,51 @@ TEST(Imgcodecs_APNG, imencode_animation) } } +TEST(Imgcodecs_APNG, animation_has_hidden_frame) +{ + // Set the path to the test image directory and filename for loading. + const string root = cvtest::TS::ptr()->get_data_path(); + const string filename = root + "readwrite/033.png"; + Animation animation1, animation2, animation3; ```
Was it alpha blending overflow issue?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_png.cpp **Change Type:** modified **Context:** PR #27127: Changes about when APNG has a hidden frame **Review Line:** 1653 **Code Changes:** ```diff + APNGFrame apngFrame; + Mat tmp; + if (animation.still_image.depth() == CV_16U) + { + animation.still_image.convertTo(tmp, CV_8U, 1.0 / 255); + } + else + tmp = animation.still_image; + + cvtColor(tmp, tmp, COLOR_BGRA2RGBA); + apngFrame.setMat(tmp); ```
currently APNG encoder converts 16U Mats to 8U before saving. no support for writing 16 bit APNG yet.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_animation.cpp **Change Type:** modified **Context:** PR #27127: Changes about when APNG has a hidden frame **Code Changes:** ```diff @@ -636,6 +636,51 @@ TEST(Imgcodecs_APNG, imencode_animation) } } +TEST(Imgcodecs_APNG, animation_has_hidden_frame) +{ + // Set the path to the test image directory and filename for loading. + const string root = cvtest::TS::ptr()->get_data_path(); + const string filename = root + "readwrite/033.png"; + Animation animation1, animation2, animation3; ```
the old values was for the first frame before. now the first frame is `still_image `in the test file.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/test/test_animation.cpp **Change Type:** modified **Context:** PR #27127: Changes about when APNG has a hidden frame **Code Changes:** ```diff @@ -636,6 +636,51 @@ TEST(Imgcodecs_APNG, imencode_animation) } } +TEST(Imgcodecs_APNG, animation_has_hidden_frame) +{ + // Set the path to the test image directory and filename for loading. + const string root = cvtest::TS::ptr()->get_data_path(); + const string filename = root + "readwrite/033.png"; + Animation animation1, animation2, animation3; ```
the test was comparing correct values before. and comparing correct values now.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_png.cpp **Change Type:** modified **Context:** PR #27127: Changes about when APNG has a hidden frame **Code Changes:** ```diff @@ -156,7 +156,7 @@ bool APNGFrame::setMat(const cv::Mat& src, unsigned delayNum, unsigned delayDen) if (!src.empty()) { - png_uint_32 rowbytes = src.depth() == CV_16U ? src.cols * src.channels() * 2 : src.cols * src.channels(); + png_uint_32 rowbytes = src.cols * (uint32_t)src.elemSize(); _width = src.cols; _height = src.rows; _colorType = src.channels() == 1 ? PNG_COLOR_TYPE_GRAY : src.channels() == 3 ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGB_ALPHA; @@ -416,14 +416,17 @@ bool PngDecoder::readData( Mat& img ) ```
The line changes simple imread behavior, right? I propose to return still image in case if user reads animation as single frame. It's APNG design decision and also presumes current OpenCV behaviour.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_png.cpp **Change Type:** modified **Context:** PR #27127: Changes about when APNG has a hidden frame **Review Line:** 436 **Code Changes:** ```diff - m_buf_pos -= 8; } else m_mat_next.copyTo(mat_cur); @@ -433,9 +436,6 @@ bool PngDecoder::readData( Mat& img ) if (!processing_start((void*)&frameRaw, mat_cur)) return false; - if(setjmp(png_jmpbuf(m_png_ptr))) - return false; - ```
i think we can delete this line which called in `processing_start()` ``` bool PngDecoder::processing_start(void* frame_ptr, const Mat& img) { if (!InitPngPtr()) return false; if (setjmp(png_jmpbuf(m_png_ptr))) return false; . . . } ```
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/imgcodecs/src/grfmt_png.cpp **Change Type:** modified **Context:** PR #27127: Changes about when APNG has a hidden frame **Review Line:** 1653 **Code Changes:** ```diff + APNGFrame apngFrame; + Mat tmp; + if (animation.still_image.depth() == CV_16U) + { + animation.still_image.convertTo(tmp, CV_8U, 1.0 / 255); + } + else + tmp = animation.still_image; + + cvtColor(tmp, tmp, COLOR_BGRA2RGBA); + apngFrame.setMat(tmp); ```
Added issue to our tracker to make the limitation more obvious.