opencv/modules
s-trinh f5014c179f
Merge pull request #27736 from s-trinh:use_USAC_P3P_in_solvePnP
Update Gao P3P with Ding P3P #27736

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

---

The current Gao P3P implementation does not cover all the degenerate cases, **see last line** in: 6d889ee74c/modules/calib3d/src/p3p.cpp (L211-L221)

See also:
- https://github.com/opencv/opencv/issues/4854

---

<details>

<summary>OBSOLETE</summary>

To fix this, the USAC P3P from OpenCV 5 is used instead: 7e6da007cd/modules/3d/src/usac/pnp_solver.cpp (L282)

---

## Some results

### Old P3P vs new

In the following video, I have tried to highlight the viewpoints which cause issues:

https://github.com/user-attachments/assets/97bec6a6-4043-4509-b50e-a9856d6423bd

| | Old P3P    | New P3P |
| -------- | ------- | ------- |
| Mean (ms)  | 0.045701 | 0.024816 |
| Median (ms) | 0.025146 | 0.023193 |
| Std (ms)    | 0.028953    | 0.006124 |

### New P3P vs AP3P

https://github.com/user-attachments/assets/eaeb21dc-3ffd-4b6c-9902-4352f824aa45

The AP3 method is superior both in term of accuracy and computation time:

| | New P3P    | AP3P |
| -------- | ------- | ------- |
| Mean (ms)  | 0.043750 | 0.023442 |
| Median (ms) | 0.023193 | 0.021484 |
| Std (ms)    | 0.039920 | 0.005265 |

### New P3P vs AP3P (range test)

https://github.com/user-attachments/assets/572e7b7a-2966-4bed-8e0c-b93d863987dc

The implemented P3P method does not work well when the tag is small, at long range.

| | New P3P    | AP3P |
| -------- | ------- | ------- |
| Mean (ms)  | 0.031351 | 0.025189 |
| Median (ms) | 0.022217 | 0.020996 |
| Std (ms)    | 0.024920 | 0.009633 |

---

- I have tried to simplify the P3P code, hope I did not break the implementation code
- calculations are performed using double type for simplicity.
- code such as the following are redundant and no more needed and should be replaced by `cv::Rodrigues`:

6d889ee74c/modules/calib3d/src/usac/pnp_solver.cpp (L395)

</details>
2025-10-16 15:21:15 +03:00
..
calib3d Merge pull request #27736 from s-trinh:use_USAC_P3P_in_solvePnP 2025-10-16 15:21:15 +03:00
core Merge pull request #27890 from Kumataro:fix26899 2025-10-16 12:03:02 +03:00
dnn Merge pull request #27785 from pratham-mcw:dnn-lstm-neon 2025-10-03 10:50:50 +03:00
features2d Merge pull request #27642 from pratham-mcw:perf_arm64_fast_loop_unroll 2025-09-19 16:49:21 +03:00
flann Merge pull request #27730 from Kumataro:fix27729 2025-09-08 10:35:01 +03:00
gapi More warning fixes iG-API on Windows. 2025-10-13 16:50:55 +03:00
highgui Fixed linking for HighGUI against Qt 6.9 and newer 2025-10-15 21:49:04 +05:30
imgcodecs Fixed warnings produced by x86 builds on Windows. 2025-10-09 11:54:10 +03:00
imgproc Add corner cases tests for minEnclosingCircle 2025-10-15 22:27:27 +03:00
java Add Java wrapper support for List<List<MatShape>> 2025-08-25 02:09:19 +09:00
js Added option to wrap opencv_contrib into JS too. 2025-09-25 17:25:04 +03:00
ml Remove more C code 2025-09-25 13:31:30 +02:00
objc feat: add conditional inclusion support to header parser 2025-05-19 10:11:52 +03:00
objdetect Merge pull request #27877 from MaximSmolskiy:fix_QRCodeDetector_detectAndDecode_crash 2025-10-08 08:50:54 +03:00
photo fix: Refactor tuple creation in NLM CUDA kernel for fixing nvcc build error 2025-10-11 14:22:27 +08:00
python Restored PYTHON_DEBUG_LIBRARIES in python bindings. 2025-10-02 09:00:22 +03:00
stitching Renamed templated BlocksCompensator::feed method to exclude claches with base class pure virtual method. 2025-09-08 14:52:58 +03:00
ts Merge pull request #27416 from Kumataro:fix27413 2025-06-12 15:32:28 +03:00
video Merge pull request #27810 from D00E:known-foreground-mask 2025-10-14 09:56:06 +03:00
videoio Merge pull request #27864 from peters:patch-2 2025-10-04 13:24:28 +03:00
world cmake: use /INCREMENTAL:NO with MSVS 2015 2023-12-07 19:46:27 +00:00