Skip to content

findChessboardCornersSB: speed improvements#12615

Merged
alalek merged 8 commits intoopencv:masterfrom
D-Alex:master
Sep 25, 2018
Merged

findChessboardCornersSB: speed improvements#12615
alalek merged 8 commits intoopencv:masterfrom
D-Alex:master

Conversation

@D-Alex
Copy link
Copy Markdown
Contributor

@D-Alex D-Alex commented Sep 22, 2018

findChessboardCornersSB: speed up using parallel_for and add support for flags

force_builders=linux,windows,macosx,docs

@param flags operation flags for future improvements
@param flags Various operation flags that can be zero or a combination of the following values:
- **CALIB_CB_NORMALIZE_IMAGE** Normalize the image gamma with equalizeHist before detection.
- **CALIB_CB_EXAUSTING ** Run an exhausting search to improve detection rate.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change to CALIB_CB_EXHAUSTIVE?
I understand this option like a brute-force approach. In this case, exhaustive search looks more appropriate in my opinion.

flags ^= CALIB_CB_ACCURACY;
}
if(flags)
CV_Error(Error::StsOutOfRange, "Invalid remaing flags " + std::to_string(flags));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCC 4.8 (Android builder) has bad support for std::to_string().

Please use this code:

CV_Error(Error::StsOutOfRange, cv::format("Invalid remaing flags %d", (int)flags));

}
});
// check if a good board was found
for(auto board : boards)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const auto& ?

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! Thank you 👍

@alalek alalek merged commit 8811dab into opencv:master Sep 25, 2018
@tompollok
Copy link
Copy Markdown
Contributor

tompollok commented Sep 26, 2018

@D-Alex did you check the chessboard detection rate of findChessboardCorners vs findChessboardCornersSB ?

I tested both functions (opencv4.0.0 alpha and not master) and findChessboardCorners seems to outperform findChessboardCornersSB in terms of chessboard detection rate.

Check out this video: https://www.youtube.com/watch?v=ImpxJSIbBdk

I played the sequence twice. first with findChessboardCorners (red) and then again with findChessboardCorners SB (green)

I think about 30% of the chessboard detections are missing. I admit that shirt is not necessarily the best for doing calibrations, but findChessboardCorners had no problems with that.

@tompollok
Copy link
Copy Markdown
Contributor

I tested it with another sequence where i wear a neutral shirt and there i have the same or worse problem. In the conditions of the image below i have zero chessboard detections with or without cv::CALIB_CB_NORMALIZE_IMAGE being set.

grafik

@D-Alex
Copy link
Copy Markdown
Contributor Author

D-Alex commented Sep 26, 2018

Thx for reporting problems with the detection rate and I am sure there is room for improvements. Have you tested it against the current version merged yesterday?

I am asking because I changed MIN_RESPONSE_RATIO from 0.3F to= 0.1F which was added to speed up detections. However, this filters out points which are less than 30% of the strongest key points. And this is exactly the case in your images.

I tested your last image and it seems to work with the current version if CALIB_CB_NORMALIZE_IMAGE is added as flag. Attached is the repsonse map of the detector which looks very healthy.

feature_map_3

@tompollok
Copy link
Copy Markdown
Contributor

Thank you for your fast response. As mentioned i have only tested against 4.0.0-alpha. Do you know if it is possible to download master build artifacts for windows from the opencv buildservers?

@alalek
Copy link
Copy Markdown
Member

alalek commented Sep 26, 2018

download master build artifacts

We don't provide such builds on public.

@D-Alex
Copy link
Copy Markdown
Contributor Author

D-Alex commented Sep 26, 2018

findChessboardCornersSB part of the alpha build is not really aware of the flags. This was added yesterday. Therefore, to work around the issue you can do the normalisation by yourself calling equalizeHist before calling findChessboardCornersSB.

In addition you can provide 1 as flag to increase the number of tests. However, the alpha version does not take advantage of multiple CPUs for around half of the code base. Also you still have the hard coded 30% threshold which might be ok if you normalise your images.

@tompollok
Copy link
Copy Markdown
Contributor

Alright, thank you @D-Alex and @alalek for your replies.

@tompollok
Copy link
Copy Markdown
Contributor

cv::equalizeHist(mat, mat); before findChessboardCornersSB(...) improved the detection from 0% to about 50% for the sequence of the image of which you made a responsemap for me. So i guess ill have to recompile master with a lower MIN_RESPONSE_RATIO.

providing 1 as a flag for findChessboardCornersSB flags parameter crashes my application. Probably some assertion, but i didnt investigate.

@D-Alex
Copy link
Copy Markdown
Contributor Author

D-Alex commented Sep 26, 2018

Yep - the assertion was also fixed when the flags were implemented. I forgot about it. If you upload your sequence somewhere I can run it with the current version. Otherwise you would have to compile it using the current master.

@tompollok
Copy link
Copy Markdown
Contributor

I compiled master and it still crashes with 1 (CALIB_CB_ADAPTIVE_THRESH)

OpenCV(4.0.0-pre) C:\3rdparty\ocv4_master\opencv\modules\calib3d\src\chessboard.cpp:3211: error: (-211:One of arguments' values is out of range) Invalid remaing flags 1 in function 'cv::findChessboardCornersSB'

@D-Alex
Copy link
Copy Markdown
Contributor Author

D-Alex commented Sep 26, 2018

Like stated in the header (I know it is hard to read when not compiled ;-)) it only supports:

CALIB_CB_NORMALIZE_IMAGE = 2
CALIB_CB_EXHAUSTING = 16,
CALIB_CB_ACCURACY = 32

@tompollok
Copy link
Copy Markdown
Contributor

I have seen the documentation but you mentioned "In addition you can provide 1 as flag to increase the number of tests." before. I also took a look at the code now and there i clearly see that 1 is not supported :-)

@tompollok
Copy link
Copy Markdown
Contributor

i guess you meant 16 instead of 1

@tompollok
Copy link
Copy Markdown
Contributor

flags = cv::CALIB_CB_NORMALIZE_IMAGE | cv::CALIB_CB_EXHAUSTIVE | cv::CALIB_CB_ACCURACY;

With flags as above the detection rate is much better but i still have many "easy" chessboards that aren't detected. If you want, i can provide you some of them.

Another question: What did you use to enable parallel_for_?

According to the link below a few options are available. Did you just enable openMP?

https://docs.opencv.org/trunk/d7/dff/tutorial_how_to_use_OpenCV_parallel_for_.html

The first precondition is to have OpenCV built with a parallel framework. In OpenCV 3.2, the following parallel frameworks are available in that order:

1. Intel Threading Building Blocks (3rdparty library, should be explicitly enabled)
2. C= Parallel C/C++ Programming Language Extension (3rdparty library, should be explicitly enabled)
3. OpenMP (integrated to compiler, should be explicitly enabled)
4. APPLE GCD (system wide, used automatically (APPLE only))
5. Windows RT concurrency (system wide, used automatically (Windows RT only))
6. Windows concurrency (part of runtime, used automatically (Windows only - MSVC++ >= 10))
7. Pthreads (if available)

@D-Alex
Copy link
Copy Markdown
Contributor Author

D-Alex commented Sep 26, 2018

Sure - I am happy to have a look why certain checkerboards are not detected. I am using a Mac therefore I would guess option 4.

@tompollok
Copy link
Copy Markdown
Contributor

Alright, i will send you some images during the next week.

With findChessboardCorners I used cornerSubPix to refine the corner locations. Am I assuming correctly that cornerSubPix would only degrade the corner locations from your algorithm?

AhiyaHiya pushed a commit to AhiyaHiya/opencv that referenced this pull request Sep 27, 2018
* master: (286 commits)
  Merge pull request opencv#12608 from dmatveev:gapi
  M_PI changed to CV_PI (opencv#12645)
  dnn: fix printf format warning
  Merge pull request opencv#12615 from D-Alex:master
  Fixed several incorrect printf format specifiers
  core: fix printf warnings by using c++11 format
  core: enable printf format warnings for cv::format
  JS: Support enum properties
  fix a bug in OpenGL
  samples: update winpack python samples launcher
  Merge pull request opencv#12310 from cv3d:chunks/enum_interface
  Merge pull request opencv#12601 from cv3d:fix/js
  release: OpenCV 4.0.0-alpha (version++)
  cuda: move CUDA modules to opencv_contrib
  cmake: update install paths (Linux)
  Merge pull request opencv#12570 from alalek:drop_usrtype1
  Fix failure to request stddev of non-intrinsics
  ts: update valgrind test filter
  build: fix Xcode 10 build problems
  Enable Myriad device for OpenVINO models test
  ...
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
findChessboardCornersSB: speed improvements (opencv#12615)

* chessboard: fix do not modify const image

* chessboard: speed up scale space using parallel_for

* chessboard: small improvements

* chessboard: speed up board growing using parallel_for

* chessboard: add flags for tuning detection

* chessboard: fix compiler warnings

* chessborad: change flag name to CALIB_CB_EXHAUSTIVE

This also fixes a typo

* chessboard: fix const ref + remove to_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants