0
0
mirror of https://github.com/opencv/opencv.git synced 2026-01-18 17:21:42 +01:00

35924 Commits

Author SHA1 Message Date
Ghazi-raad
5a0679b862 Fix null pointer dereference in G-API stateful kernels
Fixes #28095

Problem:
- Stateful kernels dereference null state pointer on line 446 in gcpukernel.hpp
- jinboson confirmed state_ptr is null on x86 Ubuntu (7 hours ago)
- Causes crash with std::shared_ptr assertion on LoongArch64 and strict platforms

Solution (addressing Copilot review feedback from PR #28096):
1. Added null pointer check using CV_Error instead of CV_Assert:
   - CV_Assert with && 'message' doesn't display the message correctly
   - CV_Error properly reports cv::Error::StsNullPtr with clear message

2. Fixed test kernels to properly initialize state using std::make_shared:
   - GOCVStInvalidResize: Initialize state in setup()
   - GOCVCountStateSetups: Initialize state before incrementing counter
   - Used std::make_shared<int>() for modern C++ best practice

Impact:
- Prevents crashes on platforms with strict null pointer checking
- Provides actionable error message for developers
- Fixes StatefulKernel.StateInitOnceInRegularMode and InvalidReallocatingKernel tests
2025-12-06 12:45:48 +00:00
Kai Pastor
6fc0f38e1c Fix CMake foreach loops 2025-12-06 11:03:53 +01:00
Kumataro
29f44b4530 chore: Synchronize 3rdparty libpng version to 1.6.52 in README/CHANGES 2025-12-06 08:33:27 +09:00
Alexander Smorkalov
324d489e71 Updated libpng to v1.6.52 and added RISC-V optimimizations. (#28111)
* Updated libpng to v1.6.51 and added RISC-V optimimizations.

* Force 3rdparty build for CI test.

* Added RISC-V RVV diagnostics for PNG.

* RISC-V RVV diagnostic fix.

* Disabled incorrect in-place flip HAL on RISC-V RVV.

* Disabled risc-v rvv of  png_read_filter_row_paeth in libpng.

* Set PNG simd configuration defaults accornding to OpenCV settings.

* Update to libpng 1.6.52 with RISC-V RVV fix.

* Build fix for RISC-V RVV.

* Reverted CI changes.
2025-12-05 17:17:22 +03:00
Alexander Smorkalov
de660aedca Reverted CI changes. 2025-12-05 16:00:14 +03:00
Alexander Smorkalov
fd11f635c1 Merge pull request #28122 from asmorkalov:as/dynamic_openmp
Dropped OPENCV_FOR_OPENMP_DYNAMIC_DISABLE environment varibale in favor of standard OMP_DYNAMIC #28122

Fixes: https://github.com/opencv/opencv/issues/25717
Replaces: https://github.com/opencv/opencv/pull/28084

### 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-05 14:13:19 +03:00
Alexander Smorkalov
92ea2c324b Fixed unicode tracing symbols with QT. 2025-12-05 08:45:32 +03:00
Alexander Smorkalov
98d065370c Build fix for RISC-V RVV. 2025-12-05 08:08:36 +03:00
Alexander Smorkalov
d88f080b7e Update to libpng 1.6.52 with RISC-V RVV fix. 2025-12-05 07:52:26 +03:00
Alexander Smorkalov
ab23a89975 Set PNG simd configuration defaults accornding to OpenCV settings. 2025-12-04 18:07:21 +03:00
Alexander Smorkalov
8807d75566 Merge pull request #28125 from asmorkalov:as/disable_riscv_flip
Disabled incorrect in-place flip HAL on RISC-V RVV
2025-12-04 17:41:12 +03:00
Alexander Smorkalov
e669a955c7 Disabled risc-v rvv of png_read_filter_row_paeth in libpng. 2025-12-04 16:35:02 +03:00
Alexander Smorkalov
e5075ffa33 Disabled incorrect in-place flip HAL on RISC-V RVV. 2025-12-04 14:55:31 +03:00
Alexander Smorkalov
71d49c2dc2 Disabled incorrect in-place flip HAL on RISC-V RVV. 2025-12-04 14:53:33 +03:00
Alexander Smorkalov
1d8d76cd50 RISC-V RVV diagnostic fix. 2025-12-04 11:28:32 +03:00
Gursimar Singh
b1d75bf477 Merge pull request #28078 from gursimarsingh:codeql-migration
Adding github CodeQL #28078

Related pipeline in CI repo: https://github.com/opencv/ci-gha-workflow/pull/280

### 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
2025-12-03 11:15:59 +03:00
nishith-fujitsu
8efc0fd47b Merge pull request #28055 from nishith-fujitsu:sve_fastGEMM1t
dnn: add SVE optimized fastGEMM1T function and SVE dispatch #28055

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

**Description**
This PR enables fastGemm1t vectorized with SVE for AARCH64 architecture that called by recurrent layers and fully connected layers with SVE dispatching mechanism.

**ARM Compatibility:**
Modified the build scripts, and configuration files to ensure compatibility with ARM processors.

**Checklist**

Code changes have been tested on ARM devices (Graviton3).

**Modifications**

- Implemented FastGemm1T kernel in SVE with Vector length agnostic approach.

- Added Flags and checks to call our ported Kernel in Recurrent Layer and FullyConnected layer.

- Changes made to cmakelist.txt to dispatch our ported kernel for SVE.

- Flag OpenCV Dispatch with SVE optimization is added to support SVE implemented kernel for OpenCV. According to OpenCV build optimization https://github.com/opencv/opencv/wiki/CPU-optimizations-build-options 
cmake \
    -DCPU_BASELINE=NEON\
    -D CPU_DISPATCH=SVE\

**Performance Improvement**
- The suggested optimizations Improves the performance of LSTM layer and fully connected layer.
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">

<head>

<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 15">
<link id=Main-File rel=Main-File
href="file:///C:/Users/jaiswaln/AppData/Local/Temp/msohtmlclip1/01/clip.htm">
<link rel=File-List
href="file:///C:/Users/jaiswaln/AppData/Local/Temp/msohtmlclip1/01/clip_filelist.xml">
<style>
<!--table
	{mso-displayed-decimal-separator:"\.";
	mso-displayed-thousand-separator:"\,";}
@page
	{margin:.75in .7in .75in .7in;
	mso-header-margin:.3in;
	mso-footer-margin:.3in;}
tr
	{mso-height-source:auto;}
col
	{mso-width-source:auto;}
br
	{mso-data-placement:same-cell;}
td
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:black;
	font-size:11.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:"Aptos Narrow", sans-serif;
	mso-font-charset:0;
	mso-number-format:General;
	text-align:general;
	vertical-align:bottom;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;}
.xl63
	{border:.5pt solid windowtext;}
.xl64
	{text-align:center;}
.xl65
	{text-align:center;
	border:.5pt solid windowtext;}
-->
</style>
</head>

<body link="#467886" vlink="#96607D">


Name of Test | dnn_neon | dnn_sve | dnn_sve   vs dnn_neon(x-factor)
-- | -- | -- | --
lstm::Layer_LSTM::BATCH=1,   IN=64, HIDDEN=192, TS=100 | 2.878 | 2.326 | 1.24
lstm::Layer_LSTM::BATCH=1,   IN=192, HIDDEN=192, TS=100 | 4.162 | 3.08 | 1.35
lstm::Layer_LSTM::BATCH=1,   IN=192, HIDDEN=512, TS=100 | 18.627 | 16.152 | 1.15
lstm::Layer_LSTM::BATCH=1,   IN=1024, HIDDEN=192, TS=100 | 10.98 | 7.976 | 1.38
lstm::Layer_LSTM::BATCH=64,   IN=64, HIDDEN=192, TS=2 | 4.41 | 3.459 | 1.27
lstm::Layer_LSTM::BATCH=64,   IN=192, HIDDEN=192, TS=2 | 6.567 | 4.807 | 1.37
lstm::Layer_LSTM::BATCH=64,   IN=192, HIDDEN=512, TS=2 | 28.471 | 22.909 | 1.24
lstm::Layer_LSTM::BATCH=64,   IN=1024, HIDDEN=192, TS=2 | 15.491 | 12.537 | 1.24
lstm::Layer_LSTM::BATCH=128,   IN=64, HIDDEN=192, TS=2 | 8.848 | 6.821 | 1.3
lstm::Layer_LSTM::BATCH=128,   IN=192, HIDDEN=192, TS=2 | 12.969 | 9.522 | 1.36
lstm::Layer_LSTM::BATCH=128,   IN=192, HIDDEN=512, TS=2 | 55.52 | 45.746 | 1.21
lstm::Layer_LSTM::BATCH=128,   IN=1024, HIDDEN=192, TS=2 | 31.226 | 26.132 | 1.19

</body>

</html>

<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">

<head>

<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 15">
<link id=Main-File rel=Main-File
href="file:///C:/Users/jaiswaln/AppData/Local/Temp/msohtmlclip1/01/clip.htm">
<link rel=File-List
href="file:///C:/Users/jaiswaln/AppData/Local/Temp/msohtmlclip1/01/clip_filelist.xml">
<style>
<!--table
	{mso-displayed-decimal-separator:"\.";
	mso-displayed-thousand-separator:"\,";}
@page
	{margin:.75in .7in .75in .7in;
	mso-header-margin:.3in;
	mso-footer-margin:.3in;}
tr
	{mso-height-source:auto;}
col
	{mso-width-source:auto;}
br
	{mso-data-placement:same-cell;}
td
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:black;
	font-size:11.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:"Aptos Narrow", sans-serif;
	mso-font-charset:0;
	mso-number-format:General;
	text-align:general;
	vertical-align:bottom;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;}
.xl65
	{border:.5pt solid windowtext;}
.xl66
	{text-align:center;}
.xl67
	{text-align:center;
	border:.5pt solid windowtext;}
-->
</style>
</head>

<body link="#467886" vlink="#96607D">


Name of Test | dnn_neon | dnn_sve | dnn_sve   vs dnn_neon(x-factor)
-- | -- | -- | --
fc::Layer_FullyConnected::([5,   16, 512, 128], 256, false, OCV/CPU) | 5.086 | 4.483 | 1.13
fc::Layer_FullyConnected::([5,   16, 512, 128], 256, true, OCV/CPU) | 8.512 | 8.347 | 1.02
fc::Layer_FullyConnected::([5,   16, 512, 128], 512, false, OCV/CPU) | 9.467 | 8.965 | 1.06
fc::Layer_FullyConnected::([5,   16, 512, 128], 512, true, OCV/CPU) | 14.855 | 13.527 | 1.1
fc::Layer_FullyConnected::([5,   16, 512, 128], 1024, false, OCV/CPU) | 18.821 | 18.023 | 1.04
fc::Layer_FullyConnected::([5,   16, 512, 128], 1024, true, OCV/CPU) | 27.558 | 24.966 | 1.1
fc::Layer_FullyConnected::([5,   512, 384, 0], 256, false, OCV/CPU) | 0.924 | 0.804 | 1.15
fc::Layer_FullyConnected::([5,   512, 384, 0], 256, true, OCV/CPU) | 1.259 | 1.126 | 1.12
fc::Layer_FullyConnected::([5,   512, 384, 0], 512, false, OCV/CPU) | 1.957 | 1.655 | 1.18
fc::Layer_FullyConnected::([5,   512, 384, 0], 512, true, OCV/CPU) | 2.831 | 2.775 | 1.02
fc::Layer_FullyConnected::([5,   512, 384, 0], 1024, false, OCV/CPU) | 5.92 | 6.379 | 0.93
fc::Layer_FullyConnected::([5,   512, 384, 0], 1024, true, OCV/CPU) | 8.924 | 8.993 | 0.99

</body>

</html>
2025-12-03 10:42:28 +03:00
Alexander Smorkalov
e3fe5a5681 Merge pull request #28112 from asmorkalov:as/jpeg_turbo_3.1.2
Merge pull request #28112 from asmorkalov:as/jpeg_turbo_3.1.2

### Pull Request Readiness Checklist

Previous update: https://github.com/opencv/opencv/pull/27031

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-03 10:26:44 +03:00
Alessandro de Oliveira Faria (A.K.A.CABELO)
9c3d3dbee7 Merge pull request #28082 from cabelo:4.x
Analog Gauge Reader - cabelo@opensuse.org #28082

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

I humbly offer this example so that all developers can understand that many problems can be solved without VLM models.

<img width="269" height="267" alt="image" src="https://github.com/user-attachments/assets/d31f1557-7648-4e9c-8933-dcadb1f326aa" />
<img width="269" height="267" alt="image" src="https://github.com/user-attachments/assets/4039417c-b5c9-4228-ac7b-5336aeb88325" />
<img width="840" height="288" alt="image" src="https://github.com/user-attachments/assets/53f8ddf9-63cd-43b1-bff0-2e9e39d14153" />
2025-12-03 10:05:50 +03:00
Alexander Smorkalov
5a4f23f9d6 Merge pull request #28088 from Ghazi-raad:fix/drawcontours-line-type-swap-26413
Fix LINE_4/LINE_8 swap in drawContours (issue #26413)
2025-12-03 09:34:01 +03:00
sinkboy-chen
4c7fd071f0 Merge pull request #28118 from sinkboy-chen:bugfix/cuda-race-condition
stitching: pass warp params by value to avoid CUDA constant races #28118

### 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 the Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on 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 are accuracy tests, performance tests, and test data in the opencv_extra repository, if applicable.  
      The patch to opencv_extra uses the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake configuration.

Fixes #26870.

In `modules/stitching/src/cuda/build_warp_maps.cu`, the original implementation copied parameters into global GPU constant symbols:

```cpp
cudaSafeCall(cudaMemcpyToSymbol(build_warp_maps::ck_rinv, k_rinv, 9 * sizeof(float)));
cudaSafeCall(cudaMemcpyToSymbol(build_warp_maps::cr_kinv, r_kinv, 9 * sizeof(float)));
cudaSafeCall(cudaMemcpyToSymbol(build_warp_maps::cscale, &scale, sizeof(float)));
```

As discussed in the issue, this can cause race conditions when multiple warps are built concurrently. This patch removes the use of these global constant symbols and instead passes the required data as kernel parameters (a total of 11 floats encapsulated in `WarpParams`).

One potential concern is increased register pressure due to additional kernel arguments. However, based on experiments using the test case from issue #26870, there is no significant performance regression; in fact, a small speed‑up was observed.

Testing was performed on an NVIDIA GeForce RTX 4090 (single GPU).

Note: ./bin/opencv_perf_stitching did not run successfully on my system even with an unmodified git checkout, so performance was evaluated using the test case from issue #26870 instead.
2025-12-03 08:51:59 +03:00
Alexander Smorkalov
2c8cfdebde Added RISC-V RVV diagnostics for PNG. 2025-12-02 10:40:01 +03:00
Galina Bykova
fc7e70ef4a fix bug in approxPolyDP: calculate distance to a segment, not to a line 2025-12-01 21:22:11 +03:30
Alexander Smorkalov
54d066b89c Force 3rdparty build for CI test. 2025-12-01 17:14:08 +03:00
Alexander Smorkalov
e47916120f Updated libpng to v1.6.51 and added RISC-V optimimizations. 2025-12-01 13:47:27 +03:00
Alexander Smorkalov
a08565253e Merge pull request #28102 from satyam102006:fix-issue-28101
highgui: fix memory leak in CvWindow Qt backend
2025-12-01 10:50:15 +03:00
Alexander Smorkalov
6bc22ad5c3 Merge pull request #28091 from ParalYAO:fix/brisk/descriptor-calculation-pointer-bug
fix(features2d): Correct pointer arithmetic in BRISK corner traversal
2025-12-01 10:34:12 +03:00
satyam yadav
fbd550438f Merge pull request #28073 from satyam102006:issue-OpenCV-to-MSMF-
catch _com_error exceptions to suppress debugger flooding #28073

Resolves: #27643

This PR fixes an issue where the Microsoft Media Foundation (MSMF) backend triggers repeated C++ exceptions (_com_error) during video capture. While these exceptions are often non-fatal "first-chance" exceptions, they cause the Visual Studio debugger to break execution repeatedly, making debugging difficulty and flooding the output window.

Changes
cap_msmf.cpp: Added try-catch blocks around critical COM interaction paths.

Updated SourceReaderCB::OnReadSample (Async callback) to catch _com_error.

Updated CvCapture_MSMF::grabFrame (Synchronous grab) to catch _com_error.

Added CV_LOG_WARNING to log the error message from the caught exception, ensuring that actual errors are still visible in the logs without crashing the application or halting the debugger.

Impact
Users debugging OpenCV applications on Windows with Visual Studio will no longer be interrupted by internal MSMF exceptions when using the default backend.

The application flow remains uninterrupted even if MSMF encounters transient internal errors.
2025-12-01 09:07:08 +03:00
satyam yadav
be607ce6c8 memory leak 2025-11-30 17:57:21 +05:30
Alexander Smorkalov
1c712fe2ff Merge pull request #28093 from AKash-A007:fix-pytest-cov-warnings-27867
python: fix pytest-cov false warnings by compiling config scripts with full path (#27867)
2025-11-28 13:21:35 +03:00
Ghazi-raad
47a6419290 Merge pull request #28086 from Ghazi-raad:fix/aravis-default-pixel-format-26523
fix: set default pixel format for Aravis cameras when unsupported format #28086

Fixes #26523

This PR fixes an issue where Aravis VideoCapture returns empty frames when the camera's pixel format is not explicitly set via CAP_PROP_FOURCC.

Problem:

The Aravis backend's retrieveFrame() function only processes four specific pixel formats:
- ARV_PIXEL_FORMAT_MONO_8
- ARV_PIXEL_FORMAT_BAYER_GR_8
- ARV_PIXEL_FORMAT_MONO_12
- ARV_PIXEL_FORMAT_MONO_16

If the camera has a different pixel format configured (or the camera's default format is unsupported), retrieveFrame() returns false on line 333 and all frames appear empty. This happens even though:
- The camera opens successfully (isOpened() returns true)
- The camera is capturing data
- The user has set up autotrigger and auto-exposure correctly

Root Cause:

In open() at line 271, the code retrieves the camera's current pixel format with arv_camera_get_pixel_format(). But if this format doesn't match one of the four supported formats, there's no fallback, causing all subsequent frames to fail retrieval.

Solution:

Added a check after retrieving the camera's pixel format. If the format is not one of the four supported formats, the code now:
1. Sets pixelFormat to a sensible default (MONO_8)
2. Applies this format to the camera via arv_camera_set_pixel_format()

This ensures:
- Cameras work out-of-the-box without requiring explicit CAP_PROP_FOURCC setup
- Users can still override the format with CAP_PROP_FOURCC if needed
- Behavior matches user expectations from other camera backends (V4L2, MSMF, etc.)

The default of MONO_8 was chosen because it's the most universally supported format across USB3 Vision and GigE Vision cameras.

Changes:

modules/videoio/src/cap_aravis.cpp: Added pixel format validation and default setting (10 lines)

Testing:

With this fix:
- Cameras with unsupported default formats will automatically switch to MONO_8
- The sample code from the issue works without uncommenting the CAP_PROP_FOURCC line
- Users can still explicitly set their preferred format via CAP_PROP_FOURCC

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 (4.x)
- [x] There is a reference to the original bug report and related work (issue #26523)
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      N/A - This requires specialized USB3 Vision / GigE Vision hardware not available in CI
- [x] The feature is well documented and sample code can be built with the project CMake
      The fix maintains existing API behavior and makes the backend work as expected
2025-11-28 12:40:08 +03:00
Alexander Smorkalov
329f0fddaf Merge pull request #28092 from dkurt:flatbuffers_25.9.23
Update FlatBuffers source code to 25.9.23
2025-11-28 10:54:30 +03:00
Akash Arunkumar
13210cbb1d python: fix pytest-cov false warnings by using compile() with full file path in exec_file_wrapper 2025-11-27 17:31:05 +00:00
Dmitry Kurtaev
895be753ac Update FlatBuffers source code to 25.9.23 2025-11-27 18:31:10 +03:00
Ghazi-raad
2cf9c68da0 Merge pull request #28087 from Ghazi-raad:fix/tempfile-race-condition-19648
Fix tempfile race condition on Windows (issue #19648) #28087

Fix tempfile race condition on Windows

Addresses issue #19648

Problem
The cv::tempfile() function on Windows used GetTempFileNameA() followed by an immediate DeleteFileA() call. This created a race condition where multiple OpenCV processes running simultaneously could receive the same temporary filename, leading to name collisions.

Root Cause
The previous implementation:

Called GetTempFileNameA() to generate a temp filename
Immediately deleted the file to free the name
Returned just the filename string
Between steps 2 and 3, another process could call GetTempFileNameA() and receive the same filename, causing a collision.

Solution
Replaced GetTempFileNameA() with GUID-based filename generation using CoCreateGuid(), following the same approach already used in GetTempFileNameWinRT() and Microsoft's recommendations for scenarios requiring many temp files.

Changes
modules/core/src/system.cpp:

Removed GetTempFileNameA() and DeleteFileA() calls
Added CoCreateGuid() to generate unique GUID-based filenames
Format: "ocv{GUID}" where GUID ensures uniqueness across processes
Benefits

Eliminates race condition in multi-process scenarios
No file I/O overhead from creating and deleting placeholder files
Consistent with WinRT implementation approach
Follows Microsoft best practices
Testing
Standard OpenCV test suite. The change only affects Windows temp file naming and maintains the same String return type and usage pattern.
2025-11-27 17:57:42 +03:00
Haodi Yao
29746ab963 fix(features2d): Correct pointer arithmetic in BRISK corner traversal
The pointer offset to move from top-right to bottom-right was incorrect. This change corrects the pointer calculation to use the proper row stride, ensuring it lands on the correct pixel.
2025-11-27 16:34:26 +08:00
Alexander Smorkalov
641a7aa2a6 Merge pull request #28090 from asmorkalov:as/system_aravis
Unblock system-wide installation of Aravis SDK.
2025-11-27 10:18:21 +03:00
Ghazi-raad
71c759b7cd Merge pull request #28085 from Ghazi-raad:fix/multiband-blender-memory-leak-27333
Fixed multiband blender memory leak 27333 #28085

Fixes #27333

This PR fixes a memory leak in MultiBandBlender where memory from pyramid vectors was not being released when prepare() was called multiple times or when the blender object was reused.

Problem:

MultiBandBlender retains hundreds of MB to several GB of memory even after the blender pointer is released. The issue occurs because:

1. The resize() function on std::vector does not release memory when the new size is less than or equal to the current size
2. It only adjusts the size marker while retaining the capacity and existing data
3. When prepare() is called, the pyramid vectors are resized but old data remains allocated

Example from the bug report: Blending 14 images (1920x1080) retained ~200MB after blender.release(). With larger images, several GB could be retained.

Root Cause:

GPU path (lines 254-256): Correctly calls clear() before operations
Non-GPU path (lines 285-298): Missing clear() calls, causing resize() to retain old data

Solution:

Added .clear() calls before .resize() in the non-GPU path to match the GPU path behavior. This ensures:
- Memory from previous blend operations is released in prepare()
- Reusing a blender object doesn't accumulate memory
- Behavior is consistent between GPU and non-GPU code paths

Changes:

modules/stitching/src/blenders.cpp: Added 2 clear() calls (dst_pyr_laplace_.clear() and dst_band_weights_.clear()) before resize() in the non-GPU path

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 (4.x)
- [x] There is a reference to the original bug report and related work (issue #27333)
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      N/A - This is a memory management fix that doesn't affect algorithm behavior. Existing stitching tests verify correctness.
- [x] The feature is well documented and sample code can be built with the project CMake
      The fix maintains existing API behavior, no documentation changes needed
2025-11-27 09:57:21 +03:00
Alexander Smorkalov
1c2cdb1818 Unblock system-wide installation of Aravis SDK. 2025-11-27 09:38:43 +03:00
Ghazi-raad
a27a13921b Fix LINE_4/LINE_8 swap in drawContours (issue #26413)
Changed condition to correctly route LINE_8 to Line() instead of Line2().

The condition 'line_type == 1 || line_type == 4' was causing LINE_8 (value 8)
to be processed by Line2() which implements 4-connectivity, and LINE_4 (value 4)
to be processed by Line() which was implementing 8-connectivity behavior. This
resulted in swapped line connectivity.

Changed to 'line_type == 1 || line_type == 8' so LINE_8 goes to Line() with
8-connectivity and LINE_4 goes to Line2() with 4-connectivity, matching the
documented behavior where LINE_4 should produce 4-connected lines and LINE_8
should produce 8-connected lines.

Fixes #26413
2025-11-26 21:41:28 +00:00
Alexander Smorkalov
4da9a518ef Merge pull request #28076 from asmorkalov:as/ubuntu_arm_update
Update ARM config label to Ubuntu 24.04.
2025-11-26 17:05:50 +03:00
Alexander Smorkalov
638f372c2e Update ARM config label to Ubuntu 24.04. 2025-11-26 16:47:13 +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
Dmitry Kurtaev
621ad482d6 Merge pull request #28051 from dkurt:minAreaRect_angle
Correct minAreaRect angle to be in range [-90, 0) #28051

### Pull Request Readiness Checklist

Box angle range over all imgproc tests is in interval `[-90, -0.0581199]`

resolves https://github.com/opencv/opencv/issues/27667
resolves https://github.com/opencv/opencv/issues/19472
resolves https://github.com/opencv/opencv/issues/24436

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-25 15:56:59 +03:00
Alexander Smorkalov
52a5b6c3df Merge pull request #28065 from AKash-A007:fix-avif-matrixcoeff-unspecified
imgcodecs: avif: use UNSPECIFIED matrixCoefficients instead of IDENTITY for YUV400
2025-11-25 09:19:41 +03:00
Alexander Smorkalov
09a92e811b Merge pull request #28072 from Kumataro:fix28071
imgcodecs: avif: support to encode with metadata for 1ch Mat
2025-11-25 09:19:00 +03:00
Kumataro
3c3596c6ef Merge pull request #28063 from Kumataro:fix28062
imgcodecs: Fix IMWRITE_AVIF_DEPTH typo and update AVIF details on imwrite() #28063

Close https://github.com/opencv/opencv/issues/28062

- Corrected the documentation for `IMWRITE_AVIF_DEPTH`.
- Added descriptions for the new AVIF encoder parameters in `imwrite()` documentation.

### 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-11-24 10:46:12 +03:00
Alexander Smorkalov
d54fb714eb Merge pull request #28067 from dimitre:4.x
typo COMPENSACTION -> COMPENSATION
2025-11-24 10:43:59 +03:00
Alexander Smorkalov
71b476b256 Merge pull request #28059 from cabelo:realsense
Just original author.
2025-11-24 09:31:28 +03:00
Kumataro
6617a7ca34 imgcodecs: avif: support metadata for 1ch Mat 2025-11-24 08:19:25 +09:00