Skip to content

search in two directions when try to add new quad in addOuterQuad#25807

Merged
asmorkalov merged 2 commits intoopencv:4.xfrom
spdfghi:4.x
Jul 24, 2024
Merged

search in two directions when try to add new quad in addOuterQuad#25807
asmorkalov merged 2 commits intoopencv:4.xfrom
spdfghi:4.x

Conversation

@spdfghi
Copy link
Copy Markdown
Contributor

@spdfghi spdfghi commented Jun 23, 2024

In ChessBoardDetector::addOuterQuad, previous code try to connect new quad with inner quad, if possible, but only search for one direction. I have made three test images, one is normal(a.jpg), one lossed an outer quad(b.jpg), and then i flipped it vertically(c.jpg). Only last one fails. I fixed it by check two directions and row/col.

Here is the test code and images:

Mat img;
vector<Point2f> corners;
auto size = cv::Size(6, 6);
img = imread("D:/tmp/a.jpg", 0);
std::cout<<cv::findChessboardCorners(img, size, corners)<<"\n";
std::cout << corners.size() << "\n";
img = imread("D:/tmp/b.jpg", 0);
std::cout<<cv::findChessboardCorners(img, size, corners)<<"\n";
std::cout << corners.size() << "\n";
img = imread("D:/tmp/c.jpg", 0);
std::cout<<cv::findChessboardCorners(img, size, corners)<<"\n";
std::cout << corners.size() << "\n";

a
a
b
b
c
c

@spdfghi spdfghi changed the title fixed bug: wrong implemention of connecting neighbor quad and new qua… search in two directions when try to add new quad in addOuterQuad Jun 24, 2024
@asmorkalov asmorkalov requested review from AleksandrPanov and asmorkalov and removed request for AleksandrPanov June 24, 2024 06:30
@asmorkalov asmorkalov added this to the 4.11.0 milestone Jun 24, 2024
@spdfghi
Copy link
Copy Markdown
Contributor Author

spdfghi commented Jun 27, 2024

Since it's not an usual algorithm, so i have made a simple note image to show how it happends:
IMG_0039
i noted the index of missed quad, the privous code try to get another quad connected to the missed quad by first search the index prev_i quad, and then get the index next_i quad of prev_i quad. It works sometime, for example, A to C. However, it failed with the opposite direction, i.e., C to A. Which depends on who was first searched by dfs previously. The line begin in 1155 i made was followed line 924

for (int i = 0; i < 4; i++)
{
    CV_DbgAssert(q);
    ChessBoardQuad* neighbor = q->neighbors[i];
    switch (i)   // adjust col, row for this quad
    {           // start at top left, go clockwise
    case 0:
        row--; col--; break;
    case 1:
        col += 2; break;
    case 2:
        row += 2;   break;
    case 3:
        col -= 2; break;
    }

@asmorkalov

@asmorkalov
Copy link
Copy Markdown
Contributor

@MaximSmolskiy Could you take a look and try with your dataset?

1 similar comment
@asmorkalov
Copy link
Copy Markdown
Contributor

@MaximSmolskiy Could you take a look and try with your dataset?

@MaximSmolskiy
Copy link
Copy Markdown
Contributor

@MaximSmolskiy Could you take a look and try with your dataset?

@asmorkalov I didn't deal with this function, so I amn't ready to review this pr.
These changes provide minor improvements on my 2 private datasets:

  1. 294 -> 296 detected chessboards
  2. 524 -> 527 detected chessboards

@asmorkalov
Copy link
Copy Markdown
Contributor

@MaximSmolskiy Thanks a lot for the feedback. The patch does not change result of synthetic benchmark. Just want to get feedback for real images.

@asmorkalov asmorkalov self-assigned this Jul 24, 2024
@asmorkalov asmorkalov merged commit 160879c into opencv:4.x Jul 24, 2024
@asmorkalov asmorkalov mentioned this pull request Jul 25, 2024
fengyuentau pushed a commit to fengyuentau/opencv that referenced this pull request Aug 15, 2024
Search in two directions when try to add new quad in addOuterQuad opencv#25807

In ChessBoardDetector::addOuterQuad, previous code try to connect new quad with inner quad, if possible, but only search for one direction. I have made  three test images, one is normal(a.jpg), one lossed an outer quad(b.jpg), and then i flipped it vertically(c.jpg). Only last one fails. I fixed it by check two directions and row/col.

Here is the test code and images:
```
Mat img;
vector<Point2f> corners;
auto size = cv::Size(6, 6);
img = imread("D:/tmp/a.jpg", 0);
std::cout<<cv::findChessboardCorners(img, size, corners)<<"\n";
std::cout << corners.size() << "\n";
img = imread("D:/tmp/b.jpg", 0);
std::cout<<cv::findChessboardCorners(img, size, corners)<<"\n";
std::cout << corners.size() << "\n";
img = imread("D:/tmp/c.jpg", 0);
std::cout<<cv::findChessboardCorners(img, size, corners)<<"\n";
std::cout << corners.size() << "\n";
```
![a](https://github.com/opencv/opencv/assets/92856207/0dc7f5bf-7637-4333-9a9f-ec4ede790027)
a
![b](https://github.com/opencv/opencv/assets/92856207/39793485-ca0c-44c0-b44d-a593d36c1888)
b
![c](https://github.com/opencv/opencv/assets/92856207/2e7789c8-cfa5-438c-9530-2862a8a3741f)
c
thewoz pushed a commit to CobbsLab/OPENCV that referenced this pull request Feb 13, 2025
Search in two directions when try to add new quad in addOuterQuad opencv#25807

In ChessBoardDetector::addOuterQuad, previous code try to connect new quad with inner quad, if possible, but only search for one direction. I have made  three test images, one is normal(a.jpg), one lossed an outer quad(b.jpg), and then i flipped it vertically(c.jpg). Only last one fails. I fixed it by check two directions and row/col.

Here is the test code and images:
```
Mat img;
vector<Point2f> corners;
auto size = cv::Size(6, 6);
img = imread("D:/tmp/a.jpg", 0);
std::cout<<cv::findChessboardCorners(img, size, corners)<<"\n";
std::cout << corners.size() << "\n";
img = imread("D:/tmp/b.jpg", 0);
std::cout<<cv::findChessboardCorners(img, size, corners)<<"\n";
std::cout << corners.size() << "\n";
img = imread("D:/tmp/c.jpg", 0);
std::cout<<cv::findChessboardCorners(img, size, corners)<<"\n";
std::cout << corners.size() << "\n";
```
![a](https://github.com/opencv/opencv/assets/92856207/0dc7f5bf-7637-4333-9a9f-ec4ede790027)
a
![b](https://github.com/opencv/opencv/assets/92856207/39793485-ca0c-44c0-b44d-a593d36c1888)
b
![c](https://github.com/opencv/opencv/assets/92856207/2e7789c8-cfa5-438c-9530-2862a8a3741f)
c
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.

3 participants