opencv/modules/imgproc/src
Mironov Arseny b964943517
Merge pull request #25607 from Fest1veNapkin:imgproc_approx_bounding_poly
Add a new function that approximates the polygon bounding a convex hull with a certain number of sides #25607

merge PR with <https://github.com/opencv/opencv_extra/pull/1179>

This PR is based on the paper [View Frustum Optimization To Maximize Object’s Image Area](https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=1fbd43f3827fffeb76641a9c5ab5b625eb5a75ba).

# Problem
I needed to reduce the number of vertices of the convex hull so that the additional area was minimal, andall vertices of the original contour enter the new contour.

![image](https://github.com/Fest1veNapkin/opencv/assets/98156294/efac35f6-b8f0-46ec-91e4-60800432620c)

![image](https://github.com/Fest1veNapkin/opencv/assets/98156294/2292d9d7-1c10-49c9-8489-23221b4b28f7)

# Description
Initially in the contour of n vertices, at each stage we consider the intersection points of the lines formed by each adjacent edges. Each of these intersection points will form a triangle with vertices through which lines pass. Let's choose a triangle with the minimum area and merge the two vertices at the intersection point. We continue until there are more vertices than the specified number of sides of the approximated polygon.
![image](https://github.com/Fest1veNapkin/opencv/assets/98156294/b87b21c4-112e-450d-a776-2a120048ca30)

# Complexity:
Using a std::priority_queue or std::set  time complexity is **(O(n\*ln(n))**, memory **O(n)**,
n - number of vertices in convex hull.

count of sides - the number of points by which we must reduce.
![image](https://github.com/Fest1veNapkin/opencv/assets/98156294/31ad5562-a67d-4e3c-bdc2-29f8b52caf88)

## Comment
If epsilon_percentage more 0, algorithm can return more values than _side_.
Algorithm returns OutputArray. If OutputArray.type() equals 0, algorithm returns values with InputArray.type().
New test uses image which are not in opencv_extra, needs to be added.

### 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
- [ ] 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
2024-07-09 17:11:23 +03:00
..
opencl Merge pull request #24621 from chacha21:remap_relative 2024-02-28 17:20:33 +03:00
_geom.h Backport C-API cleanup (imgproc) from 5.x 2023-01-16 23:29:50 +03:00
accum.cpp Deprecated convertTypeStr and made new variant that also takes the buffer size 2023-04-26 09:48:15 -04:00
accum.dispatch.cpp Merge pull request #23109 from seanm:misc-warnings 2023-10-06 13:33:21 +03:00
accum.simd.hpp Merge pull request #24325 from hanliutong:rewrite 2023-10-05 17:57:25 +03:00
approx.cpp Merge pull request #25607 from Fest1veNapkin:imgproc_approx_bounding_poly 2024-07-09 17:11:23 +03:00
bilateral_filter.dispatch.cpp HALL interface for bilaterialFilter. 2024-04-11 09:02:45 +03:00
bilateral_filter.simd.hpp Clean up the Universal Intrinsic API. 2023-10-13 19:23:30 +08:00
blend.cpp Merge pull request #24058 from hanliutong:rewrite-imgporc 2023-09-14 20:37:46 +03:00
box_filter.dispatch.cpp Deprecated convertTypeStr and made new variant that also takes the buffer size 2023-04-26 09:48:15 -04:00
box_filter.simd.hpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
canny.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
ccl_bolelli_forest_firstline.inc.hpp Merge pull request #19631 from prittt:sota-ccl 2021-02-27 17:27:24 +00:00
ccl_bolelli_forest_lastline.inc.hpp Merge pull request #19631 from prittt:sota-ccl 2021-02-27 17:27:24 +00:00
ccl_bolelli_forest_singleline.inc.hpp Merge pull request #19631 from prittt:sota-ccl 2021-02-27 17:27:24 +00:00
ccl_bolelli_forest.inc.hpp Merge pull request #19631 from prittt:sota-ccl 2021-02-27 17:27:24 +00:00
clahe.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
color_hsv.dispatch.cpp OCL: fix incompatibility with Mali ruintime 2023-12-21 00:30:44 +03:00
color_hsv.simd.hpp Remove unused variables in rgb2hsv_b simd 2024-06-26 19:07:53 +08:00
color_lab.cpp OCL: fix incompatibility with Mali ruintime 2023-12-21 00:30:44 +03:00
color_rgb.dispatch.cpp OCL: fix incompatibility with Mali ruintime 2023-12-21 00:30:44 +03:00
color_rgb.simd.hpp Clean up the Universal Intrinsic API. 2023-10-13 19:23:30 +08:00
color_yuv.dispatch.cpp Merge pull request #25616 from savuor:rv/yuv_docs 2024-05-25 13:12:03 +03:00
color_yuv.simd.hpp Merge pull request #25616 from savuor:rv/yuv_docs 2024-05-25 13:12:03 +03:00
color.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
color.hpp OCL: fix incompatibility with Mali ruintime 2023-12-21 00:30:44 +03:00
color.simd_helpers.hpp Merge pull request #24333 from definitelyuncertain:CvtRGB2YUV422 2023-10-12 10:18:24 +03:00
colormap.cpp Merge pull request #21645 from chacha21:applyColorMap_8UC1_optimized 2022-03-01 19:55:00 +03:00
connectedcomponents.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
contours_approx.cpp Merge pull request #25680 from mshabunin:fix-approx-2 2024-05-31 19:28:03 +03:00
contours_common.cpp Merge pull request #25146 from mshabunin:cpp-contours 2024-04-09 09:37:49 +03:00
contours_common.hpp Merge pull request #25146 from mshabunin:cpp-contours 2024-04-09 09:37:49 +03:00
contours_link.cpp Merge pull request #25680 from mshabunin:fix-approx-2 2024-05-31 19:28:03 +03:00
contours_new.cpp Removed old C API usage in new findContours implementation. 2024-04-10 11:19:55 +03:00
contours.cpp imgproc: fix contour approximation, added test 2024-05-30 12:23:15 +03:00
convhull.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
corner.avx.cpp Merge pull request #16236 from alalek:fix_core_simd_emulator 2020-01-10 21:31:02 +03:00
corner.cpp Merge pull request #24058 from hanliutong:rewrite-imgporc 2023-09-14 20:37:46 +03:00
corner.hpp AVX optimized implementation of Harris corner detector migrated to separate file 2017-06-29 15:19:23 +03:00
cornersubpix.cpp Merge pull request #25564 from mshabunin:cleanup-imgproc-2 2024-05-17 15:01:05 +03:00
demosaicing.cpp Remove unused brow variable 2024-06-17 18:50:53 +08:00
deriv.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
distransform.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
drawing.cpp Merge pull request #25564 from mshabunin:cleanup-imgproc-2 2024-05-17 15:01:05 +03:00
emd_new.cpp imgproc: fix allocation issue in EMD 2024-05-14 12:51:26 +03:00
emd.cpp Merge pull request #25469 from mshabunin:cpp-emd 2024-04-24 14:28:31 +03:00
featureselect.cpp Merge pull request #19392 from amirtu:OCV-165_finalize_goodFeaturesToTrack_returns_also_corner_value_PR 2021-02-15 19:55:57 +00:00
filter.dispatch.cpp Merge pull request #23109 from seanm:misc-warnings 2023-10-06 13:33:21 +03:00
filter.hpp imgproc: align GaussianBlur/sepFilter2D OpenCL with CPU version 2020-07-08 15:13:48 +00:00
filter.simd.hpp Merge pull request #25364 from mshabunin:fix-unaligned-filter 2024-04-09 17:44:36 +03:00
filterengine.hpp Merge pull request #18073 from vpisarev:apache2_license 2020-08-17 11:49:11 +00:00
fixedpoint.inl.hpp Merge pull request #25364 from mshabunin:fix-unaligned-filter 2024-04-09 17:44:36 +03:00
floodfill.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
gabor.cpp
generalized_hough.cpp Merge remote-tracking branch 'upstream/3.4' into merge-3.4 2018-09-14 23:44:35 +00:00
geometry.cpp Fixed result buffer overflow in intersectConvexConvex_ for non-convex input. 2024-06-10 19:38:35 +03:00
grabcut.cpp Merge pull request #25564 from mshabunin:cleanup-imgproc-2 2024-05-17 15:01:05 +03:00
hal_replacement.hpp Merge pull request #25616 from savuor:rv/yuv_docs 2024-05-25 13:12:03 +03:00
hershey_fonts.cpp
histogram.cpp Merge pull request #25565 from savuor:rv/hal_eq_hist 2024-05-09 08:37:55 +03:00
hough.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
imgwarp.avx2.cpp Move resize implementation to separate file 2017-08-31 14:36:19 +03:00
imgwarp.cpp New HAL API for remap 2024-04-17 11:17:32 +03:00
imgwarp.hpp Fixed most clang -Wextra-semi warnings 2022-09-27 18:06:46 -04:00
imgwarp.lasx.cpp Add Loongson Advanced SIMD Extension support: -DCPU_BASELINE=LASX 2022-09-10 09:39:43 +03:00
imgwarp.sse4_1.cpp Fixed most clang -Wextra-semi warnings 2022-09-27 18:06:46 -04:00
intelligent_scissors.cpp Merge pull request #23109 from seanm:misc-warnings 2023-10-06 13:33:21 +03:00
intersection.cpp Merge pull request #23690 from chacha21:rotatedRectangleIntersection_precision 2023-05-30 17:46:39 +03:00
linefit.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
lsd.cpp Merge pull request #23109 from seanm:misc-warnings 2023-10-06 13:33:21 +03:00
main.cpp
matchcontours.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
median_blur.dispatch.cpp Merge remote-tracking branch 'upstream/3.4' into merge-3.4 2020-03-23 16:54:35 +00:00
median_blur.simd.hpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
min_enclosing_triangle.cpp fix findMinEnclosingTriangle and add tests 2021-10-21 18:12:51 +03:00
moments.cpp Merge pull request #25564 from mshabunin:cleanup-imgproc-2 2024-05-17 15:01:05 +03:00
morph.dispatch.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
morph.simd.hpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
phasecorr.cpp Perform arithmetics in CV_32F branch of divSpectrums() with doubles to prevent infs/NaNs (+ corresponding test). 2024-06-10 15:47:29 +02:00
precomp.hpp Merge pull request #25564 from mshabunin:cleanup-imgproc-2 2024-05-17 15:01:05 +03:00
pyramids.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
resize.avx2.cpp imgproc(resize): drop unused 'pix_size4' 2020-03-29 02:41:50 +00:00
resize.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
resize.hpp Add Loongson Advanced SIMD Extension support: -DCPU_BASELINE=LASX 2022-09-10 09:39:43 +03:00
resize.lasx.cpp Add Loongson Advanced SIMD Extension support: -DCPU_BASELINE=LASX 2022-09-10 09:39:43 +03:00
resize.sse4_1.cpp imgproc(resize): drop unused 'pix_size4' 2020-03-29 02:41:50 +00:00
rotcalipers.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
samplers.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
segmentation.cpp Merge pull request #25564 from mshabunin:cleanup-imgproc-2 2024-05-17 15:01:05 +03:00
shapedescr.cpp imgproc: sync boundingRect function with 5.x 2024-04-17 23:01:31 +03:00
smooth.dispatch.cpp Added HAL function for popular bit-exact branch of GaussianBlur with sigma=0. 2024-04-17 10:13:35 +03:00
smooth.simd.hpp Merge pull request #25364 from mshabunin:fix-unaligned-filter 2024-04-09 17:44:36 +03:00
spatialgradient.cpp Merge pull request #24058 from hanliutong:rewrite-imgporc 2023-09-14 20:37:46 +03:00
stackblur.cpp fix statckblur big kernel case 2024-04-30 18:07:21 +08:00
subdivision2d.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
sumpixels.avx512_skx.hpp Merge pull request #23109 from seanm:misc-warnings 2023-10-06 13:33:21 +03:00
sumpixels.dispatch.cpp fix files permissions 2020-04-13 04:29:55 +00:00
sumpixels.simd.hpp Clean up the Universal Intrinsic API. 2023-10-13 19:23:30 +08:00
tables.cpp
templmatch.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00
thresh.cpp Merge pull request #25509 from savuor:rv/hal_otsu 2024-05-02 20:50:08 +03:00
utils.cpp Partially back-port #25075 to 4.x 2024-03-05 12:15:39 +03:00