1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-21 19:33:03 +04:00

946 Commits

Author SHA1 Message Date
Uwez Khan b5fe8dfef3 bound marker string length in aruco readDictionary 2026-07-16 19:44:15 +05:30
Jonas Perolini 37f3c7539b Merge pull request #29252 from JonasPerolini:pr-aruco-bit-threshold-in-refine
Use validBitIdThreshold for Aruco refineDetectedMarkers #29252

The goal of this PR is to solve the issue raised by @vrabaud in https://github.com/opencv/opencv/pull/28289 (comment: https://github.com/opencv/opencv/pull/28289#discussion_r3355812646). 

**Issue:** 

`refineDetectedMarkers()` converted the extracted cell ratios with `convertTo(CV_8UC1)` (an implicit 0.5 threshold) before computing the code distance, ignoring `detectorParams.validBitIdThreshold`. 

**Solution:** 

Make the refine path consistent with the main detection path `Dictionary::identify`.

**Changes:**

- Add a `Dictionary::getDistanceToId()` overload that takes the float cell pixel ratio matrix and `validBitIdThreshold` (similar to how it's done for the `identify()` overload.
- Move the per cell distance computation into a private `getDistanceToIdImpl` helper used by both `identify()` and the new overload of `getDistanceToId()` to avoid repetitions.
- `refineDetectedMarkers()` now calls the new overload.

**Tests:**

- `CV_ArucoRefine.validBitIdThreshold`: a marker with one degraded cell is recovered at threshold 0.7 but not at 0.49.
- `CV_ArucoDictionary.getDistanceToIdCellPixelRatio`: unit-tests both `getDistanceToId` overloads.

All passed
2026-06-29 13:37:43 +03:00
uwezkhan 15b5d28325 Merge pull request #29378 from uwezkhan:qr-alpha-map-bound
bound alphanumeric values in qr decodeAlpha before map lookup #29378

decodeAlpha in the no-quirc QR backend reads alphanumeric symbols from the post-ECC bitstream and indexes a fixed 45-entry map[] with the raw values. The 11-bit pair from next(11) goes up to 2047, so tuple/45 lands on 45 once the pair passes 2024, and the 6-bit trailing char from next(6) goes up to 63, so map[value] runs out to map[63]. A QR whose data codewords carry an alphanumeric segment with one of those out-of-range values reads past the static array, and the stray byte lands in the string returned by detectAndDecode. WITH_QUIRC defaults off, so this is the decoder a stock build runs.

Before, the only guard was on the encode side, which never emits those values, so the decoder trusted the stream and indexed map[] directly. New version checks value range and return empty string for malformed qr codes.

### 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
- [ ] 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
- [ ] The feature is well documented and sample code can be built with the project CMake
2026-06-28 14:18:20 +03:00
Jonas Perolini 853ee9b961 Merge pull request #29329 from JonasPerolini:get-border-errors-once
Optimization ArUco: get border errors in one pass for both normal and inverted markers #29329

This PR is a follow up to optimization in https://github.com/opencv/opencv/pull/29267.

## Context:

When detecting inverted markers, we call `_getBorderErrors` twice:
- `int borderErrors = _getBorderErrors(cellPixelRatio, ...);`
- `Mat invCellPixelRatio = 1.f - cellPixelRatio;`
- `int invBError = _getBorderErrors(invCellPixelRatio, ...);`

meaning:

1. Scan border cells once.
2. Allocate a new Mat.
3. Invert the entire `cellPixelRatio` matrix, not just the border.
4. Scan border cells again on the inverted matrix.
5. If inverted marker is better, copy the full inverted matrix back

## Solution

only call `_getBorderErrors` once and compute both 
- borderErrors: `cellPixelRatio > validBitIdThreshold`
- invBorderErrors: `1 - cellPixelRatio > validBitIdThreshold`

This saves: 
1. full invert into temporary Mat: (`Mat invCellPixelRatio = 1.f - cellPixelRatio;`)
2. scan temporary border: the second `_getBorderErrors`
3. copy temporary Mat back into `cellPixelRatio`: `invCellPixelRatio.copyTo(cellPixelRatio);`

Note that the solution does not implement: 

```
 if(params.detectInvertedMarker) {
    _getBorderErrorsBoth(...);
} else {
    borderErrors = _getBorderErrors(...);
}
```

because the extra cost to computing invBorderErrors: `if(1.f - ratio > validBitIdThreshold) invBorderErrors++;` is negligible. this also avoids having to maintain two functions: `_getBorderErrorsBoth` and `_getBorderErrors`

## Tests:

No visible results when testing the full marker detection pipeline because this step is not expensive. There is a roughly 8% noise when re-running the marker detections making it hard to spot small speed diffs. 

When testing only this specific step with a float matrix of size: `(markerSize + 2*border)^2` on a AMD Ryzen 7 (8 cores / 16 threads):
 
-  The new code is 30-45× faster at this stage depending on the marker size and whether the candidate was actually an inverted one, saving ~530-580 ns per candidate, mainly because we removed `Mat invCellPixelRatio = 1.f - cellPixelRatio`
- The new code is equivalent when detecting non-inverted markers +/- 3 ns

---

### 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-06-18 09:40:20 +03:00
Alexander Smorkalov cfb3a8bbb7 Fixed new objdetect warnings on Windows. 2026-06-15 12:32:11 +03:00
Vincent Rabaud fa55ed2837 Merge pull request #29267 from vrabaud:aruco
Fix speed regression in Aruco identify #29267

### 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-06-11 20:54:39 +03:00
s-trinh 0abd5c86f7 Merge pull request #28824 from s-trinh:update_ArUco_doc
Update ArUco doc #28824

See https://github.com/opencv/opencv/pull/28823

Update of the ArUco doc but targeted for OpenCV 4.

### 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
2026-05-20 15:05:51 +03:00
Rafael Muñoz Salinas 8c8b266b74 Merge pull request #29034 from rmsalinas:fix-arucodictionary
objdetect(aruco): fix maxCorrectionBits in predefined dictionaries #29034

This PR fixes the bugs in the creation of some dictionaries and standarizes its construction.

## Bugs
1. **DICT_ARUCO_MIP_36h12_DATA** was incorrectly assigned `maxCorrectionBits=12`, which is the intermarker distance. This was causing a high rate of false positives during detection, which is a significant problem.
2. **APRILTAG** dictionaries were incorrectly created with `maxCorrectionBits=0`, making it impossible to do error correction.

## Solution
Given a intermarker distance X, the correct `maxCorrectionBits = X/2 - 1`. Thus, standardize the construction of Dictionaries as such.
2026-05-19 09:18:29 +03:00
Kumataro 28b1f54468 core,objdetects,dnn,features2d: fix build warnings with GCC 16 2026-05-02 10:41:24 +09:00
Jeevan Mohan Pawar 273e52ce8d Merge pull request #28818 from jeevan6996:fix-charuco-detectdiamonds-clear-stale-output
objdetect: clear stale outputs in CharucoDetector::detectDiamonds #28818

## Summary
- clear `diamondCorners`/`diamondIds` outputs at the beginning of `CharucoDetector::detectDiamonds`
- prevent stale detections from previous calls when the current call has fewer than 4 markers or finds no diamonds
- add a regression test that pre-fills outputs, calls `detectDiamonds` with 3 markers, and verifies outputs are empty

Fixes #28783.

## Testing
- built `opencv_test_objdetect` locally
- ran `opencv_test_objdetect --gtest_filter=Charuco.detectDiamondsClearsOutputsWithLessThanFourMarkers`
- result: PASS
2026-04-22 15:42:37 +03:00
Vincent Rabaud ae6198e000 Rewrite getBitsFromByteList to avoid harmless buffer overflow
At the end, currentByte = byteList.ptr()[base + currentByteIdx];
could be out of bound though never used.
2026-04-15 16:14:25 +02:00
Jonas Perolini 5e91b461bc Merge pull request #28289 from JonasPerolini:pr-aruco-identification
Identify ArUco markers based on threshold to reduce false positives #28289

**Goal:** parametrize the current marker identification process (pixel-based majority count) to reduce the number of false positives while maintaining high recall. Useful in high risk scenarios in which false positives are not acceptable. 

**Context:** This PR builds on top of https://github.com/opencv/opencv/pull/23190 in which we've introduced a pixel-based confidence in the marker detection.

**Solution:** Include a new parameter: `validBitIdThreshold` used to identify markers based on the pixel count of each cell. Set the parameter default either to 50% which is equivalent to the current majority count implementation or to 49% which already singnificantly reduces the number of false positives (see details below). 

**Test coverage:** 
- Unit tests: `CV_ArucoDetectionThreshold`, `CV_InvertedArucoDetectionThreshold`
- The impact of `validBitIdThreshold` on false positives was also tested using the benchmark dataset: `MIRFLICKR-25k` https://www.kaggle.com/datasets/skfrost19/mirflickr25k which contains random images without any markers. Every marker detection is a false positive. 

Example of images in the dataset:

![im2048](https://github.com/user-attachments/assets/3e38796b-67ce-44be-a91d-2fd268414515)

![im17627](https://github.com/user-attachments/assets/37253b9f-829d-4bac-b9fc-c844d16f546e)

**Results:** A threshold of 49% already allows to significantly reduce the number of false positives for the dict `DICT_4X4_1000`: 
- `5942` false positives for `validBitIdThreshold = 0.5`
- `629` false positives for `validBitIdThreshold = 0.49` and `0.46` 
   - number of false positives divided by `9.5` when compared to `validBitIdThreshold = 0.5`
- `139` false positives for `validBitIdThreshold = 0.43` and `0.4` 
   - number of false positives divided by `42` when compared to `validBitIdThreshold = 0.5`

Dicts with a higher number of cells are not as impacted since it's much harder to obtain false positives. However, the less cells in a marker the further away it can be reliably detected, so the dict `DICT_4X4_1000` is commonly used.

<img width="1280" height="800" alt="false_positive_image_rate" src="https://github.com/user-attachments/assets/1a0ee16a-221d-443e-835b-022ed6dea6b0" />

In the image attached, the values of `validBitIdThreshold` tested are:  `0.10f, 0.20f, 0.30f, 0.40f, 0.43f, 0.46f, 0.49f, 0.50f, 0.53f, 0.56f, 0.60f, 0.70f, 0.80f, 0.90f`

Summary of the results: [summary.csv](https://github.com/user-attachments/files/24315662/summary.csv)

Note that we can also analyse the number of false positives per marker `id`. For example, here's the histogram for the dict `DICT_4X4_1000`. (The CSV attached contains all the results)

<img width="1440" height="640" alt="false_positive_ids_DICT_4X4_1000_thr0 50" src="https://github.com/user-attachments/assets/af4f3ff8-9b8f-4682-9d51-a090c2610d8c" />

For example, the marker id 17 is detected 252 times with  `validBitIdThreshold = 0.5` and only 34 times with `validBitIdThreshold = 0.49`. Looking at marker 17 (see below), we understand that this simple pattern randomly occurs in images.

<img width="447" height="441" alt="Marker17" src="https://github.com/user-attachments/assets/f5d09227-b39b-4598-94f9-b529f8300703" />

Results for every dict and every `validBitIdThreshold` [per_id.csv](https://github.com/user-attachments/files/24315667/per_id.csv)

**Missing coverage:** there is no labeled dataset with images containing markers to analyse the impact of on the recall  (i.e. look at the true positive rate). For my specific use case (drones) any threshold above `0.4` allows to maintain a high recall in all conditions.

### 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
- [ ] 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-03-04 08:44:28 +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
Alexander Smorkalov 7b3977727c Merge pull request #28460 from falloficarus22:qrcode-remove-duplicated-compute
Optimize duplicated computation in QR code error correction
2026-02-10 09:17:15 +03:00
Siddharth Panditrao 0c613de006 Merge pull request #28380 from WalkingDevFlag:fix/charuco-detector-offset-25539
Fix ~0.5px systematic offset in CharucoDetector subpixel refinement #28380

Resolves #25539

### Problem

`CharucoDetector::detectBoard` produces Charuco corner coordinates that are consistently offset by approximately **+0.5 pixels** compared to `findChessboardCorners + cornerSubPix`.

This offset is systematic (mean ≈ −0.5 px when comparing legacy − Charuco) and reproducible across images. Visual inspection also shows that the legacy chessboard detector aligns better with the actual corner locations.

### Root cause

In `charuco_detector.cpp`, the points passed to `cornerSubPix` are manually shifted by `-Point2f(0.5f, 0.5f)` before refinement and then shifted back by `+Point2f(0.5f, 0.5f)` after refinement.

However, `cornerSubPix` refines corners in **absolute image coordinates** and converges to the true saddle point based on image gradients. Shifting the initial guess does not affect the converged result as long as the true corner lies within the refinement window.

The additional `+0.5` shift applied after refinement therefore introduces a constant bias, resulting in:

```

P_out = P_true + 0.5

```

### Solution

Remove the manual `±0.5` coordinate shifts around the `cornerSubPix` call and let the refined result be returned directly.

### Test updates

Updated expected corner values in the following tests:

- `testBoardSubpixelCoords`
- `testSeveralBoardsWithCustomIds`

The previous expected values (e.g. `200`, `250`, `300`) were only correct due to the +0.5px bias introduced by the bug.

`generateImage` creates checkerboard squares of exactly **50 pixels**, which places true corner locations on **pixel boundaries** rather than pixel centers. As a result, the correct subpixel coordinates are:

```

199.5, 249.5, 299.5

```

instead of the previously expected integer values.

After updating the expected values, all **30 Charuco-related tests pass** with the fix applied.

### Verification

I verified the fix using a Python reproducer that compares `CharucoDetector` output against `findChessboardCorners + cornerSubPix`:

- **Before fix:** mean error ≈ −0.501 px  
![before_fix_multilocus](https://github.com/user-attachments/assets/cc812956-c081-4f00-a7e2-78b7427b1235)
![before_fix_zoomed_small](https://github.com/user-attachments/assets/7e6887cb-b09d-47dc-9fcd-03a27b17f310)

- **After fix:** mean error ≈ −0.001 px
![after_fix_multilocus](https://github.com/user-attachments/assets/1c4f8dfa-d0ae-417c-881e-e2a9cbc4b9f1)
![after_fix_zoomed_small](https://github.com/user-attachments/assets/9c325995-fe0b-42f3-bdbb-6754f985e936)

After the change, the Charuco detector output aligns with the legacy chessboard detector both numerically and visually.

### Notes

This change only affects the post-refinement coordinate handling and does not alter detection logic, refinement parameters, or performance.

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-01-28 14:31:54 +03:00
Murat Raimbekov 774c7e01b3 Merge pull request #28301 from raimbekovm:fix-more-typos
docs: fix spelling errors in documentation and code #28301

- [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
- [ ] The feature is well documented and sample code can be built with the project CMake

### Description

Fixed multiple spelling errors across documentation, comments, and code:

- 'colummn' → 'column' (cublas.hpp, 3 occurrences)
- 'points_per_colum' → 'points_per_column' (calib3d.hpp, 3 occurrences)
- 'Asignee' → 'Assignee' (sift files, 2 occurrences)
- 'compability' → 'compatibility' (face.hpp, 2 occurrences)
- 'orignal' → 'original' (aruco_detector.cpp)
- 'refrence' → 'reference' (chessboard.cpp)
- 'indeces' → 'indices' (stitching.hpp)
- 'OutputPrecison' → 'OutputPrecision' (test)
- 'tranform' → 'transform' (slice_layer.cpp, 3 occurrences)

Total: 24 fixes across 14 files. Documentation and comment changes only, no functional impact.
2026-01-26 21:28:50 +03:00
Abhishek b93ea5412c Optimize duplicated computation in QR code error correction
Precompute X values in Forney algorithm to eliminate redundant gfPow calls.

Previously, gfPow(2, ...) was computed multiple times for the same error
location across different loop iterations, resulting in O(L²) redundant
Galois field arithmetic operations.

This change:
- Precomputes all X values once before the main loop
- Reduces complexity from O(L²) to O(L) for X value computations
- Removes the TODO comment at line 1642
- No functional changes, only performance improvement

The optimization is most beneficial when there are many error locations
in QR codes (larger L values).
2026-01-24 17:21:12 +00:00
Alexander Smorkalov 74addff3d0 Merge pull request #28303 from raimbekovm:fix-typos-batch4
docs: fix spelling errors in code and comments
2026-01-23 13:42:15 +03:00
Alexander Smorkalov 5258bc5de9 Merge pull request #28317 from raimbekovm:fix-typos-batch7
docs: fix typos in documentation and code comments
2026-01-23 11:29:02 +03:00
Alexander Smorkalov 40ab411032 Merge pull request #28285 from akretz:fix_issue_28241
Fixed stack-use-after-scope errors in charuco detector
2025-12-27 18:17:58 +03:00
raimbekovm c058072d62 docs: fix typos in documentation and code comments
Fixed 19 typos across 15 files:
- properies → properties
- posible → possible (2×)
- indeces → indices
- matrixs → matrices (2×)
- grater → greater
- whith → with
- ouput → output
- choosen → chosen (4×)
- constains → contains
- refrence → reference
- dont → don't (4×)
- cant → can't
2025-12-26 23:42:51 +06:00
raimbekovm be7e2c91c6 docs: fix spelling errors in code and comments
- Fixed 'suported' -> 'supported' in imgproc.hpp
- Fixed 'constane/constans' -> 'constant/constants' in onevpl utils
- Fixed 'pushconstance' -> 'pushconstant' in op_matmul.cpp
- Fixed 'bufer' -> 'buffer' in test_imgwarp.cpp
- Fixed 'Framebuffrer' -> 'Framebuffer' in window_framebuffer
- Fixed 'readComplexPropery' -> 'readComplexProperty' in cap_msmf.cpp
- Fixed 'behavoir' -> 'behavior' in test_exr.impl.hpp
- Fixed 'previos' -> 'previous' in qrcode_encoder.cpp
2025-12-25 15:34:48 +06:00
Alexander Smorkalov 5c1737e0dc Merge pull request #28297 from raimbekovm:fix-documentation-typos
docs: fix typos in documentation
2025-12-25 08:35:19 +03:00
raimbekovm 17a01d687c docs: fix spelling errors in documentation
- Fixed 'reinitalized' -> 'reinitialized' in background_segm.hpp
- Fixed 'dimentions/dimentional/dimentinal' -> 'dimensions/dimensional' in mat.hpp, imgproc.hpp, gmat.hpp, recurrent_layers.cpp
- Fixed 'tresholded' -> 'thresholded' in aruco_detector.cpp
2025-12-24 22:37:09 +06:00
raimbekovm 2fb95415dd Fix typos in documentation: 'algorighm' -> 'algorithm', 'necesary' -> 'necessary' 2025-12-24 22:11:28 +06:00
Alexander Smorkalov a1b682254e Warning fix on Windows. 2025-12-23 18:25:26 +03:00
Adrian Kretz 54fc9dce0b Guarantee temporary object lifetime extension 2025-12-23 15:54:37 +01:00
Alexander Smorkalov 4705320496 Merge pull request #28239 from AdwaithBatchu:optimize-stitching-allocations
optimize: replace push_back with emplace_back in core loops
2025-12-23 15:05:35 +03:00
Jonas Perolini 2bca09a191 Merge pull request #23190 from JonasPerolini:pr-output-marker-score
Include pixel-based confidence in ArUco marker detection #23190

The aim of this pull request is to compute a **pixel-based confidence** of the marker detection. The confidence [0;1] is defined as the percentage of correctly detected pixels, with 1 describing a pixel perfect detection. Currently it is possible to get the normalized Hamming distance between the detected marker and the dictionary ground truth [Dictionary::getDistanceToId()](https://github.com/opencv/opencv/blob/4.x/modules/objdetect/src/aruco/aruco_dictionary.cpp#L114) However, this distance is based on the extracted bits and we lose information in the [majority count step](https://github.com/opencv/opencv/blob/4.x/modules/objdetect/src/aruco/aruco_detector.cpp#L487). For example, even if each cell has 49% incorrect pixels, we still obtain a perfect Hamming distance.

**Implementation tests**: Generate 36 synthetic images containing 4 markers each (with different ids) so a total of 144 markers. Invert a given percentage of pixels in each cell of the marker to simulate uncertain detection. Assuming a perfect detection, define the ground truth uncertainty as the percentage of inverted pixels. The test is passed if `abs(computedConfidece - groundTruthConfidence) < 0.05` where `0.05` accounts for minor detection inaccuracies.

- Performed for both regular and inverted markers
- Included perspective-distorted markers
- Markers in all 4 possible rotations [0, 90, 180, 270]
- Different set of detection params:
    - `perspectiveRemovePixelPerCell`
    - `perspectiveRemoveIgnoredMarginPerCell`
    - `markerBorderBits`

![TestCases](https://github.com/user-attachments/assets/1113abd3-ff7a-45c8-8b4b-a9d2182eda82)


The code properly builds locally and `opencv_test_objdetect` and `opencv_test_core` passed. Please let me know if there are any further modifications needed. 

Thanks!


I've also pushed minor unrelated improvement (let me know if you want a separate PR) in the [bit extraction method](https://github.com/opencv/opencv/blob/4.x/modules/objdetect/src/aruco/aruco_detector.cpp#L435). `CV_Assert(perspectiveRemoveIgnoredMarginPerCell <=1)` should be `< 0.5`. Since there are margins on both sides of the cell, the margins must be smaller than half of the cell. When setting `perspectiveRemoveIgnoredMarginPerCell >= 0.5`, `opencv_test_objdetect` fails. Note: 0.499 is ok because `int()` will floor the result, thus `cellMarginPixels = int(cellMarginRate * cellSize)` will be smaller than `cellSize / 2`



### 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
- [ ] 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 PR is proposed to the proper branch
- [x] The feature is well documented and sample code can be built with the project CMake
2025-12-22 20:54:40 +03:00
AdwaithBatchu 5f0bd387db optimize: replace push_back with emplace_back in core loops
Replaces wasteful temporary object construction with in-place construction using emplace_back. Covers hot paths in objdetect, imgproc, and stitching modules.
2025-12-19 11:56:20 +05:30
Alexander Smorkalov 721bb7289d Merge pull request #28185 from asmorkalov:as/static_analysys_fix
Fixed issues identified by PVS Studio #28185

Partially fixes https://github.com/opencv/opencv/issues/28167
Paper: https://pvs-studio.com/en/blog/posts/cpp/1321/

Closed items: N2, N4, N5, N6, N7, N8, N10, N11, N13, N14.

To be continued...

### 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-18 11:32:19 +03:00
Dmitry Kurtaev 334b7146f5 Merge pull request #28157 from dkurt:normalize_vec_qrdetect
Remove floating point arithmetic from angle computation in QR codes #28157

### Pull Request Readiness Checklist

resolves https://github.com/opencv/opencv/issues/24646

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-12-10 10:20:08 +03:00
Maxim Smolskiy 75598e5377 Merge pull request #27877 from MaximSmolskiy:fix_QRCodeDetector_detectAndDecode_crash
Fix QRCodeDetector::detectAndDecode crash #27877

### Pull Request Readiness Checklist

Fix #27807 

The problem is that when we find closest points from hull, we can get same closest point for several different points

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
2025-10-08 08:50:54 +03:00
Muhammed Jaseem Pallikkal 5d54e90fa4 fix to prevent QR code decoding from throwing on degenerate source points 2025-09-29 00:51:14 +05:30
Marius Wachtler 6f9f8f49dd Speedup ChArUco by avoiding temporary copies
This speeds up processing a 132x128 board by more than 100 times.
This methods return std::vectors<> which means lots of copies and allocations.
2025-09-23 19:33:15 -05:00
Kumataro 61705ea280 objdetect: enable setEpsY() for QRDetectMulti 2025-09-16 21:06:28 +09:00
Kumataro 98a70539cc Merge pull request #27730 from Kumataro:fix27729
doc: fix doxygen warnings for imgcodecs, flann and objdetect #27730

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

### 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
2025-09-08 10:35:01 +03:00
kallaballa f81240f57b stay on fast-path by using INTER_LINEAR resize when ALGO_HINT_APPROX is used 2025-08-23 19:48:04 +02:00
Alexander Smorkalov d9e2b4c650 Fixed out-of-bound access issue in QR Encoder Java warappers. 2025-06-26 17:19:10 +03:00
Sergei Nikiforov a4a253ea2b Charuco detector: stop-gap measure for poor detection rate on tough perspective
add checkMarkers flag to charucoParameters to control board verification
(post-detection)
2025-06-19 12:16:09 +02:00
Dmitry Kurtaev 1c53fd3777 Merge pull request #24426 from dkurt:qrcode_eci_encoding
Consider QRCode ECI encoding #24426

### Pull Request Readiness Checklist

related: https://github.com/opencv/opencv/pull/24350#pullrequestreview-1661658421

1. Add `getEncoding` method to obtain ECI number
2. Add `detectAndDecodeBytes`, `decodeBytes`, `decodeBytesMulti`, `detectAndDecodeBytesMulti` methods in Python (return `bytes`) and Java (return `byte[]`)
3. Allow Python bytes to std::string conversion in general and add `encode(byte[] encoded_info, Mat qrcode)` in Java


    Python example with Kanji encoding:
    ```python
    img = cv.imread("test.png")
    detect = cv.QRCodeDetector()
    data, points, straight_qrcode = detect.detectAndDecodeBytes(img)
    print(data)
    print(detect.getEncoding(), cv.QRCodeEncoder_ECI_SHIFT_JIS)
    print(data.decode("shift-jis"))
    ```
    ```
    b'\x82\xb1\x82\xf1\x82\xc9\x82\xbf\x82\xcd\x90\xa2\x8aE'
    20 20
    こんにちは世界
    ```

    source: https://github.com/opencv/opencv/blob/ba4d6c859d21536f84e0328c16f4cc3e96bf3065/modules/objdetect/test/test_qrcode_encode.cpp#L332

    ![test](https://github.com/opencv/opencv/assets/25801568/0b5eefa8-918a-4c42-9acb-830f23c0ea9f)


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-06-19 10:12:15 +03:00
utibenkei 97f73ba0b5 Merge pull request #27228 from utibenkei:fix_java_enum_wrapper
Explicitly specify enum type scopes to improve Java wrapper generation #27228 

Changed DataLayout and ImagePaddingMode to dnn::DataLayout and dnn::ImagePaddingMode to explicitly specify their scopes. This allows gen_java.py to correctly register  disc_type, preventing constructors and methods using these enum types from being skipped during Java wrapper generation.

Similarly updated QRCodeEncoder::CorrectionLevel and QRCodeEncoder::EncodeMode with explicit scope declarations.

Also added a new Java test class `DnnBlobFromImageWithParamsTest` based on: https://github.com/opencv/opencv/blob/4.x/modules/dnn/test/test_misc.cpp#L133-L243

Related issues
#23753 

### 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
2025-04-21 20:51:38 +03:00
Adrian Kretz a08b1b6566 Merge pull request #27244 from akretz:fix_issue_27183
Fix QR code encoder with autoversion #27244

The autodetected version is not honored in the `QRCodeEncoderImpl::encode*` methods. This fixes #27183

### 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
2025-04-21 17:40:33 +03:00
Maxim Smolskiy b6f213a8c7 Merge pull request #27079 from MaximSmolskiy:add-test-for-ArucoDetector-detectMarkers
Add test for ArucoDetector::detectMarkers #27079

### Pull Request Readiness Checklist

Related to #26968 and #26922

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-03-17 11:24:46 +03:00
Maxim Smolskiy 46dbc57a86 Merge pull request #26968 from MaximSmolskiy:fix-Aruco-marker-incorrect-detection-near-image-edge
Fix Aruco marker incorrect detection near image edge #26968

### Pull Request Readiness Checklist

Fix #26922 

As I understood the algorithm, at the first stage we search for the contours of the marker several times (adaptive threshold with different windows sizes). Therefore, for the same marker, we get several contours (inner and outer with different sizes due to the different windows sizes). In the second stage, we group the contours for the same marker into one group, from which we take the largest contour as the best candidate (which should best match the border of the marker).

The problem is that using the `minDistanceToBorder` parameter, we discard contours at the first stage. Thus, we discard the best candidates most appropriate to the marker border, and inner contours may remain, representing a significantly smaller marker border (which we observe in the issue).

But if we use the `minDistanceToBorder` parameter to discard the best candidate of the group at the second stage, then there will be no such problems and we will completely discard markers located too close to the border of the image.

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-03-12 09:47:49 +03:00
Alexander Smorkalov 1f63b986a1 Merge pull request #26976 from MaximSmolskiy/refactor-ArucoDetector-ArucoDetectorImpl-filterTooCloseCandidates
Refactor ArucoDetector::ArucoDetectorImpl::filterTooCloseCandidates
2025-03-11 16:10:48 +03:00
Benjamin Knecht d80fd565b4 Attempt to fix Windows int type warning 2025-03-04 16:24:50 +01:00
Benjamin Knecht 1aa658fa75 Address more comments
Use map to manage unique marker size candidate trees.
Avoid code duplication.
Add a test to show double detection with overlapping dictionaries.
Generalize to marker sizes of not only predefined dictionaries.
2025-03-04 15:24:03 +01:00
Benjamin Knecht 3084f950cf Fix dictionary comparison in test 2025-02-27 10:52:27 +01:00
Benjamin Knecht d869b12e89 Fixing warnings in tests 2025-02-25 11:50:13 +01:00