findChessboardCorners performance degradation fix for some cases#24558
findChessboardCorners performance degradation fix for some cases#24558thewoz wants to merge 503 commits into
Conversation
|
@thewoz Thanks a lot for the contribution. The PR introduces existing test regression: |
|
sorry where I can found the chess3.png images? |
|
Hi, in https://github.com/opencv/opencv_extra/tree/4.x/testdata/cv/cameracalibration and the chessboard was found in each of them. |
|
@thewoz, basically, you should clone opencv_extra repository and then set OPENCV_TEST_DATA_PATH environment variable pointing to <opencv_extra_dir>/testdata. After that just run opencv_test_calib3d and opencv_perf_calib3d. |
|
Hi, |
|
|
Hello everyone, |
|
sorry I forgot to erase a include file that I use for the debug |
|
Hello everyone is there anything else I can do ? |
|
@vpisarev could you take a look too? |
|
is there anything i can do? |
|
@thewoz, thank you! I think, the patch can be merged. |
There was a problem hiding this comment.
- need to fix extra
\n - what is the performance? reabase to #24605 (comment), this PR improves performance.
- I suggest to use
approxPolyDP()insteadbox_area_covered(check line 1795 in calibinit.cpp)
| float box_area = box.size.width * box.size.height; | ||
| if(contourArea(c) < (box_area_covered * box_area)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
There was a problem hiding this comment.
I think it's a good idea. We need to understand how much the found contour looks like a square of a chessboard. We could use approxPolyDP() for this. We could use algorithm from _findMarkerContours() in ArucoDetector:
// check is square and is convex
vector<Point> approxCurve;
approxPolyDP(contours[i], approxCurve, double(contours[i].size()) * accuracyRate, true);
if(approxCurve.size() != 4 || !isContourConvex(approxCurve)) continue;
// check min distance between corners
double minDistSq =
max(contoursImg.cols, contoursImg.rows) * max(contoursImg.cols, contoursImg.rows);
for(int j = 0; j < 4; j++) {
double d = (double)(approxCurve[j].x - approxCurve[(j + 1) % 4].x) *
(double)(approxCurve[j].x - approxCurve[(j + 1) % 4].x) +
(double)(approxCurve[j].y - approxCurve[(j + 1) % 4].y) *
(double)(approxCurve[j].y - approxCurve[(j + 1) % 4].y);
minDistSq = min(minDistSq, d);
}
double minCornerDistancePixels = double(contours[i].size()) * minCornerDistanceRate;
if(minDistSq < minCornerDistancePixels * minCornerDistancePixels) continue;
There was a problem hiding this comment.
Hi @AleksandrPanov I never perform a rebase.
Can you help me? Sorry about that...
for now I fixed the returns and tested with approxPolyDP() and everything seems to be working.
There was a problem hiding this comment.
checkout your branch to 4.x, update your 4.x branch from https://github.com/opencv/opencv, checkout your branch to fix-issue-23558, rebase and resolve conflicts:
git checkout 4.x
git pull https://github.com/opencv/opencv
git checkout fix-issue-23558
git rebase 4.x
git push -f
fix tab arrow issue
Add weights yolov3 in models.yml opencv#24496 ### 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 don't know if this action is necessary, or the previous PR scale for the brach master. Thanks.
Handle huge images in IPP distanceTransform opencv#24535 ### Pull Request Readiness Checklist * Do not use IPP for huge Mat (reproduced with opencv#23895 (comment) on `DIST_MASK_5`) I have observed two types of errors on the reproducer from the issue: 1. When `temp` is not allocated: ``` Thread 1 "app" received signal SIGSEGV, Segmentation fault. 0x00007ffff65dc755 in icv_l9_ownDistanceTransform_5x5_8u32f_C1R_21B_g9e9 () from /home/dkurtaev/opencv_install/bin/../lib/libopencv_imgproc.so.408 (gdb) bt #0 0x00007ffff65dc755 in icv_l9_ownDistanceTransform_5x5_8u32f_C1R_21B_g9e9 () from /home/dkurtaev/opencv_install/bin/../lib/libopencv_imgproc.so.408 opencv#1 0x00007ffff659e8df in icv_l9_ippiDistanceTransform_5x5_8u32f_C1R () from /home/dkurtaev/opencv_install/bin/../lib/libopencv_imgproc.so.408 opencv#2 0x00007ffff5c390f0 in cv::distanceTransform (_src=..., _dst=..., _labels=..., distType=2, maskSize=5, labelType=1) at /home/dkurtaev/opencv/modules/imgproc/src/distransform.cpp:854 opencv#3 0x00007ffff5c396ef in cv::distanceTransform (_src=..., _dst=..., distanceType=2, maskSize=5, dstType=5) at /home/dkurtaev/opencv/modules/imgproc/src/distransform.cpp:903 opencv#4 0x000055555555669e in main (argc=1, argv=0x7fffffffdef8) at /home/dkurtaev/main.cpp:18 ``` 2. When we keep `temp` allocated every time: ``` OpenCV(4.8.0-dev) Error: Assertion failed (udata < (uchar*)ptr && ((uchar*)ptr - udata) <= (ptrdiff_t)(sizeof(void*)+64)) in fastFree, file /home/dkurtaev/opencv/modules/core/src/alloc.cpp, line 191 terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(4.8.0-dev) /home/dkurtaev/opencv/modules/core/src/alloc.cpp:191: error: (-215:Assertion failed) udata < (uchar*)ptr && ((uchar*)ptr - udata) <= (ptrdiff_t)(sizeof(void*)+64) in function 'fastFree' ``` * Try enable IPP for 3x3 (see opencv#15904) * Reduce memory footprint with IPP 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
…n and bug fix (opencv#24462) * add hardswish for cann * gemm cann bug fix * fix indentation * cann: add layer norm * cann: add instance norm * add supportBackend * cann: layer norm does not support axis=-1 due to 1d mat issue * disable instance norm for now * fix doc * remove tensor desc initialization for 1D tensor
…e-selection-onnxrt-directml G-API: Advanced device selection for ONNX DirectML Execution Provider opencv#24060 ### Overview Extend `cv::gapi::onnx::ep::DirectML` to accept `adapter name` as `ctor` parameter in order to select execution device by `name`. E.g: ``` pp.cfgAddExecutionProvider(cv::gapi::onnx::ep::DirectML("Intel Graphics")); ``` ### 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
Using cv2 dnn interface to run yolov8 model opencv#24396 This is a sample code for using opencv dnn interface to run ultralytics yolov8 model for object detection. ### 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
…_gemm Fast gemm for einsum opencv#24509 ## This PR adds performance tests for Einsum Layer with FastGemm. See below results of performance test on different inputs ### 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 - [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
…on-estimator Bugfix/qrcode version estimator opencv#24364 Fixes opencv#24366 ### 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
Updated Android samples for modern Android studio. Added OpenCV from Maven support. opencv#24473 Updated samples for recent Android studio: - added namespace field that is required in build.gradle files - replaced _switch_ by _if-else_ because it doesn't work with constants from resources - added missed log library dependency in face-detection/jni/CMakeLists.txt - use local.properties to define NDK location Added support for OpenCV from Maven. Now you can choose 3 possible sources of OpenCV lib in settings.gradle: SDK path, local Maven repository, public Maven repository. (Creating Maven repository from SDK is added here opencv#24456 ) There are differences in project configs for SDK and Maven versions: - different dependencies in build.gradle - different OpenCV library names in CMakeLists.txt - SDK version requires OpenCV_DIR definition Requires: - opencv/ci-gha-workflow#124 - opencv-infrastructure/opencv-gha-dockerfile#26
28fbca0 to
45e047f
Compare
|
Hello everyone, |
|
@thewoz, I tried to use the approxPolyDP() func too, and it really wasn't working too well. You could try to call this function twice, but it doesn't look like a good solution. Now I think that use |
|
Hi @AleksandrPanov thank you for your time.. |
|
@thewoz, there are not enough tests in OpenCV for findchessboardcorners() and therefore algorithm changes can cause regressions that we may not catch. We want to expand the test suite, but this is a big task. After that, we will try to improve the code based on your ideas. |
|
Hi @AleksandrPanov, |
Fixes #23558
In the issue #23558 an empty image was passed to the findChessboardCorners() function with the CALIB_CB_FAST_CHECK flag. The fast check failed and findChessboardCorners() wasted 15minutes finding a checkerboard that was not there in the image.
The reason is that the checkChessboardBinary() function returned true because the checkQuads() function was convinced that among all the contours found by fillQuads() were those of the checkerboard.
The problem was icvGetQuadrangleHypotheses() that incorrectly filtering the contours found. It was passing too many contours to checkQuads(), and by the law of large numbers, checkQuads() was able to find contours that "looked" like a checkerboard between them.
What I did is to shrink the parameters in the icvGetQuadrangleHypotheses() function. I changed the range of the ratio between the sides of the contour found to 0.5 and 1.5. More reasonable values than the previous 0.3 and 3.0. In addition, I raised the minimum side length of the hypothetical square from 10 to 25 pixels.
After the change I tried the function on other checkerboard images and had no problems.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.