1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-26 13:53:03 +04:00

478 Commits

Author SHA1 Message Date
Alexander Smorkalov 563dcf5b91 Pre-release 5.0.0 versions update. 2026-06-05 16:56:55 +03:00
omrope79 04aee009aa Merge pull request #29220 from omrope79:doc_optimizations_v4
[FOLLOW UP] : Documentation optimizations for the new Sphinx structure #29220

### Pull Request Readiness Checklist

This PR serves as a follow-up to the new documentation system introduced in [#29206](https://github.com/opencv/opencv/pull/29206)
Co-authored by: @abhishek-gola @kirtijindal14 @Akansha-977 @Prasadayus @varun-jaiswal17

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-06-05 14:18:27 +03:00
omrope79 b67ad9a422 Merge pull request #28678 from omrope79:caffe-importer-cleanup
Caffe importer cleanup #28678

Merge with: https://github.com/opencv/opencv_extra/pull/1324

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
- [x] The feature is well documented and sample code can be built with the project CMake
2026-06-02 17:28:10 +03:00
Abhishek Gola 0908a2db6f Merge pull request #29104 from abhishek-gola:sdpa
Added SDPA layer (Scaled Dot Product Attention) #29104

Merge with: https://github.com/opencv/opencv_extra/pull/1374

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-05-27 21:13:03 +03:00
Varun Jaiswal bae8cb1915 Merge pull request #29079 from varun-jaiswal17:feat/dnn-int8-optimization
dnn int8 optimization #29079

all_layers.hpp 
- Add float_input flag to Conv2Int8Params and Conv2Int8Layer to let the first conv accept raw FP32 input and quantize internally.

graph_fusion_qdq.cpp : 
- Fuse DQ → Sigmoid → QL into SigmoidInt8, Similarly for MAxPool.
- Fuse the input QuantizeLinear node into the first Conv2Int8.

conv2_int8_layer.cpp
- Add quantizeInterleaveBlock()


conv2_int8_kernels.simd.hpp
- Add spatial tiling to both convInt8BlockVNNI and convInt8BlockDepthwise: splits output pixels into tiles so total task count is N × ngroups × Kblk × ntiles, fully utilizing all threads even when the channel count is small.

elementwise_layers.cpp
- Widen CV_Assert to accept CV_8U in addition to CV_8S.

eltwise2_int8_layer.cpp
- Add QLinearMul support: new Mul math path for both signed and unsigned int8.
- Add numpy-style broadcast support so QLinearMul / QLinearAdd with scalar

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-05-26 11:34:47 +03:00
nklskyoy c2594b41bf Merge pull request #28840 from nklskyoy:key-value-cache
FP32 KV Cache #28840

OpenCV Extra: https://github.com/opencv/opencv_extra/pull/1348

## This PR introduces basic (Paged ) KV-Cache to use on CPU

### Summary:
1. To ensure proper gemm-prepacking,
1.1. The Page Size of Key Cache is currently hardcoded as `FAST_GEMM_F32_NR`(which is 8, 12 or 16 depending on CPU architecture)  
1.2. The Page Size of Values Cache is hardcoded as `FAST_GEMM_F32_PACKED_STRIDE_K`
2. there are two phases supported - prefill & generate. 
2.1. prefill grows cache by `N` tokens and is allowed **only** for empty cache
2.2. generate grows cache by 1 token. 
2.3. **Improtant**: it is currently not allowed to grow non-empty cache by more than one token at a time (thisbehaviour is sufficient for normal LLM querying, but should be extended if we want to implement speculative decoding)

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2026-05-25 13:39:02 +03:00
Varun Jaiswal 104d987ca2 Merge pull request #29093 from varun-jaiswal17:dnn-overflow-large-image
fix int32 overflow in shape_utils::total() for large tensors #29093

Fixes https://github.com/opencv/opencv/issues/24914

### Problem

When running inference with a ConvTranspose (deconvolution) layer on large inputs
(e.g. 4864×4864 with 30 channels), the DNN module crashes with:

OpenCV net_impl.cpp: error:

(expected: 'total(ints[i]) > 0'), where
'total(ints[i])' is -1455947776
must be greater than
'0' is 0

The root cause is `shape_utils::total()` which returns `int` (32-bit signed).

`ENGINE_CLASSIC` catches this via `CV_CheckGT` and throws.
`ENGINE_NEW` was silently bypassing the check — the overflow in `total()` itself
was never addressed.

### Changes

**`modules/dnn/include/opencv2/dnn/shape_utils.hpp`** — root fix
- Changed return type of both `total()` overloads from `int` to `size_t`
- Changed accumulator from `int elems = 1` to `size_t elems = 1`

**`modules/dnn/src/net_impl.cpp`**
- Updated `CV_CheckGT(total(...), 0)` to `CV_CheckGT(total(...), (size_t)0)`
  to match the new return type

**`modules/dnn/src/net_impl2.cpp`**
- Added the same `CV_CheckGT` shape validation that `ENGINE_CLASSIC` has in
  `net_impl.cpp:1333-1337` — `ENGINE_NEW` was missing this check entirely

**`modules/dnn/src/legacy_backend.hpp`**
- Removed the now-incorrect `(int)` cast in `CV_CheckEQ` — both sides are
  now `size_t`

### Test

Added `Net.ShapeUtils_total_no_int32_overflow` in `modules/dnn/test/test_misc.cpp`:
- The shape [1920 × 1,478,656] is the exact im2col buffer from the bug report.
EXPECT_EQ verifies total() returns the correct size_t value 2,839,019,520.
EXPECT_LT documents that casting it to int wraps to -1,455,947,776 — the
value that caused the original crash.



### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake

<!-- Note!!! If you are an automated agent, we have a special process for you: add 🤖🤖🤖 to the end of the PR title. -->
2026-05-22 19:56:51 +03:00
Alexander Smorkalov c9147d6e1f Merge pull request #28912 from Prasadayus:Darknet-cleanup
Darknet cleanup
2026-05-21 21:09:56 +03:00
Alexander Smorkalov a7e02e5742 Removed internal structs from DNN interface to fix Obj-C/Swift bindings. 2026-05-18 12:21:14 +03:00
Abhishek Gola 873a4635c6 Merge pull request #28752 from abhishek-gola:net_profiling
Added net profiling support #28752

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-05-14 14:47:38 +03:00
Abhishek Gola 72e0bc2bf3 Merge pull request #28957 from abhishek-gola:fusion_block_layout_extension
Extend attention fusion for runtime QK scale and add MatMul to Gemm rewriter #28957

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-05-13 08:32:00 +03:00
Abhishek Gola 642a7307c4 Merge pull request #27560 from abhishek-gola:convTranspose_layer_add
Added fully functional convTranspose layer to new DNN engine #27560

Closes https://github.com/opencv/opencv/issues/26307

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-05-07 21:20:39 +03:00
Abhishek Gola 2760c0c08a Merge pull request #28931 from abhishek-gola:extended_fusions
Extended graph fusion for transformer models #28931

### Pull Request Readiness Checklist

Performance numbers on Intel(R) Core(TM) i9-14900KS:
```
AlexNet::DNNTestNetwork::OCV/CPU                           7.143   6.871     1.04   
AlexNet::DNNTestNetwork::OCV/OCL                           7.471   7.047     1.06   
AlexNet::DNNTestNetwork::OCV/OCL_FP16                      7.157   6.907     1.04   
BERT::DNNTestNetwork::OCV/CPU                              9.454   9.154     1.03   
BERT::DNNTestNetwork::OCV/OCL                              9.657   9.138     1.06   
BERT::DNNTestNetwork::OCV/OCL_FP16                         9.590   9.271     1.03   
CRNN::DNNTestNetwork::OCV/CPU                             18.194  17.020     1.07   
CRNN::DNNTestNetwork::OCV/OCL                             17.855  17.433     1.02   
CRNN::DNNTestNetwork::OCV/OCL_FP16                        17.629  17.277     1.02   
DenseNet_121::DNNTestNetwork::OCV/CPU                     24.735  23.863     1.04   
DenseNet_121::DNNTestNetwork::OCV/OCL                     24.991  25.140     0.99   
DenseNet_121::DNNTestNetwork::OCV/OCL_FP16                24.598  24.019     1.02   
EAST_text_detection::DNNTestNetwork::OCV/CPU              26.929  27.084     0.99   
EAST_text_detection::DNNTestNetwork::OCV/OCL              26.863  27.531     0.98   
EAST_text_detection::DNNTestNetwork::OCV/OCL_FP16         26.884  27.082     0.99   
EfficientDet::DNNTestNetwork::OCV/CPU                     62.667  62.716     1.00   
EfficientDet_int8::DNNTestNetwork::OCV/CPU                34.446  34.796     0.99   
EfficientNet::DNNTestNetwork::OCV/CPU                     11.875  11.786     1.01   
EfficientNet::DNNTestNetwork::OCV/OCL                     12.434  11.806     1.05   
EfficientNet::DNNTestNetwork::OCV/OCL_FP16                11.886  11.899     1.00   
FastNeuralStyle_eccv16::DNNTestNetwork::OCV/CPU           15.104  14.327     1.05   
FastNeuralStyle_eccv16::DNNTestNetwork::OCV/OCL           15.071  14.670     1.03   
FastNeuralStyle_eccv16::DNNTestNetwork::OCV/OCL_FP16      15.262  14.072     1.08   
GoogLeNet::DNNTestNetwork::OCV/CPU                         5.030   5.031     1.00   
GoogLeNet::DNNTestNetwork::OCV/OCL                         5.075   5.017     1.01   
GoogLeNet::DNNTestNetwork::OCV/OCL_FP16                    5.053   5.055     1.00   
Inception_5h::DNNTestNetwork::OCV/CPU                      6.777   6.430     1.05   
Inception_5h::DNNTestNetwork::OCV/OCL                      7.309   6.683     1.09   
Inception_5h::DNNTestNetwork::OCV/OCL_FP16                 6.624   6.549     1.01   
Inception_v2_Faster_RCNN::DNNTestNetwork::OCV/CPU         86.676  82.918     1.05   
Inception_v2_Faster_RCNN::DNNTestNetwork::OCV/OCL         85.460  84.873     1.01   
Inception_v2_SSD_TensorFlow::DNNTestNetwork::OCV/CPU      16.007  15.723     1.02   
Inception_v2_SSD_TensorFlow::DNNTestNetwork::OCV/OCL      15.974  16.015     1.00   
Inception_v2_SSD_TensorFlow::DNNTestNetwork::OCV/OCL_FP16 16.219  15.593     1.04   
MPHand::DNNTestNetwork::OCV/CPU                            3.273   3.313     0.99   
MPHand::DNNTestNetwork::OCV/OCL                            3.466   3.318     1.04   
MPHand::DNNTestNetwork::OCV/OCL_FP16                       3.314   3.258     1.02   
MPPalm::DNNTestNetwork::OCV/CPU                            2.839   1.973     1.44   
MPPalm::DNNTestNetwork::OCV/OCL                            2.773   2.132     1.30   
MPPalm::DNNTestNetwork::OCV/OCL_FP16                       2.783   2.133     1.30   
MPPose::DNNTestNetwork::OCV/CPU                            7.644   8.711     0.88   
MPPose::DNNTestNetwork::OCV/OCL                            7.555   7.210     1.05   
MPPose::DNNTestNetwork::OCV/OCL_FP16                       7.564   7.559     1.00   
MobileNet_SSD_Caffe::DNNTestNetwork::OCV/CPU               9.040   8.813     1.03   
MobileNet_SSD_Caffe::DNNTestNetwork::OCV/OCL               8.692   9.481     0.92   
MobileNet_SSD_Caffe::DNNTestNetwork::OCV/OCL_FP16          8.792   8.884     0.99   
MobileNet_SSD_v1_TensorFlow::DNNTestNetwork::OCV/CPU       7.893   7.735     1.02   
MobileNet_SSD_v1_TensorFlow::DNNTestNetwork::OCV/OCL       8.233   7.816     1.05   
MobileNet_SSD_v1_TensorFlow::DNNTestNetwork::OCV/OCL_FP16  7.949   7.817     1.02   
MobileNet_SSD_v2_TensorFlow::DNNTestNetwork::OCV/CPU      14.373  15.282     0.94   
MobileNet_SSD_v2_TensorFlow::DNNTestNetwork::OCV/OCL      14.218  15.788     0.90   
MobileNet_SSD_v2_TensorFlow::DNNTestNetwork::OCV/OCL_FP16 14.473  14.853     0.97   
MobileNetv2_ONNX::DNNTestNetwork::OCV/CPU                  1.507   1.440     1.05   
MobileNetv2_ONNX::DNNTestNetwork::OCV/OCL                  1.529   1.394     1.10   
MobileNetv2_ONNX::DNNTestNetwork::OCV/OCL_FP16             1.448   1.433     1.01   
PPHumanSeg::DNNTestNetwork::OCV/CPU                        2.302   1.919     1.20   
PPHumanSeg::DNNTestNetwork::OCV/OCL                        2.097   1.865     1.12   
PPHumanSeg::DNNTestNetwork::OCV/OCL_FP16                   2.129   1.908     1.12   
PPOCRv3::DNNTestNetwork::OCV/CPU                          20.612  20.858     0.99   
PPOCRv3::DNNTestNetwork::OCV/OCL                          21.672  21.444     1.01   
PPOCRv3::DNNTestNetwork::OCV/OCL_FP16                     22.660  20.857     1.09   
ResNet50_QDQ_ONNX::DNNTestNetwork::OCV/CPU                 6.443   6.718     0.96   
ResNet50_QDQ_ONNX::DNNTestNetwork::OCV/OCL                 6.842   6.823     1.00   
ResNet50_QDQ_ONNX::DNNTestNetwork::OCV/OCL_FP16            6.895   6.579     1.05   
ResNet_50_v1_ONNX::DNNTestNetwork::OCV/CPU                 7.669   7.629     1.01   
ResNet_50_v1_ONNX::DNNTestNetwork::OCV/OCL                 7.514   7.473     1.01   
ResNet_50_v1_ONNX::DNNTestNetwork::OCV/OCL_FP16            7.598   7.513     1.01   
SFace::DNNTestNetwork::OCV/CPU                             3.427   3.334     1.03   
SFace::DNNTestNetwork::OCV/OCL                             3.420   3.337     1.02   
SFace::DNNTestNetwork::OCV/OCL_FP16                        3.497   3.375     1.04   
SSD::DNNTestNetwork::OCV/CPU                              83.165  83.476     1.00   
SSD::DNNTestNetwork::OCV/OCL                              83.531  84.121     0.99   
SSD::DNNTestNetwork::OCV/OCL_FP16                         82.447  83.234     0.99   
SqueezeNet_v1_1::DNNTestNetwork::OCV/CPU                   1.334   1.308     1.02   
SqueezeNet_v1_1::DNNTestNetwork::OCV/OCL                   1.279   1.313     0.97   
SqueezeNet_v1_1::DNNTestNetwork::OCV/OCL_FP16              1.429   1.290     1.11   
VIT_Base_Patch16_224::DNNTestNetwork::OCV/CPU             71.211  75.013     0.95   
VIT_Base_Patch16_224::DNNTestNetwork::OCV/OCL             71.988  71.218     1.01   
VIT_Base_Patch16_224::DNNTestNetwork::OCV/OCL_FP16        73.700  82.285     0.90   
VitTrack::DNNTestNetwork::OCV/CPU                          4.096   2.091     1.96   
VitTrack::DNNTestNetwork::OCV/OCL                          3.830   2.056     1.86   
VitTrack::DNNTestNetwork::OCV/OCL_FP16                     3.796   2.110     1.80   
YOLOX::DNNTestNetwork::OCV/CPU                            24.346  23.079     1.05   
YOLOX::DNNTestNetwork::OCV/OCL                            24.442  23.459     1.04   
YOLOX::DNNTestNetwork::OCV/OCL_FP16                       23.947  23.327     1.03   
YOLOv3::DNNTestNetwork::OCV/CPU                           59.140  59.140     1.00   
YOLOv3::DNNTestNetwork::OCV/OCL                           46.725  45.292     1.03   
YOLOv3::DNNTestNetwork::OCV/OCL_FP16                      46.939  45.382     1.03   
YOLOv4::DNNTestNetwork::OCV/CPU                           70.062  68.145     1.03   
YOLOv4::DNNTestNetwork::OCV/OCL                           219.570 214.823    1.02   
YOLOv4::DNNTestNetwork::OCV/OCL_FP16                      219.276 213.472    1.03   
YOLOv4_tiny::DNNTestNetwork::OCV/CPU                       8.362   8.221     1.02   
YOLOv4_tiny::DNNTestNetwork::OCV/OCL                       8.373   8.095     1.03   
YOLOv4_tiny::DNNTestNetwork::OCV/OCL_FP16                  8.830   8.088     1.09   
YOLOv5::DNNTestNetwork::OCV/CPU                            9.237   8.484     1.09   
YOLOv5::DNNTestNetwork::OCV/OCL                            8.776   8.537     1.03   
YOLOv5::DNNTestNetwork::OCV/OCL_FP16                       8.747   8.536     1.02   
YOLOv8::DNNTestNetwork::OCV/CPU                           11.019  11.463     0.96   
YOLOv8::DNNTestNetwork::OCV/OCL                           11.204  10.766     1.04   
YOLOv8::DNNTestNetwork::OCV/OCL_FP16                      11.355  10.764     1.05   
YuNet::DNNTestNetwork::OCV/CPU                             3.371   3.466     0.97   
YuNet::DNNTestNetwork::OCV/OCL                             3.396   3.105     1.09   
YuNet::DNNTestNetwork::OCV/OCL_FP16                        3.150   3.130     1.01   
```

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-05-06 11:54:40 +03:00
Prasad Ayush Kumar 5af1571073 Darknet cleanup 2026-04-30 14:43:11 +05:30
Abhishek Gola c83b86eb57 Merge pull request #28811 from abhishek-gola:qlinear_support
Added QLinear layer support #28811

closes: https://github.com/opencv/opencv/issues/26310

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-04-28 17:38:29 +03:00
Abhishek Gola c44d03d8e1 added eyelike layer support 2026-04-14 11:49:12 +05:30
Abhishek Gola de851d24a5 Merge pull request #28121 from abhishek-gola:loop_layer_add
Add Loop layer to new DNN engine #28121

Addition of loop layer in 5.x for issue: https://github.com/opencv/opencv/issues/26179 and https://github.com/opencv/opencv/issues/26141 and https://github.com/opencv/opencv/issues/25200

OpenCV Extra: https://github.com/opencv/opencv_extra/pull/1335

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-04-14 09:15:46 +03:00
Abhishek Gola 3d77645a3a Merge pull request #28750 from abhishek-gola:activation_fusion
Extended fusion for activation functions in new DNN engine #28750

After this fusion, we see following improvements in YOLO models:

| Model | Before (`ENGINE_NEW`) | After (`ENGINE_NEW`) | `ENGINE_ORT` | % Improvement (Before v/s After) |
| :--- | :--- | :--- | :--- | :--- |
| **YOLOv8n** | 18.89  ms| 12.06 ms| 12.15 ms| 36.16% |
| **YOLOv5n** | 17.12  ms| 9.29 ms| 9.23 ms| 45.73% |
| **YOLOX-S** | 38.78  ms| 25.56 ms| 25.16 ms| 34.09% |

Device details: 
      - Model name: Intel(R) Core(TM) i9-14900KS, x86, 32 Cores, ubuntu 24.04,
### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-04-14 09:08:14 +03:00
Abhishek Gola 53d9a67cf3 Merge pull request #28741 from abhishek-gola:int8_block_layout
Int8 block layout support #28741

After this patch we got the following speed ups on **resnet50-qdq.onnx** model.

- Inference time now: **_~6.6ms_** (inference time using onnxruntime is ~5.7ms).
- Inference time before: _**~11.5ms**_ [after QDQ PR #28595]
- Speed up: _**~42.6% or 1.74x**_
- Device details:
- Model name: Intel(R) Core(TM) i9-14900KS, x86, 32 Cores, ubuntu 24.04, 

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-04-12 19:40:03 +03:00
Abhishek Gola 2ec6a6bb65 Merge pull request #28588 from abhishek-gola:ORT_GPU_wrapper
Added OnnxRuntime GPU wrapper #28588

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-04-06 15:40:58 +03:00
Jorge Velez a49a293d3c Merge pull request #27534 from JorgeV92:gsoc2025-tokenizer
GSoC 2025: Add Tokenizer Support to DNN Module #27534

merge with https://github.com/opencv/opencv_extra/pull/1276

### Summary
This pull request introduces initial support for a tokenizer module under `modules/dnn/src/tokenizer` as part of Google Summer of Code 2025 (Project: Tokenization for OpenCV DNN).

### Status
- [x] Project structure in place
- [x] Initial BPE tokenizer loading
- [x] Regex splitting (in progress)
- [x] Encoding logic for GPT-2 tokenizer (in progress)
- [ ] Documentation (to be improved)

### Goals
The goal is to support Hugging Face-compatible tokenization (e.g., GPT-2) natively in C++ to be integrated with DNN inference pipelines. 

The core pipeline lives in `dnn/src/tokenizer/core_bpe.hpp` and `dnn/src/tokenizer/encoding.hpp`. For Unicode handling I’m using `dnn/src/tokenizer/unicode.hpp`, which is adapted from llama.cpp.


### Feedback
Please share early feedback on:
- General design structure
- Integration strategy with `dnn`
- Code organization or naming conventions

### Reference
Project: https://summerofcode.withgoogle.com/programs/2025/projects/79SW6eNK
2026-04-06 10:46:13 +03:00
Abhishek Gola e59506bbf5 Merge pull request #28595 from abhishek-gola:qdq_support
* added qdq fusion

* Added VNNI optimizations
2026-03-31 15:16:09 +03:00
Abhishek Gola 40ce5b4132 Merge pull request #28637 from abhishek-gola:old_dnn_tickets_cleanup
Added Output Tensor Names support in new DNN engine #28637

closes: https://github.com/opencv/opencv/issues/26201

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-03-26 15:07:56 +03:00
Vadim Pisarevsky 1b483ffea6 Merge pull request #28585 from vpisarev:dnn_block_layout_v5
Block layout-based convolution in DNN #28585

merge together with https://github.com/opencv/opencv_extra/pull/1321

Some core parts of the new engine in DNN module have been revised substantially:

1. all tests seem to pass, except for `Test_Graph_Simplifier.ResizeSubgraph`, which has been disabled because it does not take the newly added `TransformLayoutLayer` into account. The test should be reworked perhaps.
1. convolution and related operations (maxpool/avgpool) now use so-called block layout (`DATA_LAYOUT_BLOCK`), where `NxCxHxW` tensors are represented  as `NxC1xHxWxC0`, where `C1=(C + C0-1)/C0` and `C0` is a power-of-two (usually 4, 8, 16 or 32).
1. graph is now pre-processed and `TransformLayoutLayer` is inserted to convert data from NCHW or NHWC layout to the block layout or vice versa. The transformations are done in a lazy way only when they are really needed. For example, in the whole Resnet only 2 transformations are performed.
1. transformer-based models and other models that do not use convolutions will run as usual, without going to block layout.
1. there is yet another graph preprocessing stage added that embeds constant weights/scale and bias into convolution and batch norm layers.
1. 'batchnorm', 'activation' and 'adding a residual' are now fused with convolution, just like in the old engine. That brings some noticeable acceleration.
1. optimized convolution kernels have been added.
     * depthwise convolution, as well as maxpool and avgpool support C0=4, 8, 16 etc. _as long as_  C0 is divisible by the number of fp32 lanes in a SIMD register of the target platform (e.g. on ARM with NEON there must be `C0 % 4 == 0`, on x64 with AVX2 `C0 % 8 == 0`).
     * non-depthwise convolution only supports C0=8 for now. C0=8 seems to be a sweetspot for ARM with NEON, x64 with AVX2 or RISC-V with RVV (with 128- or 256-bit registers). For some platforms with dedicated matrix accelerators C0=16 or even C0=32 might be more efficient, but we could add the respective kernels later.
     * only fp32 kernels have been added. fp16/bf16 kernels might be added a little later.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
- [x] Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2026-03-13 17:09:27 +03:00
Abhishek Gola 95c66292b5 Merge pull request #28444 from abhishek-gola:added_ORT_wrapper
Added ONNX Runtime as an optional wrapper #28444

This PR adds ONNXRuntime (ORT) as an _optional_ wrapper, which can be enabled by adding **WITH_ONNXRUNTIME** flag in CMake command.

Using ORT wrapper the inference time for _resnet50.onnx model_ has come to _**~7ms**_ from _**~14ms**_.
Also, we are able to run models like `ssd_mobilenet_v1.onnx`.
### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-02-27 15:47:12 +03:00
Alexander Smorkalov ca69b54521 Merge pull request #28522 from abhishek-gola:batchnorm_layer_add
Added Batch Normalization layer to new DNN engine
2026-02-15 10:31:23 +03:00
Alexander Smorkalov 82ff8e45e9 Merge branch 4.x 2026-02-14 15:37:33 +03:00
Abhishek Gola 6420d2b929 Added batchnorm layer 2026-02-11 16:22:20 +05:30
Abhishek Gola 1719aa1339 Merge pull request #28453 from abhishek-gola:roialign_layer_add
Added RoiAlign layer support in new DNN engine #28453

Fixes `Unsupported Operation: RoiAlign` issue in https://github.com/opencv/opencv/issues/20258 and https://github.com/opencv/opencv/issues/22099, model parsing is successful now.

Merge with: https://github.com/opencv/opencv_extra/pull/1310

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-02-10 14:45:56 +03:00
Abhishek Gola abc9100c9b added layer norm 2026-01-29 12:58:31 +05:30
nklskyoy d851f3bc80 Merge pull request #27988 from nklskyoy:attention-2-layer
AttentionOnnxAiLayer #27988 
 
Implements https://onnx.ai/onnx/operators/onnx__Attention.html#attention-23

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2026-01-26 15:58:13 +03:00
Alexander Smorkalov e63d2a12f0 pre: OpenCV 4.13.0 (version++). 2025-12-23 18:31:50 +03:00
Abhishek Gola eb36a78f5e Merge pull request #28075 from abhishek-gola:hann-hamming-blackman-support
Added Hannwindow, Hammingwindow & Blackmanwindow support #28075

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-12-23 16:37:45 +03:00
Abhishek Gola 2ea31d5075 Merge pull request #28110 from abhishek-gola:randomNormalLike_layer
Added RandomNormalLike layer for fixing ViTs parsing issue #28110
 
closes: https://github.com/opencv/opencv/issues/27603
### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-12-16 20:48:36 +03:00
nklskyoy d218732a70 Merge pull request #28104 from nklskyoy:rms-norm
RMSNorm: reference cpu impl #28104

https://onnx.ai/onnx/operators/onnx__RMSNormalization.html

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2025-12-13 09:41:44 +03:00
nklskyoy 74fae2770e Merge pull request #28031 from nklskyoy:rotary-position-layer
Rotary position layer #28031

Implemented https://onnx.ai/onnx/operators/onnx__RotaryEmbedding.html#rotaryembedding-23

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2025-11-25 15:12:17 +03:00
Abhishek Gola b8c9c070ea Merge pull request #27894 from abhishek-gola:affine_layer_add
Added affine grid layer to new DNN engine #27894

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-11-11 16:36:08 +03:00
Abhishek Gola 21b2c91814 Merge pull request #27941 from abhishek-gola:dft_layer_add
Added DFT layer to new DNN engine #27941

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-11-11 13:28:24 +03:00
Abhishek Gola e9298fb73e Merge pull request #27902 from abhishek-gola:onehot_layer_add
Added Onehot layer support to new DNN engine #27902

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-10-30 22:21:14 +03:00
Abhishek Gola e794c11b0b Merge pull request #27892 from abhishek-gola:center_crop_pad_layer
Added center crop pad layer to new DNN engine #27892

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-10-13 15:11:23 +03:00
Abhishek Gola 91768f9a27 Merge pull request #27809 from abhishek-gola:softmax_cross_entropy
Added support for SCE and NLL losses #27809

This pull request adds the support for Negative Log-Likelihood loss and Softmax Cross-Entropy loss in new DNN engine.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-10-11 12:45:17 +03:00
Abhishek Gola 93385c6cdf Merge pull request #27816 from abhishek-gola:reduce_layer
Extended Reduce layer support in new DNN engine #27816

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-10-10 10:11:19 +03:00
Abhishek Gola 2470c07f1b Merge pull request #27698 from abhishek-gola:add_cast_layer
Added cast and castlike layers support in new DNN engine #27698

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-10-04 13:22:30 +03:00
Abhishek Gola d79e95c018 Merge pull request #27674 from abhishek-gola:nonmaxsuppression_layer_add
Added nonmaxsuppression (NMS) layer to new DNN engine #27674

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-09-19 12:55:37 +03:00
Abhishek Gola 68a5aea843 Merge pull request #27586 from abhishek-gola:resize_layer_add
Added fully functional resize layer to new DNN engine #27586

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-09-18 09:17:04 +03:00
Abhishek Gola cd4f2c2561 Merge pull request #27676 from abhishek-gola:unique_layer_add
Added unique layer to new DNN engine #27676

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-09-17 16:04:52 +03:00
Vadim Pisarevsky bdab54f79e Merge pull request #27757 from vpisarev:matshape_inside_mat
Use MatShape instead of MatSize inside cv::Mat/cv::UMat #27757

**Merge together with https://github.com/opencv/opencv_contrib/pull/3996**
---

This PR continues cv::Mat/cv::UMat refactoring. See #26056, where `MatShape` was introduced. Now it's put inside cv::Mat/cv::UMat instead of a weird `MatSize`. MatSize is now an alias for MatShape:

**before:**

```
struct MatShape { ... };
struct MatSize { ... };

struct Mat {
    ...
    int dims;
    int rows;
    int cols;

    ...

    MatShape shape() const { ... /* constructs MatShape out of MatSize and returns it;
                                    layout is always 'unknown', because we don't store it */ }

    MatSize size; // size is not valid without the parent cv::Mat,
                  // because size.p may point to Mat::rows or to Mat::cols,
                  // depending on the dimensionality, and dims() returns Mat::dims.
    MatStep step; // may allocate memory, depending on the dimensionality.
    ...
};
```

**after:**

```
struct MatShape { ... };
typedef MatShape MatSize; // they are now synonyms

struct Mat {
    ...
    int dims;
    int rows;
    int cols;

    ...

    MatShape shape() const { return size; } // just return the embedded shape (including the proper layout information)

    MatSize size; // size is self-contained data structure that can be used without the parent cv::Mat.
                  // size.dims is now a copy of dims; size.p[*] contains copies of Mat::rows and Mat::cols when dims <= 2.
    MatStep step; // does not allocate extra memory buffers.
    ...
};
```

There are several reasons to do that:

1. the main reason is to be able to store data layout (MatShape::layout) inside each cv::Mat/cv::UMat. This is necessary for the proper shape inference in DNN module. In particular, it's necessary for the next step of DNN inference optimization where we introduce block-layout-optimized convolution and other operations. Later on, we can use layout information to support non-interleaved images (e.g. RRR...GGG...BBB...) or even batches of such images in core/imgproc modules.
2. the other reason is to represent 3D/4D/5D etc. tensors as cv::Mat/cv::UMat instances more conveniently, without extra dynamic memory allocation. Before this patch we allocated some memory buffers dynamically to store shape & steps for more than 2D arrays. Now the whole cv::Mat/cv::UMat header can be stored completely on stack/in a container. Creating another copy of Mat/UMat header is now done more efficiently.
3. the third reason is to introduce the new coding pattern: `dst.create(src.size, <dst_type>);`. The pattern is suitable for most of element-wise (including cloning) and filtering operations. This pattern does not only look crisp and self-documenting, it will also automatically copy shape (including layout) from the source tensor into the destination matrix/tensor.
4. in the future we might add `colorspace` member to MatShape that will allow to distinguish RGB from BGR or NV12. `dst.create(src.size, <dst_type>);` will then copy the colorspace information as well.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-09-15 15:03:34 +03:00
Abhishek Gola 105a3c335b Merge pull request #27701 from abhishek-gola:nonzero_layer_add
Added nonzero layer to new DNN engine #27701

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-09-12 08:51:20 +03:00
Abhishek Gola f67ae273b3 Merge pull request #27700 from abhishek-gola:gridsample_layer_add
Added gridsample layer to new DNN engine #27700

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-09-09 14:45:13 +03:00
Abhishek Gola defc988c0d Merge pull request #27666 from abhishek-gola:bitshift_layer_add
Added bitshift layer to new DNN engine #27666

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2025-08-18 17:33:28 +03:00