You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a code smell "break" in loop in the calib3d, USAC source code in the following source code module:
sampler.cpp
See attached screenshots for examples:
Detailed description
The whle loops below should be rewritten to not rely on "break" statements to terminate. They should instead have a condition written into the while loops to terminate when a value is reached, instead of just "breaking".
Steps to reproduce
One can have embedded while loops to terminate where a break is reached. Here is the link to the file as is:
This can be written similar to as shown in the After chunk of code, compared to the Before chunk:
Before
void setSampleNumber (int k) {
kth_sample_number = k;
// If the method should act exactly like RANSAC
if (kth_sample_number > growth_max_samples)
return;
else { // Increment the size of the sampling pool while required
subset_size = sample_size; // reset subset size as from the beginning
while (kth_sample_number > growth_function[subset_size-1]) {
subset_size++;
if (subset_size >= points_size){
subset_size = points_size;
break;
}
}
if (termination_length < subset_size)
termination_length = subset_size;
}
}
Proposed
void setSampleNumber (int k) {
kth_sample_number = k;
**int stop = 0;**
// If the method should act exactly like RANSAC
if (kth_sample_number > growth_max_samples)
return;
else { // Increment the size of the sampling pool while required
subset_size = sample_size; // reset subset size as from the beginning
while (kth_sample_number > growth_function[subset_size-1] ) {
subset_size++;
if (subset_size >= points_size **and stop_int == 0**){
subset_size = points_size;
**stop = 1;**
}
}
if (termination_length < subset_size)
termination_length = subset_size;
}
}
Issue submission checklist
I report the issue, it's not a question
I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
I updated to the latest OpenCV version and the issue is still there
There is reproducer code and related data files (videos, images, onnx, etc)
The text was updated successfully, but these errors were encountered:
Bruce387
changed the title
Removing "break" statements from loops - calib3d
Removing "break" statements from While loop - calib3d, USAC source code
May 27, 2024
System Information
There is a code smell "break" in loop in the calib3d, USAC source code in the following source code module:
sampler.cpp
See attached screenshots for examples:
Detailed description
The whle loops below should be rewritten to not rely on "break" statements to terminate. They should instead have a condition written into the while loops to terminate when a value is reached, instead of just "breaking".
Steps to reproduce
One can have embedded while loops to terminate where a break is reached. Here is the link to the file as is:
https://github.com/opencv/opencv/blob/4.x/modules/calib3d/src/usac/sampler.cpp
This can be written similar to as shown in the After chunk of code, compared to the Before chunk:
Before
Proposed
Issue submission checklist
The text was updated successfully, but these errors were encountered: