Commit Graph

570 Commits

Author SHA1 Message Date
Abhishek Gola
c4f7634256 Merge pull request #30183 from abhishek-gola/python-ml-dtypes
python: keep exact bfloat16 / float8 dtypes in the bindings via ml_dtypes
2026-10-31 20:26:08 +05:30
Abhishek Gola
782daa0ab9 python: wrap long lines in the bfloat16 / float8 binding code and tests
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-10-30 16:04:56 +05:30
Abhishek Gola
26bd26e400 python: rename setAllowNonConventionalDataTypes() / getAllowNonConventionalDataTypes() to setUseExactNumpyDtypes() / useExactNumpyDtypes()
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-10-30 16:00:13 +05:30
Abhishek Gola
8751eb491e python: drop the CV_16BF -> float32 mapping, share the empty / 0-D output path, run flag tests without ml_dtypes
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-10-30 15:59:00 +05:30
Vladimir Iglovikov
47ca334d41 fix(python): handle byte-swapped NumPy inputs on 5.x 2026-10-29 21:39:48 +05:45
Abhishek Gola
3f7c2f7077 python: limit setAllowNonConventionalDataTypes() to outputs, fix short ml_dtypes operands, document it
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-10-28 18:19:43 +05:30
Maidul Hasan Masum
ad833bee96 Merge pull request #30549 from mh-masum6875:docs-python-signatures-5x
python: add documentation signatures for hand-wrapped highgui functions - #30549

Port of #30508 to 5.x

`createTrackbar`, `createButton` and `setMouseCallback` are registered by hand in `cv2.cpp`, so `gen2.py` never sees them and they end up with no Python signature in the generated docs.

Argument names come from the keyword lists in `cv2_highgui.cpp`, which is why `setMouseCallback` reads `window_name, on_mouse` rather than the camelCase in its `cv2.cpp` docstring.

### 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
- [ ] 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-10-28 14:28:52 +03:00
Vladimir Iglovikov
1efa7e9c12 fix(python): accept NumPy inputs in UMat constructor stubs 2026-10-19 16:34:51 +03:00
Vladimir Iglovikov
e0d92ceb00 fix(python): accept scalar min and max operands in stubs 2026-10-17 07:28:37 +05:45
Vladimir Iglovikov
c245b01e9f fix(python): accept scalar and empty InputArray arguments in stubs 2026-10-16 14:11:31 +05:45
Abhishek Gola
2dc797b92e python: return the existing ndarray for bfloat16 / float8 Mats instead of a copy
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-10-14 17:45:25 +05:30
Abhishek Gola
f527a649bf refactoring 2026-10-14 17:40:19 +05:30
Abhishek Gola
7feb8acd5e python: gate bfloat16 / float8 dtypes behind setAllowNonConventionalDataTypes() and drop the ml_dtypes import
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-10-14 17:36:26 +05:30
Abhishek Gola
3f426d1f1b Merge pull request #30207 from abhishek-gola:core-drop-nd-suffix
drop ND prefix from the functions - #30207

Merge pull request #30207 from abhishek-gola:core-drop-nd-suffix

### 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-10-14 11:26:22 +03:00
Abhishek Gola
3220c1b35d python: warn once when ml_dtypes is missing and bfloat16 / float8 are widened to float32
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-10-09 15:34:49 +05:30
Abhishek Gola
634d639930 python: publish CV_16BF / CV_8F_E4M3FN / CV_8F_E4M3FNUZ type constants
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-10-09 14:21:39 +05:30
Abhishek Gola
252b03de39 python: cross the binding with exact bfloat16 / float8 dtypes
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-10-08 14:29:16 +05:30
Savya Sanchi Sharma
68fd896a44 Merge pull request #30173 from SavyaSanchi-Sharma:calib/fisheye
Calib: assersion fix of fisheye calib - #30173

Replaces a CV_Assert in fisheye::InitExtrinsics with a graceful failure path (returns bool, caller now throws a descriptive StsBadArg naming the degenerate view) instead of crashing on a hard assert. Also adds validation that rejects legacy numeric  flag values passed to fisheye::calibrate/stereoCalibrate, and fixes CALIB_CHECK_COND to actually gate the condition check in stereo calibration. Includes an hdr_parser.py change to resolve using Base::CONST enum aliases for Python bindings.

### 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-10-08 11:12:30 +03:00
Kari Pikkarainen
41ef839c7d Merge pull request #30148 from kari-pikkarainen:fix/python-stubs-optional-output-args-5.x
python: mark documented None output arrays as optional in typing stubs (5.x) 🤖🤖🤖 - #30148

Port of #30139 to 5.x, as requested in https://github.com/opencv/opencv/pull/30139#issuecomment-5994064397. Relates to #30138.

The two commits are cherry-picked from #30139 without code changes. The second commit message is reworded for the 5.x module layout.

**Commit 1:** adds `make_optional_arg` entries to `NODES_TO_REFINE` in `modules/python/src2/typing_stubs_generation/api_refinement.py`. These output arrays are documented and used with `None` in the 5.x samples and tutorials, but the stubs type them as required, so mypy rejects correct code:

| Function | Argument |
|---|---|
| `calcOpticalFlowPyrLK` | `nextPts` |
| `calcOpticalFlowFarneback` | `flow` |
| `normalize` | `dst` |
| `kmeans` | `bestLabels` |
| `drawKeypoints` | `outImage` |
| `drawMatches` | `outImg` |
| `drawMatchesKnn` | `outImg` |

**Commit 2:** skips `NODES_TO_REFINE` entries whose function, class or namespace is absent from the build, as the `dnn`/`cuda` refinements already do. On 5.x this also fixes an existing failure: with `-DBUILD_opencv_calib=OFF`, the `calibrateCamera` entry raises `SymbolNotFoundError` and no stubs are generated at all. A wrong argument name in a present function still raises `RuntimeError`.

### Verification

I ran CMake configure only, then `gen2.py` from this branch and from `5.x` (2d88732) on the generated `gen_python_config.json`, with `PYTHONHASHSEED=0`:

- **Full build:** the only differences are 16 signatures in `cv2/__init__.pyi`. Each listed argument changes from `cv2.typing.MatLike` / `UMat` to `... | None`, across the Mat and UMat overloads, and `drawMatches` has two C++ overloads.
- **`-DBUILD_opencv_video=OFF`:** stubs are generated. The two optical-flow entries are skipped and the other refinements still apply.
- **`-DBUILD_opencv_calib=OFF`:** `5.x` generates no stubs (`SymbolNotFoundError` for `calibrateCamera`). This branch generates them.
- **mypy 2.4.0:** I installed the generated stubs as a stub-only package and type-checked calls that pass `None` for each argument, e.g. `cv2.normalize(img, None, 0, 255, cv2.NORM_MINMAX)`. With the `5.x` stubs there are 11 `call-overload` errors; with this branch there are none.

Builds without `features` still fail for a separate reason, the `Feature2D` aliases in `predefined_types.py`. I'll address that in a follow-up.

_Prepared with AI assistance (Claude Code); I reviewed the change and the verification results._

### 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
- [ ] 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

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-10-06 08:40:49 +03:00
Eugenio "Jay" Zuccarelli
05b1114930 python: typing stubs: import typing for Sequence return types
SequenceTypeNode and ClassTypeNode always format as _typing.Sequence[...]
and _typing.Type[...], but ContainerTypeNode only reports the typing
import as required when compatible_to_runtime_usage is set. Stubs for
modules that use these nodes without any other _typing usage (e.g.
cv2/videoio_registry) reference _typing without importing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 10:46:39 +00:00
Vincent Rabaud
747ffc57be Merge pull request #30040 from vrabaud:function_ptr
Fix function pointer signature mismatches - #30040

Contrib PR: https://github.com/opencv/opencv_contrib/pull/4224

Calling a function through a function pointer with a mismatched signature is undefined behavior in C/C++ and causes Clang Control Flow Integrity to trap with `SIGILL` (`ud1`) at indirect call sites.

This is a follow-up on https://github.com/opencv/opencv/pull/28939

### 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
- [ ] 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-09-23 10:44:20 +03:00
Alexander Smorkalov
ec77d2ea85 Fixed type conflict in python bindings. 2026-09-01 13:08:06 +03:00
Prasad Ayush Kumar
e62a7038d5 Merge pull request #29767 from Prasadayus:fix/int32_output
python: fix int32 output arrays on Windows by mapping 32-bit NPY_LONG - #29767

On Windows numpy spells `int32` as C `long`, so such arrays arrive as `NPY_LONG` (typenum 7) instead of `NPY_INT` (5). `numpyTypeToCvDepth()` has no case for it, so `pyopencv_to()` takes the cast-and-copy path — which is rejected for **output** arguments, even though the data is already bit-identical to `CV_32S`:

```python
cv.watershed(img, np.int32(markers))
```

```
cv2.error: (-5:Bad argument) in function 'watershed'
> Overload resolution failed:
>  - Layout of the output array markers is incompatible with cv::Mat
```

Three tests fail on Windows for this reason, all on an int32 output argument (`markers`, `detectedIds`):

- `test_watershed`
- `test_aruco_detector_refine`
- `test_charuco_refine`

### 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-09-01 11:32:39 +03:00
Abhishek Gola
c7dd924be3 Merge pull request #29594 from abhishek-gola:bitcast_matmul_dft_layers
Added Bitcast layer & extended MatMul and DFT layers support - #29594

### 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-09-01 10:23:57 +03:00
Abhishek Gola
0627765f01 Merge pull request #29360 from abhishek-gola:exotic_cast_operations
Support ONNX Cast/CastLike for FP8/FP4/INT4/UINT4/E8M0 dtypes - #29360

### 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-08-31 09:05:29 +03:00
NIKHIL
6f71f201ee Fix silent loss of high-channel ndarray dimensions
Detect three-dimensional NumPy arrays as multichannel inputs before applying the channel limit so OpenCV reports an explicit conversion error instead of treating the channel axis as a matrix dimension. Add regression coverage for a 129-channel remap input.

Assisted-by: OpenAI Codex
2026-08-09 19:52:07 +05:30
vrooomy
6e338fb03b extract test list into a separate .py file 2026-08-04 13:46:33 +05:30
vrooomy
5fcdb9b01e code cleanup 2026-08-03 14:41:43 +05:30
vrooomy
25ed5d4c0d map 64bit int anf bfloat16 2026-08-03 12:26:19 +05:30
Abhishek Gola
319a03a2c9 added m.empty() 2026-07-22 14:22:40 +05:30
Abhishek Gola
ae392712b1 onnx coverage 2026-07-15 17:26:50 +05:30
Alexander Smorkalov
59218f9edd Merge pull request #29175 from asmorkalov:as/geometry2
Geometry module #29175

OpenCV Contrib: https://github.com/opencv/opencv_contrib/pull/4129
CI changes: https://github.com/opencv/ci-gha-workflow/pull/313

Continues
- https://github.com/opencv/opencv/pull/28804
- https://github.com/opencv/opencv/pull/29101
- https://github.com/opencv/opencv/pull/29108
- https://github.com/opencv/opencv/pull/28810

Todo for followup PRs:
- [x] Rename doxygen groups
- [x] Fix JS modules layout and whitelists
- [ ] Sort tutorials code/snippets

### 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
- [ ] 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-31 14:23:15 +03:00
Prasad Ayush Kumar
223b110c30 Merge pull request #28968 from Prasadayus:Identity_function_fix_for_0D
Fixes the issue for Identity functions for 0D #28968

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

### 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-12 14:43:46 +03:00
Alexander Smorkalov
1a6f669763 Merge branch 4.x 2026-04-09 18:44:48 +03:00
LHOOL1109
9dba8a7df0 Merge pull request #28747 from LHOOL1109:fix/python-zero-channel-crash
python: fix segfault on 0-channel numpy array input #28747

### Pull Request Readiness Checklist

- [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
      N/A: a Python unit test is added in `modules/python/test/test_mat.py`. No external test data required.
- [x] The feature is well documented and sample code can be built with the project CMake
      N/A: this is a bug fix, not a new feature. No documentation update needed.

### Problem

Passing a numpy array with shape `(H, W, 0)` (0 channels) to any OpenCV function that accepts a `Mat` argument (e.g. `cv2.resize`, `cv2.warpAffine`, `cv2.blur`) causes a **segfault**.

**Reproducer:**
```python
import cv2
import numpy as np

arr = np.zeros((100, 100, 0), np.uint8)
cv2.resize(arr, (200, 200))  # segfault
```

### Root Cause

In `modules/python/src2/cv2_convert.cpp`, the numpy→Mat conversion checks channel validity only against `CV_CN_MAX` (upper bound):

```cpp
if (channels > CV_CN_MAX)   // channels=0 passes this check
```

With `channels=0`, `CV_MAKETYPE(0, 0)` produces `type=-8`, which corrupts the Mat's internal type field and causes undefined behavior downstream.

### Fix

Extend the check to also reject `channels < 1`:

```cpp
if (channels < 1 || channels > CV_CN_MAX)
```

**After fix:**
```
cv2.error: src unable to wrap channels, invalid count (0, must be in [1, 512])
```

### Notes

- This affects all functions that accept a `Mat` input, not just `cv2.resize`
- The same bug exists in the `5.x` branch
- A 0-channel array has no valid OpenCV Mat representation; rejecting it with a clear error is the correct behavior and poses no backward-compatibility risk (the previous behavior was a crash)
2026-04-03 14:26:18 +03:00
Alexander Smorkalov
b5a7e0c662 Merge branch 4.x 2026-03-19 11:29:57 +03:00
Pavel Guzenfeld
3779f630bc Clean up stale typing stubs during incremental builds
When a module is disabled in an incremental build (e.g. switching from
-DBUILD_opencv_gapi=ON to OFF), its typing stub directory persists from
the previous build.  The stubs generator only creates directories for
enabled modules but never removes old ones, and the copy step merges
rather than replaces, so stale .pyi files propagate to both the loader
directory and the install prefix.

This causes type-checkers (mypy, pyright) to report errors for stubs
that reference symbols from modules that are no longer available.

Fix both propagation paths:

- generation.py: remove all subdirectories under the stubs output root
  before regenerating, so only currently enabled module stubs exist in
  the build directory.  Top-level files (py.typed) are preserved.

- copy_typings_stubs_on_success.py: remove stale .pyi files and
  py.typed markers from the loader directory before copying fresh stubs,
  so leftover stubs from a previous copy are cleaned up.  Runtime .py
  files are not affected.
2026-03-16 23:41:37 +02:00
Pavel Guzenfeld
95ab7149fe Fix Python bindings when optional modules like gapi are disabled
Fix two issues that cause `import cv2` to fail when building with
-DBUILD_opencv_gapi=OFF:

1. In `has_all_required_modules()`, the function parameter `type_node`
   was ignored in favor of the enclosing scope's loop variable `node`.
   This works by accident when called as `has_all_required_modules(node)`
   but is incorrect — the parameter should be used directly.

2. In `__load_extra_py_code_for_module()`, only `ImportError` was
   caught. When a stale gapi submodule directory exists from a previous
   build, gapi/__init__.py raises `AttributeError` (not `ImportError`)
   because it tries to access C++ bindings that don't exist. Now catches
   both exception types for defense-in-depth.

Refs: #26098
2026-03-15 23:21:42 +02:00
Matt Van Horn
c3457f99f3 Merge pull request #28621 from mvanhorn:osc/28528-fix-houghcircles-return-type
imgproc: fix HoughCircles Python return type to allow None #28621

### 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
- [ ] 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

### Description

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

`HoughCircles` returns `None` when no circles are found, but the auto-generated Python type stub declares the return type as `MatLike` without `None`. This causes type checkers (mypy/pyright) to miss potential `None` dereferences.

**Fix:** Add `HoughCircles` to `NODES_TO_REFINE` in `api_refinement.py` using the existing `make_optional_none_return` helper - the same pattern already used for `imread` and `imdecode`.

This contribution was developed with AI assistance (Claude Code).
2026-03-11 08:55:36 +03:00
Murat Raimbekov
91c78f5064 Merge pull request #28309 from raimbekovm:fix-typos-batch6
docs: fix typos in documentation and code comments #28309

## Summary

This PR fixes 10 spelling errors in documentation and code comments across 7 files.

## Changes
- `suppport` → `support` (2 occurrences in test_video_io.cpp)
- `compability` → `compatibility` (2 occurrences in face.hpp)
- `successfull` → `successful` (1 occurrence in cv2.cpp)
- `accomodate` → `accommodate` (2 occurrences in calib3d.hpp and test_camera.cpp)
- `minimun` → `minimum` (1 occurrence in aruco_detector.hpp)
- `maximun` → `maximum` (1 occurrence in aruco_detector.hpp)
- `orignal` → `original` (1 occurrence in aruco_detector.cpp)

## Test plan
- [x] No API changes
- [x] Documentation-only changes
- [x] Code compiles without errors
2026-03-03 14:29:47 +03:00
Muhammad Awais
69bdcc9386 Merge pull request #28536 from Sikandar1310291:fix/inrange-typing-28534
Fix inRange type signature to accept Scalar values #28536

Fixes #28534

The Python type signature for cv2.inRange was too restrictive, requiring MatLike for lowerb and upperb parameters. However, the C++ implementation accepts InputArray which includes Scalar values (tuples, floats, etc.).

This caused type checkers to incorrectly flag valid code from official tutorials as type errors.

Added make_matlike_or_scalar_arg() refinement function to create union types MatLike | Scalar for affected parameters, matching the C++ InputArray behavior.

### 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-02 09:43:56 +03:00
Alexander Smorkalov
6c995c768f Merge branch 4.x 2026-02-20 22:05:35 +03:00
Satge96
d1e12b9aa9 fix: mark distCoeffs, cameraMatrix as optional in calibrateCamera function 2026-01-28 11:14:29 +01:00
Alexander Smorkalov
e466110245 Merge branch 4.x 2025-12-02 15:38:19 +03:00
Anshu
166f4591d2 Merge pull request #28047 from 0AnshuAditya0:fix-pyos-fspath-memory-leak
Fix memory leak in pyopencv_to for path-like objects #28047
   
This PR fixes a memory leak in pyopencv_to when handling path-like objects (e.g., pathlib.Path).
Problem:
PyOS_FSPath() returns a new strong reference, but the code was not calling Py_XDECREF to decrement it, causing a memory leak on every call with path-like arguments.
Solution:

Store the returned reference from PyOS_FSPath() in a separate variable path_obj
Call Py_XDECREF(path_obj) on all function exit paths (both success and error paths)
This ensures proper reference counting without changing the function's behavior

Testing:
The leak can be reproduced using the steps in issue #28046 with Python built with --with-address-sanitizer. This fix ensures the reference is properly released.
Fixes #28046

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

 ✓ I agree to contribute to the project under Apache 2 License.
 ✓ 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 (4.x)
 ✓ There is a reference to the original bug report and related work (#28046)
 NA 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-26 12:18:42 +03:00
Alexander Smorkalov
1b6fb61b89 Merge branch 4.x 2025-11-18 08:51:08 +03:00
Vadim Levin
17ce5a290b fix: use export_name as resolved typename for AliasTypeNode
Use ctype_name as export name for AliasTypeNode if export name is not
explicitly provided.
2025-11-12 10:30:31 +03:00
Alexander Smorkalov
1a74264ee9 Merge branch 4.x 2025-09-26 12:10:49 +03:00
Dmitry Kurtaev
4159c0ad98 Merge pull request #27779 from dkurt:dlpack_5.x_types
Add 5.x types for DLPack. Keep uint32/int64/uint64 data type for conversion to Numpy. More types support for GpuMat::convertTo #27779

### Pull Request Readiness Checklist

**Merge with contrib**: https://github.com/opencv/opencv_contrib/pull/4000

related: https://github.com/opencv/opencv/pull/27581

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-25 10:14:46 +03:00
Quaylyn Rimer
1fdff6da75 Merge pull request #27620 from killerdevildog:fix-scalar-typing-issue-27528
Fix Python Scalar typing issue #27528 #27620

- Add ScalarInput and ScalarOutput types for better type safety
- ScalarInput: Union[Sequence[float], float] for function parameters
- ScalarOutput: Sequence[float] for function return values
- Keep original Scalar type for backwards compatibility (deprecated)
- Add refinement functions to apply new types to specific functions
- Functions returning scalars now use ScalarOutput (mean, sumElems, trace)
- Drawing functions now use ScalarInput for color parameters
- Resolves MyPy compatibility issues with scalar return values
- Maintains full backwards compatibility

closes #27528 

### 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
- [ ] 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-10 16:47:12 +03:00