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/dnn/src/layers/elementwise_layers.cpp **Change Type:** modified **Context:** PR #25881: dnn: optimize activations with v_exp **Code Changes:** ```diff @@ -859,12 +859,6 @@ struct GeluFunctor : public BaseFunctor { one = vx_setall_f32(1.0f), reciprocal_sqrt2 = vx_setall_f32(M_SQRT1_2); for (; i <= len - vlanes; i += vlanes) { - if (i + vlanes > len) { - if (i == 0 || i == len) { - break; - } - i = len - vlanes; - } ```
`exp` call is not needed, if x == 0.
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/elementwise_layers.cpp **Change Type:** modified **Context:** PR #25881: dnn: optimize activations with v_exp **Code Changes:** ```diff @@ -859,12 +859,6 @@ struct GeluFunctor : public BaseFunctor { one = vx_setall_f32(1.0f), reciprocal_sqrt2 = vx_setall_f32(M_SQRT1_2); for (; i <= len - vlanes; i += vlanes) { - if (i + vlanes > len) { - if (i == 0 || i == len) { - break; - } - i = len - vlanes; - } ```
The same for the constant. It's used several times. I propose to introduce named constant with description and use it.
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/elementwise_layers.cpp **Change Type:** modified **Context:** PR #25881: dnn: optimize activations with v_exp **Code Changes:** ```diff @@ -859,12 +859,6 @@ struct GeluFunctor : public BaseFunctor { one = vx_setall_f32(1.0f), reciprocal_sqrt2 = vx_setall_f32(M_SQRT1_2); for (; i <= len - vlanes; i += vlanes) { - if (i + vlanes > len) { - if (i == 0 || i == len) { - break; - } - i = len - vlanes; - } ```
Added source.
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/elementwise_layers.cpp **Change Type:** modified **Context:** PR #25881: dnn: optimize activations with v_exp **Code Changes:** ```diff @@ -859,12 +859,6 @@ struct GeluFunctor : public BaseFunctor { one = vx_setall_f32(1.0f), reciprocal_sqrt2 = vx_setall_f32(M_SQRT1_2); for (; i <= len - vlanes; i += vlanes) { - if (i + vlanes > len) { - if (i == 0 || i == len) { - break; - } - i = len - vlanes; - } ```
Guarded the constant with an anonymous namespace.
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/elementwise_layers.cpp **Change Type:** modified **Context:** PR #25881: dnn: optimize activations with v_exp **Code Changes:** ```diff @@ -859,12 +859,6 @@ struct GeluFunctor : public BaseFunctor { one = vx_setall_f32(1.0f), reciprocal_sqrt2 = vx_setall_f32(M_SQRT1_2); for (; i <= len - vlanes; i += vlanes) { - if (i + vlanes > len) { - if (i == 0 || i == len) { - break; - } - i = len - vlanes; - } ```
Looks like the extra conditions are redundant. You can replace for loop with: ``` for (; i < len - vlanes; i += vlanes) ``` It's applicable for all cases in the PR.
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/elementwise_layers.cpp **Change Type:** modified **Context:** PR #25881: dnn: optimize activations with v_exp **Code Changes:** ```diff @@ -859,12 +859,6 @@ struct GeluFunctor : public BaseFunctor { one = vx_setall_f32(1.0f), reciprocal_sqrt2 = vx_setall_f32(M_SQRT1_2); for (; i <= len - vlanes; i += vlanes) { - if (i + vlanes > len) { - if (i == 0 || i == len) { - break; - } - i = len - vlanes; - } ```
The idea is to also apply intrinsics on the tail by fetching the last vlanes elements, although it may introduce duplicated computation. This trick is borrowed from Halide. Below is an example. Assume vlanes=4 and we have 7 elements. Without this trick, the last 3 elements have to be processed by a extra for loop. With this trick, it works like two times of loop, both of which process 4 elements, but the second loop takes elements of index 4567, while the first takes 1234 (index 4 element is processed twice).
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/elementwise_layers.cpp **Change Type:** modified **Context:** PR #25881: dnn: optimize activations with v_exp **Code Changes:** ```diff @@ -859,12 +859,6 @@ struct GeluFunctor : public BaseFunctor { one = vx_setall_f32(1.0f), reciprocal_sqrt2 = vx_setall_f32(M_SQRT1_2); for (; i <= len - vlanes; i += vlanes) { - if (i + vlanes > len) { - if (i == 0 || i == len) { - break; - } - i = len - vlanes; - } ```
I got the point. The problem is that you introduce several extra conditions in the loop. I propose to extract the condition and add vectorized tail computation with overlap after the loop.
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/elementwise_layers.cpp **Change Type:** modified **Context:** PR #25881: dnn: optimize activations with v_exp **Code Changes:** ```diff @@ -859,12 +859,6 @@ struct GeluFunctor : public BaseFunctor { one = vx_setall_f32(1.0f), reciprocal_sqrt2 = vx_setall_f32(M_SQRT1_2); for (; i <= len - vlanes; i += vlanes) { - if (i + vlanes > len) { - if (i == 0 || i == len) { - break; - } - i = len - vlanes; - } ```
> Problem is spreading over codebase. I volunteer to take care of this if there is a list of this problem.
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/core/src/hal_replacement.hpp **Change Type:** modified **Context:** PR #25936: HAL for dot product added **Review Line:** 916 **Code Changes:** ```diff + * @param type Data type of both images, for example CV_8U or CV_32F + * @param dot_val Pointer to resulting dot product value + * @return int + */ +inline int hal_ni_dotProduct(const uchar* a_data, size_t a_step, const uchar* b_data, size_t b_step, int width, int height, + int type, double *dot_val) +{ return CV_HAL_ERROR_NOT_IMPLEMENTED; } + +//! @cond IGNORED +#define cv_hal_dotProduct hal_ni_dotProduct +//! @endcond ```
can we return int64_t instead of double?
You are an expert OpenCV code reviewer specializing in API design and compatibility. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/src/hal_replacement.hpp **Change Type:** modified **Context:** PR #25936: HAL for dot product added **Review Line:** 916 **Code Changes:** ```diff + * @param type Data type of both images, for example CV_8U or CV_32F + * @param dot_val Pointer to resulting dot product value + * @return int + */ +inline int hal_ni_dotProduct(const uchar* a_data, size_t a_step, const uchar* b_data, size_t b_step, int width, int height, + int type, double *dot_val) +{ return CV_HAL_ERROR_NOT_IMPLEMENTED; } + +//! @cond IGNORED +#define cv_hal_dotProduct hal_ni_dotProduct +//! @endcond ```
Public interface: `double Mat::dot(InputArray _mat) const`. `int64_t` looks strange. Also the `::dot()` may handle floats and doubles.
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/src/matmul.dispatch.cpp **Change Type:** modified **Context:** PR #25936: HAL for dot product added **Review Line:** 998 **Code Changes:** ```diff @@ -995,9 +995,18 @@ double Mat::dot(InputArray _mat) const CV_INSTRUMENT_REGION(); Mat mat = _mat.getMat(); + CV_Assert_N( mat.type() == type(), mat.size == size); + int cn = channels(); + if (this->dims <= 2) + { + double product = 0; ```
`CV_Assert_N` is deprecated due to malformed or useless error messages. Use `CV_Check*` instead.
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/test/test_arithm.cpp **Change Type:** modified **Context:** PR #25902: Mask support with CV_Bool in ts and core **Code Changes:** ```diff @@ -2462,23 +2462,22 @@ TEST(Compare, regression_16F_do_not_crash) EXPECT_NO_THROW(cv::compare(mat1, mat2, dst, cv::CMP_EQ)); } - TEST(Core_minMaxIdx, regression_9207_1) { const int rows = 4; const int cols = 3; uchar mask_[rows*cols] = { ```
We should not modify existed tests. We should add new tests for new types support.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/core/test/test_arithm.cpp **Change Type:** modified **Context:** PR #25902: Mask support with CV_Bool in ts and core **Code Changes:** ```diff @@ -2462,23 +2462,22 @@ TEST(Compare, regression_16F_do_not_crash) EXPECT_NO_THROW(cv::compare(mat1, mat2, dst, cv::CMP_EQ)); } - TEST(Core_minMaxIdx, regression_9207_1) { const int rows = 4; const int cols = 3; uchar mask_[rows*cols] = { ```
I would make it random, 8U or bool
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/core/include/opencv2/core.hpp **Change Type:** modified **Context:** PR #25902: Mask support with CV_Bool in ts and core **Code Changes:** ```diff @@ -352,8 +352,8 @@ result of an incorrect sign in the case of overflow. @param src2 second input array or a scalar. @param dst output array that has the same size and number of channels as the input array(s); the depth is defined by dtype or src1/src2. -@param mask optional operation mask - 8-bit single channel array, that specifies elements of the -output array to be changed. +@param mask optional operation mask - CV_8U, CV_8S or CV_Bool single channel array, that specifies elements +of the output array to be changed. @param dtype optional depth of the output array (see the discussion below). @sa subtract, addWeighted, scaleAdd, Mat::convertTo ```
why not add CV_8S as yet another option, since we are doing changes anyway
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/test/test_arithm.cpp **Change Type:** modified **Context:** PR #25902: Mask support with CV_Bool in ts and core **Code Changes:** ```diff @@ -2462,23 +2462,22 @@ TEST(Compare, regression_16F_do_not_crash) EXPECT_NO_THROW(cv::compare(mat1, mat2, dst, cv::CMP_EQ)); } - TEST(Core_minMaxIdx, regression_9207_1) { const int rows = 4; const int cols = 3; uchar mask_[rows*cols] = { ```
Added couple of more tests.
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 #25814: add getFrameCount() member function to BaseImageDecoder **Code Changes:** ```diff @@ -1263,26 +1263,8 @@ void ImageCollection::Impl::init(String const& filename, int flags) { m_decoder->setSource(filename); CV_Assert(m_decoder->readHeader()); - // count the pages of the image collection - size_t count = 1; - while(m_decoder->nextPage()) count++; - - m_size = count; + m_size = m_decoder->getFrameCount(); ```
It should be removed then, right? As soon as following `m_size = count;`
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 #25814: add getFrameCount() member function to BaseImageDecoder **Code Changes:** ```diff @@ -1263,26 +1263,8 @@ void ImageCollection::Impl::init(String const& filename, int flags) { m_decoder->setSource(filename); CV_Assert(m_decoder->readHeader()); - // count the pages of the image collection - size_t count = 1; - while(m_decoder->nextPage()) count++; - - m_size = count; + m_size = m_decoder->getFrameCount(); ```
Also there is GDAL branch bellow.
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 #25814: add getFrameCount() member function to BaseImageDecoder **Code Changes:** ```diff @@ -1263,26 +1263,8 @@ void ImageCollection::Impl::init(String const& filename, int flags) { m_decoder->setSource(filename); CV_Assert(m_decoder->readHeader()); - // count the pages of the image collection - size_t count = 1; - while(m_decoder->nextPage()) count++; - - m_size = count; + m_size = m_decoder->getFrameCount(); ```
``` m_size = m_decoder->getFrameCount(); if (m_size > 0) { m_pages.resize(m_size); return; } ``` if `m_frame_count` set by `m_decoder->readHeader()` set m_size and return.. otherways the following code needed. To remove the code below, we need to make sure that all decoders set the `m_frame_count` variable.
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 #25814: add getFrameCount() member function to BaseImageDecoder **Code Changes:** ```diff @@ -1263,26 +1263,8 @@ void ImageCollection::Impl::init(String const& filename, int flags) { m_decoder->setSource(filename); CV_Assert(m_decoder->readHeader()); - // count the pages of the image collection - size_t count = 1; - while(m_decoder->nextPage()) count++; - - m_size = count; + m_size = m_decoder->getFrameCount(); ```
`m_frame_count = 1;` default for all decoders except AvifDecoder and TiffDecoder.
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 #25814: add getFrameCount() member function to BaseImageDecoder **Review Line:** 1272 **Code Changes:** ```diff @@ -1263,26 +1263,8 @@ void ImageCollection::Impl::init(String const& filename, int flags) { m_decoder->setSource(filename); CV_Assert(m_decoder->readHeader()); - // count the pages of the image collection - size_t count = 1; - while(m_decoder->nextPage()) count++; - - m_size = count; + m_size = m_decoder->getFrameCount(); m_pages.resize(m_size); - // Reinitialize the decoder because we advanced to the last page while counting the pages of the image -#ifdef HAVE_GDAL - if (m_flags != IMREAD_UNCHANGED && (m_flags & IMREAD_LOAD_GDAL) == IMREAD_LOAD_GDAL) { - m_decoder = GdalDecoder().newDecoder(); ```
You now need a GDAL implementation right?
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 #25814: add getFrameCount() member function to BaseImageDecoder **Review Line:** 1272 **Code Changes:** ```diff @@ -1263,26 +1263,8 @@ void ImageCollection::Impl::init(String const& filename, int flags) { m_decoder->setSource(filename); CV_Assert(m_decoder->readHeader()); - // count the pages of the image collection - size_t count = 1; - while(m_decoder->nextPage()) count++; - - m_size = count; + m_size = m_decoder->getFrameCount(); m_pages.resize(m_size); - // Reinitialize the decoder because we advanced to the last page while counting the pages of the image -#ifdef HAVE_GDAL - if (m_flags != IMREAD_UNCHANGED && (m_flags & IMREAD_LOAD_GDAL) == IMREAD_LOAD_GDAL) { - m_decoder = GdalDecoder().newDecoder(); ```
current GDAL decoder reads only one image. deleted lines changes nothing for actual GDAL decoder. imho adding overridden `nextPage()` to GDAL decoder should be in scope of other PR
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/include/opencv2/imgcodecs.hpp **Change Type:** modified **Context:** PR #25814: add getFrameCount() member function to BaseImageDecoder **Code Changes:** ```diff @@ -305,11 +305,13 @@ The function imreadmulti loads a specified range from a multi-page image from th */ CV_EXPORTS_W bool imreadmulti(const String& filename, CV_OUT std::vector<Mat>& mats, int start, int count, int flags = IMREAD_ANYCOLOR); -/** @brief Returns the number of images inside the give file +/** @brief Returns the number of images inside the given file -The function imcount will return the number of pages in a multi-page image, or 1 for single-page images +The function imcount returns the number of pages in a multi-page image (e.g. TIFF), the number of frames in an animation (e.g. AVIF), and 1 otherwise. +If the image cannot be decoded, 0 is returned. ```
This comment used the future tense, let's make it simpler: The function imcount returns the number of pages in a multi-page image (e.g. TIFF), the number of frames in an animation (e.g. AVIF), and 1 otherwise. If the image cannot be decoded, 0 is returned.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/videoio/src/cap_obsensor_capture.cpp **Change Type:** modified **Context:** PR #23237: videoio: add support for Orbbec Femto Mega RGB-D camera **Review Line:** 39 **Code Changes:** ```diff static const obsensor::StreamProfile depthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y16}; - static const obsensor::StreamProfile gemini2depthProfile = {1280, 800, 30, obsensor::FRAME_FORMAT_Y14}; - static const obsensor::StreamProfile astra2depthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile gemini2DepthProfile = {1280, 800, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile astra2DepthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile megaColorProfile = {1280, 720, 30, obsensor::FRAME_FORMAT_MJPG}; + static const obsensor::StreamProfile megaDepthProfile = {640, 576, 30, obsensor::FRAME_FORMAT_Y16}; streamChannelGroup_ = obsensor::getStreamChannelGroup(index); if (!streamChannelGroup_.empty()) @@ -46,11 +48,17 @@ VideoCapture_obsensor::VideoCapture_obsensor(int index) : isOpened_(false) ```
Why Motion JPEG? I propose to preserve the best quality by default, if possible.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/videoio/src/cap_obsensor_capture.cpp **Change Type:** modified **Context:** PR #23237: videoio: add support for Orbbec Femto Mega RGB-D camera **Review Line:** 39 **Code Changes:** ```diff static const obsensor::StreamProfile depthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y16}; - static const obsensor::StreamProfile gemini2depthProfile = {1280, 800, 30, obsensor::FRAME_FORMAT_Y14}; - static const obsensor::StreamProfile astra2depthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile gemini2DepthProfile = {1280, 800, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile astra2DepthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile megaColorProfile = {1280, 720, 30, obsensor::FRAME_FORMAT_MJPG}; + static const obsensor::StreamProfile megaDepthProfile = {640, 576, 30, obsensor::FRAME_FORMAT_Y16}; streamChannelGroup_ = obsensor::getStreamChannelGroup(index); if (!streamChannelGroup_.empty()) @@ -46,11 +48,17 @@ VideoCapture_obsensor::VideoCapture_obsensor(int index) : isOpened_(false) ```
For platform compatibility reasons, the YUYV format does not pass on some of the lower performance platforms we tested.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/videoio/src/cap_obsensor_capture.cpp **Change Type:** modified **Context:** PR #23237: videoio: add support for Orbbec Femto Mega RGB-D camera **Review Line:** 39 **Code Changes:** ```diff static const obsensor::StreamProfile depthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y16}; - static const obsensor::StreamProfile gemini2depthProfile = {1280, 800, 30, obsensor::FRAME_FORMAT_Y14}; - static const obsensor::StreamProfile astra2depthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile gemini2DepthProfile = {1280, 800, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile astra2DepthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile megaColorProfile = {1280, 720, 30, obsensor::FRAME_FORMAT_MJPG}; + static const obsensor::StreamProfile megaDepthProfile = {640, 576, 30, obsensor::FRAME_FORMAT_Y16}; streamChannelGroup_ = obsensor::getStreamChannelGroup(index); if (!streamChannelGroup_.empty()) @@ -46,11 +48,17 @@ VideoCapture_obsensor::VideoCapture_obsensor(int index) : isOpened_(false) ```
I propose to make MJPEG optional. (M)JPEG makes frames a bit blury. It affects feature detectors.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/videoio/src/cap_obsensor_capture.cpp **Change Type:** modified **Context:** PR #23237: videoio: add support for Orbbec Femto Mega RGB-D camera **Review Line:** 39 **Code Changes:** ```diff static const obsensor::StreamProfile depthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y16}; - static const obsensor::StreamProfile gemini2depthProfile = {1280, 800, 30, obsensor::FRAME_FORMAT_Y14}; - static const obsensor::StreamProfile astra2depthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile gemini2DepthProfile = {1280, 800, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile astra2DepthProfile = {640, 480, 30, obsensor::FRAME_FORMAT_Y14}; + static const obsensor::StreamProfile megaColorProfile = {1280, 720, 30, obsensor::FRAME_FORMAT_MJPG}; + static const obsensor::StreamProfile megaDepthProfile = {640, 576, 30, obsensor::FRAME_FORMAT_Y16}; streamChannelGroup_ = obsensor::getStreamChannelGroup(index); if (!streamChannelGroup_.empty()) @@ -46,11 +48,17 @@ VideoCapture_obsensor::VideoCapture_obsensor(int index) : isOpened_(false) ```
MJPEG helps to save bandwidth (and connect multiple cameras). On other cameras some formats+fps are not available without compression (especially FHD+) - MJPEG or H264. BTW, MJPG is already used before this patch, see `colorProfile` on the line 35.
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/videoio/include/opencv2/videoio.hpp **Change Type:** modified **Context:** PR #25874: `videoio`: fix `cv::VideoWriter` with FFmpeg encapsulation timestamps **Code Changes:** ```diff @@ -211,6 +211,8 @@ enum VideoCaptureProperties { CAP_PROP_CODEC_EXTRADATA_INDEX = 68, //!< Positive index indicates that returning extra data is supported by the video back end. This can be retrieved as cap.retrieve(data, <returned index>). E.g. When reading from a h264 encoded RTSP stream, the FFmpeg backend could return the SPS and/or PPS if available (if sent in reply to a DESCRIBE request), from calls to cap.retrieve(data, <returned index>). CAP_PROP_FRAME_TYPE = 69, //!< (read-only) FFmpeg back-end only - Frame type ascii code (73 = 'I', 80 = 'P', 66 = 'B' or 63 = '?' if unknown) of the most recently read frame. CAP_PROP_N_THREADS = 70, //!< (**open-only**) Set the maximum number of threads to use. Use 0 to use as many threads as CPU cores (applicable for FFmpeg back-end only). + CAP_PROP_PTS = 71, //!< (read-only) FFmpeg back-end only - presentation timestamp of the most recently read frame using the FPS time base. e.g. fps = 25, VideoCapture::get(\ref CAP_PROP_PTS) = 3, presentation time = 3/25 seconds. + CAP_PROP_DTS_DELAY = 72, //!< (read-only) FFmpeg back-end only - maximum difference between presentation (pts) and decompression timestamps (dts) using FPS time base. e.g. delay is maximum when frame_num = 0, if true, VideoCapture::get(\ref CAP_PROP_PTS) = 0 and VideoCapture::get(\ref CAP_PROP_DTS_DELAY) = 2, dts = -2. Non zero values usually imply the stream is encoded using B-frames which are not decoded in presentation order. #ifndef CV_DOXYGEN CV__CAP_PROP_LATEST #endif @@ -230,8 +232,10 @@ enum VideoWriterProperties { ```
It'll be great to add some references to `cv::VideoCapture` properties. It's not obvious, if the properties are needed and how to extract them from the encoded stream.
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/videoio/include/opencv2/videoio.hpp **Change Type:** modified **Context:** PR #25874: `videoio`: fix `cv::VideoWriter` with FFmpeg encapsulation timestamps **Code Changes:** ```diff @@ -211,6 +211,8 @@ enum VideoCaptureProperties { CAP_PROP_CODEC_EXTRADATA_INDEX = 68, //!< Positive index indicates that returning extra data is supported by the video back end. This can be retrieved as cap.retrieve(data, <returned index>). E.g. When reading from a h264 encoded RTSP stream, the FFmpeg backend could return the SPS and/or PPS if available (if sent in reply to a DESCRIBE request), from calls to cap.retrieve(data, <returned index>). CAP_PROP_FRAME_TYPE = 69, //!< (read-only) FFmpeg back-end only - Frame type ascii code (73 = 'I', 80 = 'P', 66 = 'B' or 63 = '?' if unknown) of the most recently read frame. CAP_PROP_N_THREADS = 70, //!< (**open-only**) Set the maximum number of threads to use. Use 0 to use as many threads as CPU cores (applicable for FFmpeg back-end only). + CAP_PROP_PTS = 71, //!< (read-only) FFmpeg back-end only - presentation timestamp of the most recently read frame using the FPS time base. e.g. fps = 25, VideoCapture::get(\ref CAP_PROP_PTS) = 3, presentation time = 3/25 seconds. + CAP_PROP_DTS_DELAY = 72, //!< (read-only) FFmpeg back-end only - maximum difference between presentation (pts) and decompression timestamps (dts) using FPS time base. e.g. delay is maximum when frame_num = 0, if true, VideoCapture::get(\ref CAP_PROP_PTS) = 0 and VideoCapture::get(\ref CAP_PROP_DTS_DELAY) = 2, dts = -2. Non zero values usually imply the stream is encoded using B-frames which are not decoded in presentation order. #ifndef CV_DOXYGEN CV__CAP_PROP_LATEST #endif @@ -230,8 +232,10 @@ enum VideoWriterProperties { ```
The properties should be provided by or calculated from the parameters provided to the external encoder. Is this clearer in the below? ``` VIDEOWRITER_PROP_PTS_INDEX = 12, //!< Specifies the frame presentation index for each frame when encapsulating raw video (\ref VIDEOWRITER_PROP_RAW_VIDEO != 0). This property is **only** necessary when encapsulating **externally** encoded video where the decoding order differs from the presentation order, such as in GOP patterns with bi-directional B-frames. The value should be provided by your external encoder and is equivalent to dividing the current position of the video file (\ref CAP_PROP_POS_MSEC) by the duration (i.e. 1000.0/VideoCapture::get(\ref CAP_PROP_FPS) if the frame rate is fixed) of each frame. FFmpeg back-end only. VIDEOWRITER_PROP_B_FRAME_PRESENTATION_DELAY = 13, //!< Maximum delay (in frames) between a B-frame's decoding and presentation. For example, in a GOP with presentation order IBP and decoding order IPB, this value would be 1, as the B-frame is decoded third but presented second. This property is **only** necessary when encapsulating **externally** encoded video where the decoding order differs from the presentation order, such as in GOP patterns with bi-directional B-frames. The value should be calculated based on the specific GOP pattern you used while encoding. FFmpeg back-end only. ```
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/videoio/include/opencv2/videoio.hpp **Change Type:** modified **Context:** PR #25874: `videoio`: fix `cv::VideoWriter` with FFmpeg encapsulation timestamps **Code Changes:** ```diff @@ -211,6 +211,8 @@ enum VideoCaptureProperties { CAP_PROP_CODEC_EXTRADATA_INDEX = 68, //!< Positive index indicates that returning extra data is supported by the video back end. This can be retrieved as cap.retrieve(data, <returned index>). E.g. When reading from a h264 encoded RTSP stream, the FFmpeg backend could return the SPS and/or PPS if available (if sent in reply to a DESCRIBE request), from calls to cap.retrieve(data, <returned index>). CAP_PROP_FRAME_TYPE = 69, //!< (read-only) FFmpeg back-end only - Frame type ascii code (73 = 'I', 80 = 'P', 66 = 'B' or 63 = '?' if unknown) of the most recently read frame. CAP_PROP_N_THREADS = 70, //!< (**open-only**) Set the maximum number of threads to use. Use 0 to use as many threads as CPU cores (applicable for FFmpeg back-end only). + CAP_PROP_PTS = 71, //!< (read-only) FFmpeg back-end only - presentation timestamp of the most recently read frame using the FPS time base. e.g. fps = 25, VideoCapture::get(\ref CAP_PROP_PTS) = 3, presentation time = 3/25 seconds. + CAP_PROP_DTS_DELAY = 72, //!< (read-only) FFmpeg back-end only - maximum difference between presentation (pts) and decompression timestamps (dts) using FPS time base. e.g. delay is maximum when frame_num = 0, if true, VideoCapture::get(\ref CAP_PROP_PTS) = 0 and VideoCapture::get(\ref CAP_PROP_DTS_DELAY) = 2, dts = -2. Non zero values usually imply the stream is encoded using B-frames which are not decoded in presentation order. #ifndef CV_DOXYGEN CV__CAP_PROP_LATEST #endif @@ -230,8 +232,10 @@ enum VideoWriterProperties { ```
I mean slightly different thing. The VideoWriter user should get values for the new properties somehow. I see 2 sources: - get something for cv::VideoCapture and promote it to writer (good case). For the case we need a reference to VideoCapture props. - dig in IP camera settings or encoder settings manually (bad case). The case means that we cannot implement generic code that works for all streams.
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/videoio/include/opencv2/videoio.hpp **Change Type:** modified **Context:** PR #25874: `videoio`: fix `cv::VideoWriter` with FFmpeg encapsulation timestamps **Code Changes:** ```diff @@ -211,6 +211,8 @@ enum VideoCaptureProperties { CAP_PROP_CODEC_EXTRADATA_INDEX = 68, //!< Positive index indicates that returning extra data is supported by the video back end. This can be retrieved as cap.retrieve(data, <returned index>). E.g. When reading from a h264 encoded RTSP stream, the FFmpeg backend could return the SPS and/or PPS if available (if sent in reply to a DESCRIBE request), from calls to cap.retrieve(data, <returned index>). CAP_PROP_FRAME_TYPE = 69, //!< (read-only) FFmpeg back-end only - Frame type ascii code (73 = 'I', 80 = 'P', 66 = 'B' or 63 = '?' if unknown) of the most recently read frame. CAP_PROP_N_THREADS = 70, //!< (**open-only**) Set the maximum number of threads to use. Use 0 to use as many threads as CPU cores (applicable for FFmpeg back-end only). + CAP_PROP_PTS = 71, //!< (read-only) FFmpeg back-end only - presentation timestamp of the most recently read frame using the FPS time base. e.g. fps = 25, VideoCapture::get(\ref CAP_PROP_PTS) = 3, presentation time = 3/25 seconds. + CAP_PROP_DTS_DELAY = 72, //!< (read-only) FFmpeg back-end only - maximum difference between presentation (pts) and decompression timestamps (dts) using FPS time base. e.g. delay is maximum when frame_num = 0, if true, VideoCapture::get(\ref CAP_PROP_PTS) = 0 and VideoCapture::get(\ref CAP_PROP_DTS_DELAY) = 2, dts = -2. Non zero values usually imply the stream is encoded using B-frames which are not decoded in presentation order. #ifndef CV_DOXYGEN CV__CAP_PROP_LATEST #endif @@ -230,8 +232,10 @@ enum VideoWriterProperties { ```
Right I was thinking of streams provided by external encoders (`cudacodec::VideoWriter`) not of the encapsulation of RTSP streams. For the first parameter (`VIDEOWRITER_PROP_PTS_INDEX`), if the frame rate is provided in the rtsp stream it is equivalent to dividing the current position of the video file (`CAP_PROP_POS_MSEC`) by the duration of the frame (i.e. 1000.0/`VideoCapture::get(CAP_PROP_FPS)` if the frame rate is fixed. If the frame rate isn't fixed then we would need to create an extra property inside `cv::VideoCapture` to provide this information? I am not sure if the second parameter (`VIDEOWRITER_PROP_B_FRAME_PRESENTATION_DELAY`) is available inside FFmpeg but if it is (for all versions) we would need to create this extra property inside `cv::VideoCapture` as well.
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Review Line:** 81 **Code Changes:** ```diff + # Do top-k sampling of 50 + topk_indices = np.argpartition(probs, -50, axis=-1)[:, -50:] + topk_probs = np.take_along_axis(probs, topk_indices, axis=-1) + + # Normalize top-k probabilities + topk_probs /= np.sum(topk_probs, axis=-1, keepdims=True) + + # Select a token from the top-k probabilities + sampled_indices = [np.random.choice(topk_indices[i], p=topk_probs[i]) for i in range(len(topk_probs))] + sampled_indices = np.array(sampled_indices).reshape(-1, 1) + ```
Do we really need softmax and normalization to just get top-k predictions? I think their order is not changed from raw logits.
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Code Changes:** ```diff @@ -0,0 +1,125 @@ +''' +This is a sample script to run GPT-2 inference in OpenCV using ONNX model. +The script loads the GPT-2 model and runs inference on a given prompt. +Currently script only works with fixed size window, that means +you will have to specify prompt of the same length as when model was exported to ONNX. + + +Exporting GPT-2 model to ONNX. +To export GPT-2 model to ONNX, you can use the following procedure: ```
`import cv2 as cv`
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Code Changes:** ```diff @@ -0,0 +1,125 @@ +''' +This is a sample script to run GPT-2 inference in OpenCV using ONNX model. +The script loads the GPT-2 model and runs inference on a given prompt. +Currently script only works with fixed size window, that means +you will have to specify prompt of the same length as when model was exported to ONNX. + + +Exporting GPT-2 model to ONNX. +To export GPT-2 model to ONNX, you can use the following procedure: ```
maybe just `readNet`?
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Review Line:** 38 **Code Changes:** ```diff + + + +from copy import deepcopy +import numpy as np +import tiktoken +import argparse +import cv2 as cv + +def parse_args(): + parser = argparse.ArgumentParser(description='Use this script to run GPT-2 inference in OpenCV', ```
External dependency. Add instruction of how to install and which version.
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Review Line:** 31 **Code Changes:** ```diff + + pip install tiktoken==0.7.0 + +2. Run the script: + + python gpt2_inference.py --model=<path-to-onnx-model> --max_seq_len=<max-output-lenght> --batch_size=<use-one-used-while-exportinh> --prompt=<use-promt-of-the-same-length-used-while-exporting> +''' + + + +from copy import deepcopy ```
``` --prompt=<use-promt-of-the-same-length-used-while-exporting> ``` Can sample support simple padding in case of shorter prompt? Otherwise user cannot understand how to fill the same length.
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Review Line:** 31 **Code Changes:** ```diff + + pip install tiktoken==0.7.0 + +2. Run the script: + + python gpt2_inference.py --model=<path-to-onnx-model> --max_seq_len=<max-output-lenght> --batch_size=<use-one-used-while-exportinh> --prompt=<use-promt-of-the-same-length-used-while-exporting> +''' + + + +from copy import deepcopy ```
how to know head of time which prompt legth user used?
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Review Line:** 31 **Code Changes:** ```diff + + pip install tiktoken==0.7.0 + +2. Run the script: + + python gpt2_inference.py --model=<path-to-onnx-model> --max_seq_len=<max-output-lenght> --batch_size=<use-one-used-while-exportinh> --prompt=<use-promt-of-the-same-length-used-while-exporting> +''' + + + +from copy import deepcopy ```
If model exported with some input shape we can accept prompt with less or equal length and pad in case of shorter prompt. There is an option to obtain input shape in OpenCV like this: https://github.com/opencv/opencv/blob/6a11847d579e95bc5cca64d951684d4b578870ae/modules/dnn/src/model.cpp#L51
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Review Line:** 81 **Code Changes:** ```diff + # Do top-k sampling of 50 + topk_indices = np.argpartition(probs, -50, axis=-1)[:, -50:] + topk_probs = np.take_along_axis(probs, topk_indices, axis=-1) + + # Normalize top-k probabilities + topk_probs /= np.sum(topk_probs, axis=-1, keepdims=True) + + # Select a token from the top-k probabilities + sampled_indices = [np.random.choice(topk_indices[i], p=topk_probs[i]) for i in range(len(topk_probs))] + sampled_indices = np.array(sampled_indices).reshape(-1, 1) + ```
`np.random.choice` expect probabilities (sum to 1). otherwise you are correct
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Review Line:** 31 **Code Changes:** ```diff + + pip install tiktoken==0.7.0 + +2. Run the script: + + python gpt2_inference.py --model=<path-to-onnx-model> --max_seq_len=<max-output-lenght> --batch_size=<use-one-used-while-exportinh> --prompt=<use-promt-of-the-same-length-used-while-exporting> +''' + + + +from copy import deepcopy ```
Let's use `max_input_length` as an additional parameter: https://github.com/search?q=repo%3Ahuggingface%2Ftransformers%20max_input_length&type=code
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Code Changes:** ```diff @@ -0,0 +1,125 @@ +''' +This is a sample script to run GPT-2 inference in OpenCV using ONNX model. +The script loads the GPT-2 model and runs inference on a given prompt. +Currently script only works with fixed size window, that means +you will have to specify prompt of the same length as when model was exported to ONNX. + + +Exporting GPT-2 model to ONNX. +To export GPT-2 model to ONNX, you can use the following procedure: ```
You can remove numpy from the list. It's already there as OpenCV dependency.
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Code Changes:** ```diff @@ -0,0 +1,125 @@ +''' +This is a sample script to run GPT-2 inference in OpenCV using ONNX model. +The script loads the GPT-2 model and runs inference on a given prompt. +Currently script only works with fixed size window, that means +you will have to specify prompt of the same length as when model was exported to ONNX. + + +Exporting GPT-2 model to ONNX. +To export GPT-2 model to ONNX, you can use the following procedure: ```
It makes sense to use command line parameter for seed. Zero is good default value.
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:** samples/dnn/gpt2_inference.py **Change Type:** added **Context:** PR #25868: Add sample for GPT2 inference **Review Line:** 117 **Code Changes:** ```diff + if len(tokens) > input_token_size: + tokens = tokens[:input_token_size] + elif len(tokens) < input_token_size: + tokens2pad = input_token_size - len(tokens) + # append <space> token to the prompt + tokens += [220] * tokens2pad + + + output_buffer = gpt2_inference(net, tokens, max_length, num_return_sequences) + + for i in range(num_return_sequences): ```
EOS I tried this. Your prompt followed by EOS make model output sentences that are not related to your prompt (as you indicatited end of context by EOS)
You are an expert OpenCV code reviewer specializing in API design and compatibility. Review the provided code changes and provide specific, actionable feedback.
**File:** doc/tutorials/app/orbbec_uvc.markdown **Change Type:** added **Context:** PR #25907: Add tutorial on using Orbbec 3D cameras (UVC) **Code Changes:** ```diff @@ -0,0 +1,126 @@ +Using Orbbec 3D cameras (UVC) {#tutorial_orbbec_uvc} +==================================================== + +@tableofcontents + +@prev_tutorial{tutorial_orbbec_astra_openni} +@next_tutorial{tutorial_intelperc} + +| | | ```
Please add table with author and compatibility notes like here: https://github.com/opencv/opencv/blob/4.x/doc/tutorials/calib3d/camera_calibration/camera_calibration.markdown
You are an expert OpenCV code reviewer specializing in documentation and code clarity. Review the provided code changes and provide specific, actionable feedback.
**File:** doc/tutorials/app/orbbec_uvc.markdown **Change Type:** added **Context:** PR #25907: Add tutorial on using Orbbec 3D cameras (UVC) **Code Changes:** ```diff @@ -0,0 +1,126 @@ +Using Orbbec 3D cameras (UVC) {#tutorial_orbbec_uvc} +==================================================== + +@tableofcontents + +@prev_tutorial{tutorial_orbbec_astra_openni} +@next_tutorial{tutorial_intelperc} + +| | | ```
Please remove extra empty lines here and below in the document.
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:** doc/tutorials/app/orbbec_uvc.markdown **Change Type:** added **Context:** PR #25907: Add tutorial on using Orbbec 3D cameras (UVC) **Code Changes:** ```diff @@ -0,0 +1,126 @@ +Using Orbbec 3D cameras (UVC) {#tutorial_orbbec_uvc} +==================================================== + +@tableofcontents + +@prev_tutorial{tutorial_orbbec_astra_openni} +@next_tutorial{tutorial_intelperc} + +| | | ```
the older Orbbec 3D which --> the older Orbbec 3D cameras which
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:** doc/tutorials/app/orbbec_uvc.markdown **Change Type:** added **Context:** PR #25907: Add tutorial on using Orbbec 3D cameras (UVC) **Code Changes:** ```diff @@ -0,0 +1,126 @@ +Using Orbbec 3D cameras (UVC) {#tutorial_orbbec_uvc} +==================================================== + +@tableofcontents + +@prev_tutorial{tutorial_orbbec_astra_openni} +@next_tutorial{tutorial_intelperc} + +| | | ```
If you can put your real name here?
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:** doc/tutorials/app/orbbec_uvc.markdown **Change Type:** added **Context:** PR #25907: Add tutorial on using Orbbec 3D cameras (UVC) **Code Changes:** ```diff @@ -0,0 +1,126 @@ +Using Orbbec 3D cameras (UVC) {#tutorial_orbbec_uvc} +==================================================== + +@tableofcontents + +@prev_tutorial{tutorial_orbbec_astra_openni} +@next_tutorial{tutorial_intelperc} + +| | | ```
It's not necessary in my opinion.
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:** doc/tutorials/app/orbbec_uvc.markdown **Change Type:** added **Context:** PR #25907: Add tutorial on using Orbbec 3D cameras (UVC) **Code Changes:** ```diff @@ -0,0 +1,126 @@ +Using Orbbec 3D cameras (UVC) {#tutorial_orbbec_uvc} +==================================================== + +@tableofcontents + +@prev_tutorial{tutorial_orbbec_astra_openni} +@next_tutorial{tutorial_intelperc} + +| | | ```
You can remove the 4th item now.
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:** doc/tutorials/app/orbbec_uvc.markdown **Change Type:** added **Context:** PR #25907: Add tutorial on using Orbbec 3D cameras (UVC) **Code Changes:** ```diff @@ -0,0 +1,126 @@ +Using Orbbec 3D cameras (UVC) {#tutorial_orbbec_uvc} +==================================================== + +@tableofcontents + +@prev_tutorial{tutorial_orbbec_astra_openni} +@next_tutorial{tutorial_intelperc} + +| | | ```
Can you add toggle to show the two pictures, same as the switch to show the two code version?
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:** doc/tutorials/app/orbbec_uvc.markdown **Change Type:** added **Context:** PR #25907: Add tutorial on using Orbbec 3D cameras (UVC) **Code Changes:** ```diff @@ -0,0 +1,126 @@ +Using Orbbec 3D cameras (UVC) {#tutorial_orbbec_uvc} +==================================================== + +@tableofcontents + +@prev_tutorial{tutorial_orbbec_astra_openni} +@next_tutorial{tutorial_intelperc} + +| | | ```
Can be removed too in my opinion.
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:** doc/tutorials/app/orbbec_uvc.markdown **Change Type:** added **Context:** PR #25907: Add tutorial on using Orbbec 3D cameras (UVC) **Code Changes:** ```diff @@ -0,0 +1,126 @@ +Using Orbbec 3D cameras (UVC) {#tutorial_orbbec_uvc} +==================================================== + +@tableofcontents + +@prev_tutorial{tutorial_orbbec_astra_openni} +@next_tutorial{tutorial_intelperc} + +| | | ```
measurement limits --> depth range; potentially enhancing the visualization's relevance to a specific depth range --> removing invalid pixels on the depth map.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/checks/cpu_rvv.cpp **Change Type:** modified **Context:** PR #25883: Upgrade RISC-V Vector intrinsic and cleanup the obsolete RVV backend. **Code Changes:** ```diff @@ -1,17 +1,16 @@ #include <stdio.h> -#if defined(__riscv) -# include <riscv_vector.h> -# define CV_RVV 1 +#if !defined(__riscv) || !defined(__riscv_v) +#error "RISC-V or vector extension(RVV) is not supported by the compiler" #endif ```
Let's make this file compatible with T-Head toolchain too. It uses old intrinsics, doesn't define `__riscv_v_intrinsics`, but have `__riscv_v` and `__THEAD_VERSION__` macros. Perhaps even simple `#include <riscv_vector.h>` would be enough to check that it works. Otherwise our CPU detection mechanism will not find RVV and would disable RVV 0.7.1 HAL: https://github.com/opencv/opencv/blob/53a5b85d9f6e2a58066f966d901c0e93ea1ebcf0/CMakeLists.txt#L1040-L1046
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/checks/cpu_rvv.cpp **Change Type:** modified **Context:** PR #25883: Upgrade RISC-V Vector intrinsic and cleanup the obsolete RVV backend. **Code Changes:** ```diff @@ -1,17 +1,16 @@ #include <stdio.h> -#if defined(__riscv) -# include <riscv_vector.h> -# define CV_RVV 1 +#if !defined(__riscv) || !defined(__riscv_v) +#error "RISC-V or vector extension(RVV) is not supported by the compiler" #endif ```
Ok, do you mean ... ```cpp #include <stdio.h> #if defined(__riscv) # include <riscv_vector.h> # define CV_RVV 1 #endif #if defined CV_RVV && !defined __THEAD_VERSION__ #if !defined(__riscv_v_intrinsic) || (__riscv_v_intrinsic < 12000) #error "RISC-V Vector Intrinsic v0.12 or higher is required." #endif int test() { const float src[] = { 0.0f, 0.0f, 0.0f, 0.0f }; uint64_t ptr[2] = {0x0908060504020100, 0xFFFFFFFF0E0D0C0A}; vuint8m1_t a = __riscv_vreinterpret_v_u64m1_u8m1(__riscv_vle64_v_u64m1(ptr, 2)); vfloat32m1_t val = __riscv_vle32_v_f32m1((const float*)(src), 4); return (int)__riscv_vfmv_f_s_f32m1_f32(val); } #elif defined CV_RVV && defined __THEAD_VERSION__ int test() { const float src[] = { 0.0f, 0.0f, 0.0f, 0.0f }; uint64_t ptr[2] = {0x0908060504020100, 0xFFFFFFFF0E0D0C0A}; vuint8m1_t a = vreinterpret_v_u64m1_u8m1(vle64_v_u64m1(ptr, 2)); vfloat32m1_t val = vle32_v_f32m1((const float*)(src), 4); return (int)vfmv_f_s_f32m1_f32(val); } #else #error "RISC-V vector extension(RVV) is not supported" #endif int main() { printf("%d\n", test()); return 0; } ```
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** cmake/checks/cpu_rvv.cpp **Change Type:** modified **Context:** PR #25883: Upgrade RISC-V Vector intrinsic and cleanup the obsolete RVV backend. **Code Changes:** ```diff @@ -1,17 +1,16 @@ #include <stdio.h> -#if defined(__riscv) -# include <riscv_vector.h> -# define CV_RVV 1 +#if !defined(__riscv) || !defined(__riscv_v) +#error "RISC-V or vector extension(RVV) is not supported by the compiler" #endif ```
Yes, it should work. Perhaps we could also simplify the file a bit to reduce macros depth: ```.cpp #if !defined(__riscv) || !defined(__riscv_v) #error "Not RISC-V or no RVV ..." #endif #if !defined(__THEAD_VERSION__) && defined(__riscv_v_intrinsic) && __riscv_v_intrinsic < 12000 #error "Wrong intrinsics ..." #endif #include <riscv_vector.h> #ifdef (__THEAD_VERSION__) int test() { // ... old version } #else { // ... new version } #endif int main() {...} ```
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
Why not as a part of the previous loop?
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
I recommend use shapes directly. Including 1D vector with multiple values.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
Could you define reduction operation on 0d / 1d tensor? Any reference?
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
formally there is not any. This test is to check if layer fails on singleton matrices
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
There are some in onnxruntime: https://github.com/microsoft/onnxruntime/blob/4a196d15940b0f328735c888e2e861d67602ffcf/onnxruntime/test/providers/cpu/reduction/reduction_ops_test.cc#L326 (Search for 0D).
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/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
incorrect comment
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
```suggestion cv::Mat output_ref = cv::Mat(std::vector<int>(input_shape.size(), 1), CV_32F, out_value); ```
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
Why do still we have ONE output value for matrix? Don't write WEAK tests.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
Sorry, I do not understand you. What could be output for 1D(or 0D) matrix under reduction operation other than one output value? What do you mean by output value?
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/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
Done! (did not see the comment, sorry)
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
in case of `[4, 4]` input and `axis=1` output is `[4, 1]`, so it also can be tested
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Review Line:** 490 **Code Changes:** ```diff +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; + if (shape(input).size() == 0 || shape(input).size() == 1){ + result = cv::Mat(shape(input).size(), shape(input).data(), CV_32F); + int sz[1] = {1}; + if (!shape(input).empty() && shape(input)[0] != 1){ + result = cv::Mat(1, 1, CV_32F); + result = result.reshape(1, 1, sz); + } ```
Might be incorrect for `std::vector<int>({4})` test case (not represented). Number of input dimensions is 1 however output shape is not equal to input shape.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Review Line:** 502 **Code Changes:** ```diff + if (axis == 0) { + result = cv::Mat::zeros(1, input.cols, CV_32F); + } else { + result = cv::Mat::zeros(input.rows, 1, CV_32F); + } + } + + auto process_value = [&](float& res, float value, bool is_first) { + if (operation == "max") { + res = is_first ? value : std::max(res, value); + } else if (operation == "min") { ```
Can we simplify to something like this? ```cpp MatShape shape(input). if (!shape.empty()) shape[axis] = 1; result = cv::Mat::zeros(shape.size(), &shape[0], CV_32F); ```
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
Please clarify this condition. For example, `{1, 4}` input, axis=1 should be reduced to `{1x1}`: `[[a, b, c, d]]` -> `[[a*a + b*b + c*c + d*d]]`
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Review Line:** 592 **Code Changes:** ```diff + ASSERT_EQ(shape(output_ref), shape(outputs[0])); + normAssert(output_ref, outputs[0]); +} +INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Reduce_Test, Combine( +/*input blob shape*/ Values( + std::vector<int>({}), + std::vector<int>({1}), + std::vector<int>({4}), + std::vector<int>({1, 4}), + std::vector<int>({4, 1}), + std::vector<int>({4, 4}) ```
nit: use without parenthesis for simplificity, e.g. `std::vector<int>{}`.
You are an expert OpenCV code reviewer specializing in implementation quality. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_layers_1d.cpp **Change Type:** modified **Context:** PR #25101: 1D test for Reduce layer **Code Changes:** ```diff @@ -480,6 +480,128 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Layer_Scatter_Test, Combine( +typedef testing::TestWithParam<tuple<std::vector<int>, std::string, int>> Layer_Reduce_Test; +TEST_P(Layer_Reduce_Test, Accuracy_01D) +{ + auto reduceOperation = [](const cv::Mat& input, const std::string& operation, int axis) -> cv::Mat { + // Initialize result matrix + cv::Mat result; ```
Please drop debug printing.
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/core/include/opencv2/core.hpp **Change Type:** modified **Context:** PR #25914: throw() -> noexcept **Code Changes:** ```diff @@ -123,12 +123,12 @@ class CV_EXPORTS Exception : public std::exception Instead, the macros CV_Error(), CV_Error_() and CV_Assert() are used. */ Exception(int _code, const String& _err, const String& _func, const String& _file, int _line); - virtual ~Exception() throw(); + virtual ~Exception() CV_NOEXCEPT; /*! \return the error description and the context as a text string. */ ```
Use `CV_NOEXCEPT` according to existed codebase,
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/dnn/src/ie_ngraph.hpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -17,7 +17,8 @@ #pragma warning(disable : 4245) #pragma warning(disable : 4268) #endif -#include <ngraph/ngraph.hpp> +#include <openvino/openvino.hpp> +#include <openvino/op/ops.hpp> #ifdef _MSC_VER #pragma warning(pop) #endif ```
Should be valid even for earlier release: https://github.com/opencv/opencv/blob/0fabe2b9e9fac96957b553b6a83483bddfe129bb/modules/dnn/src/op_inf_engine.hpp#L49. Not sure about `ov::` namespace
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/ie_ngraph.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -14,7 +14,7 @@ #include <opencv2/dnn/shape_utils.hpp> #ifdef HAVE_DNN_NGRAPH -#include <ie_extension.h> +#include <openvino/core/extension.hpp> #endif // HAVE_DNN_NGRAPH #include <opencv2/core/utils/configuration.private.hpp> @@ -35,36 +35,6 @@ static bool DNN_IE_SERIALIZE = utils::getConfigurationParameterBool("OPENCV_DNN_ ```
Is `ov::` available for `< 2020.3`?
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/elementwise_layers.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -490,13 +490,13 @@ struct ReLUFunctor : public BaseFunctor #endif #ifdef HAVE_DNN_NGRAPH - std::shared_ptr<ngraph::Node> initNgraphAPI(const ngraph::Output<ngraph::Node>& node) + std::shared_ptr<ov::Node> initNgraphAPI(const ov::Output<ov::Node>& node) { if (slope) { - auto param = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, ngraph::Shape{1}, &slope); - return std::make_shared<ngraph::op::PRelu>(node, param); ```
```cpp #include <openvino/op/ops.hpp> ```
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/elementwise_layers.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -490,13 +490,13 @@ struct ReLUFunctor : public BaseFunctor #endif #ifdef HAVE_DNN_NGRAPH - std::shared_ptr<ngraph::Node> initNgraphAPI(const ngraph::Output<ngraph::Node>& node) + std::shared_ptr<ov::Node> initNgraphAPI(const ov::Output<ov::Node>& node) { if (slope) { - auto param = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, ngraph::Shape{1}, &slope); - return std::make_shared<ngraph::op::PRelu>(node, param); ```
And I think better to include it to `op_inf_engine.hpp`
You are an expert OpenCV code reviewer specializing in performance optimization. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/layers/elementwise_layers.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -490,13 +490,13 @@ struct ReLUFunctor : public BaseFunctor #endif #ifdef HAVE_DNN_NGRAPH - std::shared_ptr<ngraph::Node> initNgraphAPI(const ngraph::Output<ngraph::Node>& node) + std::shared_ptr<ov::Node> initNgraphAPI(const ov::Output<ov::Node>& node) { if (slope) { - auto param = std::make_shared<ngraph::op::Constant>(ngraph::element::f32, ngraph::Shape{1}, &slope); - return std::make_shared<ngraph::op::PRelu>(node, param); ```
Includes of separated ops speed up build. But I cannot use this approach with 2021 OpenVINO release :(
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/ie_ngraph.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -14,7 +14,7 @@ #include <opencv2/dnn/shape_utils.hpp> #ifdef HAVE_DNN_NGRAPH -#include <ie_extension.h> +#include <openvino/core/extension.hpp> #endif // HAVE_DNN_NGRAPH #include <opencv2/core/utils/configuration.private.hpp> @@ -35,36 +35,6 @@ static bool DNN_IE_SERIALIZE = utils::getConfigurationParameterBool("OPENCV_DNN_ ```
do you need to support 4 years old OpenVINO? Can we say only 2022.1 and newer are supported? It will significantly simplify conditions in code where OpenVINO is used and also will allow to drop legacy cmake code and rely only on `find_package(OpenVINO)` 2 year since 2022.1 is a good release history
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/ie_ngraph.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -14,7 +14,7 @@ #include <opencv2/dnn/shape_utils.hpp> #ifdef HAVE_DNN_NGRAPH -#include <ie_extension.h> +#include <openvino/core/extension.hpp> #endif // HAVE_DNN_NGRAPH #include <opencv2/core/utils/configuration.private.hpp> @@ -35,36 +35,6 @@ static bool DNN_IE_SERIALIZE = utils::getConfigurationParameterBool("OPENCV_DNN_ ```
Agree. For now CI works on 2021.4 so we can keep it to test it against OpenVINO API 2.0 (2022.x). I just mean that this lane changed under `#ifdef` and we don't test it. So specifically for this line, I recommend revert. Let's drop OpenVINO support for 2020.x in a separate PR.
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/ie_ngraph.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -14,7 +14,7 @@ #include <opencv2/dnn/shape_utils.hpp> #ifdef HAVE_DNN_NGRAPH -#include <ie_extension.h> +#include <openvino/core/extension.hpp> #endif // HAVE_DNN_NGRAPH #include <opencv2/core/utils/configuration.private.hpp> @@ -35,36 +35,6 @@ static bool DNN_IE_SERIALIZE = utils::getConfigurationParameterBool("OPENCV_DNN_ ```
> 2021.4 API 2.0 since 2022.1 If we want to drop IE:: and API 1.0, we need to test since 2022.1
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/dnn/src/ie_ngraph.hpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -17,7 +17,8 @@ #pragma warning(disable : 4245) #pragma warning(disable : 4268) #endif -#include <ngraph/ngraph.hpp> +#include <openvino/openvino.hpp> +#include <openvino/op/ops.hpp> #ifdef _MSC_VER #pragma warning(pop) #endif ```
Conflicts with existing namespace https://github.com/opencv/opencv/actions/runs/8256827567/job/22596488054?pr=25199
You are an expert OpenCV code reviewer specializing in API design and compatibility. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/ie_ngraph.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -14,7 +14,7 @@ #include <opencv2/dnn/shape_utils.hpp> #ifdef HAVE_DNN_NGRAPH -#include <ie_extension.h> +#include <openvino/core/extension.hpp> #endif // HAVE_DNN_NGRAPH #include <opencv2/core/utils/configuration.private.hpp> @@ -35,36 +35,6 @@ static bool DNN_IE_SERIALIZE = utils::getConfigurationParameterBool("OPENCV_DNN_ ```
> I only recommend to do this in a separate PR But in this case we need to do double job: - Current PR supports both Pre and Post API 1.0 changes - Next PR removes Pre API 1.0 code path. I suppose we need to do it in one shot and just drop API 1.0 here
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/detection_output_layer.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Review Line:** 56 **Code Changes:** ```diff @@ -55,11 +55,7 @@ #ifdef HAVE_DNN_NGRAPH #include "../ie_ngraph.hpp" -#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) -#include <ngraph/op/detection_output.hpp> -#else -#include <ngraph/op/experimental/layers/detection_output.hpp> ```
HAVE_DNN_NGRAPH => HAVE_DNN_OPENVINO ?
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/net_openvino.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Review Line:** 14 **Code Changes:** ```diff #include <opencv2/core/utils/configuration.private.hpp> #include <opencv2/core/utils/logger.hpp> +#include "op_inf_engine.hpp" + +#ifdef HAVE_INF_ENGINE +#include <openvino/op/util/op_types.hpp> +#endif + #include "net_impl.hpp" ```
```suggestion #ifdef HAVE_OPENVINO ```
You are an expert OpenCV code reviewer specializing in API design and compatibility. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/net_openvino.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -9,6 +9,12 @@ #include <opencv2/core/utils/configuration.private.hpp> #include <opencv2/core/utils/logger.hpp> +#include "op_inf_engine.hpp" + +#ifdef HAVE_INF_ENGINE +#include <openvino/op/util/op_types.hpp> +#endif + ```
it's removed in API 2.0
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/op_inf_engine.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Review Line:** 12 **Code Changes:** ```diff @@ -10,7 +10,7 @@ #include <opencv2/dnn/shape_utils.hpp> #ifdef HAVE_INF_ENGINE -#include <ie_extension.h> +#include <openvino/core/extension.hpp> #elif defined(ENABLE_PLUGINS) // using plugin API #include "backend.hpp" ```
```suggestion #ifdef HAVE_OPENVINO ```
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/dnn/src/op_inf_engine.hpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Review Line:** 24 **Code Changes:** ```diff -#define INF_ENGINE_RELEASE_2021_2 2021020000 -#define INF_ENGINE_RELEASE_2021_3 2021030000 -#define INF_ENGINE_RELEASE_2021_4 2021040000 #define INF_ENGINE_RELEASE_2022_1 2022010000 #define INF_ENGINE_RELEASE_2023_0 2023000000 +#define INF_ENGINE_RELEASE_2024_0 2024000000 #ifndef INF_ENGINE_RELEASE -#warning("IE version have not been provided via command-line. Using 2021.4 by default") -#define INF_ENGINE_RELEASE INF_ENGINE_RELEASE_2021_4 +#warning("IE version have not been provided via command-line. Using 2022.1 by default") ```
```suggestion #define OPENVINO_RELEASE_2024_0 2024000000 ``` and can we remove old ones?
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/detection_output_layer.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Review Line:** 56 **Code Changes:** ```diff @@ -55,11 +55,7 @@ #ifdef HAVE_DNN_NGRAPH #include "../ie_ngraph.hpp" -#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) -#include <ngraph/op/detection_output.hpp> -#else -#include <ngraph/op/experimental/layers/detection_output.hpp> ```
Will cost a lot of changes as well as DNN_BACKEND_INFERENCE_ENGINE -> DNN_BACKEND_OPENVINO.
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/dnn/src/op_inf_engine.hpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Review Line:** 24 **Code Changes:** ```diff -#define INF_ENGINE_RELEASE_2021_2 2021020000 -#define INF_ENGINE_RELEASE_2021_3 2021030000 -#define INF_ENGINE_RELEASE_2021_4 2021040000 #define INF_ENGINE_RELEASE_2022_1 2022010000 #define INF_ENGINE_RELEASE_2023_0 2023000000 +#define INF_ENGINE_RELEASE_2024_0 2024000000 #ifndef INF_ENGINE_RELEASE -#warning("IE version have not been provided via command-line. Using 2021.4 by default") -#define INF_ENGINE_RELEASE INF_ENGINE_RELEASE_2021_4 +#warning("IE version have not been provided via command-line. Using 2022.1 by default") ```
Let’s remove old ones, but keep IE notation to reduce changes.
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/dnn/src/op_inf_engine.hpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -19,19 +19,13 @@ #ifdef HAVE_INF_ENGINE -#define INF_ENGINE_RELEASE_2020_2 2020020000 -#define INF_ENGINE_RELEASE_2020_3 2020030000 -#define INF_ENGINE_RELEASE_2020_4 2020040000 -#define INF_ENGINE_RELEASE_2021_1 2021010000 -#define INF_ENGINE_RELEASE_2021_2 2021020000 -#define INF_ENGINE_RELEASE_2021_3 2021030000 ```
Please remove this workaround with `CNNNetwork` alias
You are an expert OpenCV code reviewer specializing in testing and validation. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/test/test_ie_models.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Review Line:** 269 **Code Changes:** ```diff - // Fill output blobs. + // Fill output tensors. outputsMap.clear(); - BlobMap outputBlobs; - for (auto& it : net.getOutputsInfo()) + for (const auto& it : model->outputs()) { - const InferenceEngine::TensorDesc& desc = it.second->getTensorDesc(); - genData(desc, outputsMap[it.first], outputBlobs[it.first]); + auto type = it.get_element_type(); + auto shape = it.get_shape(); ```
Single failed test: ``` [ RUN ] DNNTestOpenVINO.models/0, where GetParam() = (NGRAPH/CPU, "age-gender-recognition-retail-0013") Exception message: OpenCV(4.9.0-dev) /home/openvino/opencv/modules/dnn/src/net_impl.cpp:570: error: (-215:Assertion failed) inp.total() in function 'allocateLayers' /home/openvino/opencv/modules/dnn/test/test_ie_models.cpp:399: Failure Expected: runCV(backendId, targetId, xmlPath, binPath, inputsMap, cvOutputsMap) doesn't throw an exception. Actual: it throws. runCV /home/openvino/opencv/modules/dnn/test/test_ie_models.cpp:415: Failure Expected equality of these values: ieOutputsMap.size() Which is: 2 cvOutputsMap.size() Which is: 0 unknown file: Failure C++ exception with description "OpenCV(4.9.0-dev) /home/openvino/opencv/modules/dnn/test/test_ie_models.cpp:419: error: (-215:Assertion failed) dstIt != cvOutputsMap.end() in function 'Body' " thrown in the test body. [ FAILED ] DNNTestOpenVINO.models/0, where GetParam() = (NGRAPH/CPU, "age-gender-recognition-retail-0013") (87 ms) ```
You are an expert OpenCV code reviewer specializing in API design and compatibility. Review the provided code changes and provide specific, actionable feedback.
**File:** modules/dnn/src/net_openvino.cpp **Change Type:** modified **Context:** PR #25199: Fix for OpenVINO 2024.0. OpenVINO 2022.1 as minimal supported version. **Code Changes:** ```diff @@ -9,6 +9,12 @@ #include <opencv2/core/utils/configuration.private.hpp> #include <opencv2/core/utils/logger.hpp> +#include "op_inf_engine.hpp" + +#ifdef HAVE_INF_ENGINE +#include <openvino/op/util/op_types.hpp> +#endif + ```
This is a workaround to wrap `ov::Model` from API 2.0: https://github.com/opencv/opencv/pull/25199/files#r1524623439
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/test/test_smooth_bitexact.cpp **Change Type:** modified **Context:** PR #25911: Post-merge fixes for algorithm hint API **Review Line:** 296 **Code Changes:** ```diff - EXPECT_LE(nz, 0.06*src.total()); // Less 6% of different pixels - - double min_val, max_val; - minMaxLoc(flatten_diff, &min_val, &max_val); - EXPECT_LE(max_val, 2); // expectes results floating +-1 + EXPECT_LE(cvtest::norm(dst, gt, NORM_INF), 1); + EXPECT_LE(cvtest::norm(dst, gt, NORM_L1 | NORM_RELATIVE), 0.06); // Less 6% of different pixels } INSTANTIATE_TEST_CASE_P(/*nothing*/, GaussianBlurVsBitexact, ```
`EXPECT_LE(cvtest::norm(dst, gt, NORM_L1 | NORM_RELATIVE), 0.06); // Less 6% of different pixels`
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/core/include/opencv2/core/hal/intrin.hpp **Change Type:** modified **Context:** PR #24941: Add support for v_exp (exponential) **Code Changes:** ```diff @@ -1239,6 +1239,7 @@ namespace CV__SIMD_NAMESPACE { #define CV_SIMD 0 #endif +#include "intrin_math.hpp" #include "simd_utils.impl.hpp" #ifndef CV_DOXYGEN ```
Please add reference to the algorithm with name. Information about application range and quality will be very useful too.
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/test/test_intrin_utils.hpp **Change Type:** modified **Context:** PR #24941: Add support for v_exp (exponential) **Review Line:** 1702 **Code Changes:** ```diff @@ -1698,6 +1698,103 @@ template<typename R> struct TheTest return *this; } + void __test_exp(LaneType dataMax, LaneType diff_thr, LaneType enlarge_factor, LaneType flt_min) { + int n = VTraits<R>::vlanes(); + + // Test overflow and underflow values with step + const LaneType step = (LaneType) 0.01; + for (LaneType i = dataMax + 1; i <= dataMax + 11;) { + Data<R> dataUpperBound, dataLowerBound, resOverflow, resUnderflow; ```
The test is very weak. v_exp() is critical function. We must test it properly. 1. We must test all the corner and popular cases ``` exp(nan)=nan, exp(0)=1, exp(1)~e, exp(inf)=inf, exp(-inf)=0, exp(88) < inf, exp(89..100)=inf (overflow), // check every number with step 0.1 or even 0.01 0<=exp(-100..-88)<FLT_MIN (underflow). // check every number with step 0.1 or even 0.01 ``` 2. ``` for (int i = 0; i < 10000; i++) { 1. generate vlanes() numbers x_j, j=0..vlanes()-1 in range [-100,100]. 2. compute vector exponent v_exp() 3. compute exponent for each number using std::exp() 4. check relative accuracy a. std::exp(x_j) = inf => EXPECT_GT(vector_exp_j, FLT_MAX*0.99) b. std::exp(x_j) < inf => EXPECT_GE(vector_exp_j, 0); EXPECT_LT(std::abs(vector_exp_j-std_exp_j) < 1e-6*(std::abs(std_exp_j)+FLT_MIN*100) ``` where 0.99, 1e-6 and 100 should probably be adjusted.
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/core/include/opencv2/core/hal/intrin.hpp **Change Type:** modified **Context:** PR #24941: Add support for v_exp (exponential) **Code Changes:** ```diff @@ -1239,6 +1239,7 @@ namespace CV__SIMD_NAMESPACE { #define CV_SIMD 0 #endif +#include "intrin_math.hpp" #include "simd_utils.impl.hpp" #ifndef CV_DOXYGEN ```
sure, I will do it
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/core/include/opencv2/core/hal/intrin.hpp **Change Type:** modified **Context:** PR #24941: Add support for v_exp (exponential) **Code Changes:** ```diff @@ -1239,6 +1239,7 @@ namespace CV__SIMD_NAMESPACE { #define CV_SIMD 0 #endif +#include "intrin_math.hpp" #include "simd_utils.impl.hpp" #ifndef CV_DOXYGEN ```
Almost all documentation in this file is ignored. This file contains too much conditional compilations through `#if` and template-based logic. Doxygen doesn't work properly with that. Documentation is stored and well structured in intrin_cpp.hpp
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/hal/intrin.hpp **Change Type:** modified **Context:** PR #24941: Add support for v_exp (exponential) **Code Changes:** ```diff @@ -1239,6 +1239,7 @@ namespace CV__SIMD_NAMESPACE { #define CV_SIMD 0 #endif +#include "intrin_math.hpp" #include "simd_utils.impl.hpp" #ifndef CV_DOXYGEN ```
1. My suggestion is to move this and similar implementations into a separate file. There is already `simd_utils.impl.hpp`. It could be reused or created a new one like `simd_math.impl.hpp` 2. Also all functions should be guarded if some ISA has better support for these functions. At least intrin_cpp.hpp could use `std::exp()` as reference (to ensure that test code is adequate)
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/test/test_intrin_utils.hpp **Change Type:** modified **Context:** PR #24941: Add support for v_exp (exponential) **Review Line:** 1702 **Code Changes:** ```diff @@ -1698,6 +1698,103 @@ template<typename R> struct TheTest return *this; } + void __test_exp(LaneType dataMax, LaneType diff_thr, LaneType enlarge_factor, LaneType flt_min) { + int n = VTraits<R>::vlanes(); + + // Test overflow and underflow values with step + const LaneType step = (LaneType) 0.01; + for (LaneType i = dataMax + 1; i <= dataMax + 11;) { + Data<R> dataUpperBound, dataLowerBound, resOverflow, resUnderflow; ```
Since `v_max(nan, x)` and `v_min(nan, x)` will not return `nan` except neon, I disabled this test. Are there some way to handle this case?
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/core/include/opencv2/core/hal/intrin.hpp **Change Type:** modified **Context:** PR #24941: Add support for v_exp (exponential) **Code Changes:** ```diff @@ -1239,6 +1239,7 @@ namespace CV__SIMD_NAMESPACE { #define CV_SIMD 0 #endif +#include "intrin_math.hpp" #include "simd_utils.impl.hpp" #ifndef CV_DOXYGEN ```
OK, I added a line in `intrin_cpp.hpp` for document ``` | Operations\\Types | float 32 | float 64 | |-------------------|:-:|:-:| ...... |exp | x | x | ```
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/core/include/opencv2/core/hal/intrin.hpp **Change Type:** modified **Context:** PR #24941: Add support for v_exp (exponential) **Code Changes:** ```diff @@ -1239,6 +1239,7 @@ namespace CV__SIMD_NAMESPACE { #define CV_SIMD 0 #endif +#include "intrin_math.hpp" #include "simd_utils.impl.hpp" #ifndef CV_DOXYGEN ```
Let's implement item 2 too. I want to benchmark both options before merge.