Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

negative index in padded image? #4

Open
svoros opened this issue May 24, 2018 · 12 comments
Open

negative index in padded image? #4

svoros opened this issue May 24, 2018 · 12 comments

Comments

@svoros
Copy link

svoros commented May 24, 2018

Hi,
I've been trying to use your code on Windows 10 (vc++12, OpenCV 2.4.9).
I'm able to compile correctly but am facing some issues when running the code.
More precisely, when I'm in the function FAsTMatch::evaluateConfigs,
when the score is computed as
score += abs(vals_i1[j] - padded.at(target_y - 1, target_x - 1) );
I have negative values for target_x - 1, so the program crashes.
I'm running the tests with the image.png and template.png files you provided.
I have otherwise not changed the parameters you used in your main function to call the FAsTMatch, and have not changed the padding of the image either.
Would you have any insights on how to solve this issue?
Thanks

@joeqincai
Copy link

I also have faced problem about
score += abs(vals_i1[j] - padded.at(target_y - 1, target_x - 1) );
I have negative values for target_x - 1, so the program crashes. I don't have good idea to solve it.

@joeqincai
Copy link

In addition, WITHIN(affine_corners.atcv::Point2f(0) like this , it doesn't work.

@svoros
Copy link
Author

svoros commented Jun 7, 2018

Hi
I actually was able to solve the issue and it seems to work: in the current code, the image is only padded horizontally (black stripes on the top and bottom). I solved the issue by padding it vertically too.
In FastMatch.cpp, I replaced the original padding by:
/* Use a padded image, to avoid boundary checking */
Mat padded( image.rows * 3, image.cols + 100 , image.type(), Scalar(0.0) );
image.copyTo( Mat(padded, Rect(50, image.rows, image.cols, image.rows)) );
I also modified tmp1 definitions to take into account the new padding;
double tmp_1 = (r2x + 1) + a13 + 0.5 + 50;
It seems to work for me (I did this quickly so I hope I made the correct changes everywhere, but at least the program doesn't crash and it seems to find the templates where they should be).

@svoros
Copy link
Author

svoros commented Jun 7, 2018

For WITHIN(affine_corners...) I modified the code in such way in configsToAffine():

cv::Point2f point0, point1, point2, point3;
point0.x = affine_corners.at(0, 0);
point0.y = affine_corners.at(0, 1);
point1.x = affine_corners.at(1, 0);
point1.y = affine_corners.at(1, 1);
point2.x = affine_corners.at(2, 0);
point2.y = affine_corners.at(2, 1);
point3.x = affine_corners.at(3, 0);
point3.y = affine_corners.at(3, 1);

if (WITHIN(point0, top_left, bottom_right) &&
WITHIN(point1, top_left, bottom_right) &&
WITHIN(point2, top_left, bottom_right) &&
WITHIN(point3, top_left, bottom_right)) {

affines[i] = affine;
insiders[i] = true;

}

@yangninghua
Copy link

Hi
I actually was able to solve the issue and it seems to work: in the current code, the image is only padded horizontally (black stripes on the top and bottom). I solved the issue by padding it vertically too.
In FastMatch.cpp, I replaced the original padding by:
/* Use a padded image, to avoid boundary checking */
Mat padded( image.rows * 3, image.cols + 100 , image.type(), Scalar(0.0) );
image.copyTo( Mat(padded, Rect(50, image.rows, image.cols, image.rows)) );
I also modified tmp1 definitions to take into account the new padding;
double tmp_1 = (r2x + 1) + a13 + 0.5 + 50;
It seems to work for me (I did this quickly so I hope I made the correct changes everywhere, but at least the program doesn't crash and it seems to find the templates where they should be).

Hello, thank you for your answer, it really can run, but the speed is not particularly satisfactory, I am on the window10 i7 6 core 12 thread GTX1060 computer, it needs more time than matlab

@yangninghua
Copy link

For WITHIN(affine_corners...) I modified the code in such way in configsToAffine():

cv::Point2f point0, point1, point2, point3;
point0.x = affine_corners.at(0, 0);
point0.y = affine_corners.at(0, 1);
point1.x = affine_corners.at(1, 0);
point1.y = affine_corners.at(1, 1);
point2.x = affine_corners.at(2, 0);
point2.y = affine_corners.at(2, 1);
point3.x = affine_corners.at(3, 0);
point3.y = affine_corners.at(3, 1);

if (WITHIN(point0, top_left, bottom_right) &&
WITHIN(point1, top_left, bottom_right) &&
WITHIN(point2, top_left, bottom_right) &&
WITHIN(point3, top_left, bottom_right)) {

affines[i] = affine;
insiders[i] = true;

}

Excuse me, after you configure it, use the author's picture, how long does it run in Release?

@svoros
Copy link
Author

svoros commented Nov 4, 2018 via email

@subokita
Copy link
Owner

subokita commented Nov 4, 2018

Somehow I completely missed all the conversations.
Anyway, I didn't come up with the name FAST, it was the original author of the code, at that point of time, for the thing it does (rotational invariance), it was fast.

Second thing, since I didn't have access to CUDA, so I the only parallelization I did was to use Intel TBB, if you know some GPU computing, that should speed it up considerably. Remember, this is 4 years old code, advancement in GPU, Tensor Flow, etc, should mean that this can be optimized way faster.

Also, avoid
affine_corners.at(0, 0);
deference it to pointer instead, if that code gets executed multiple times. Since at(x,y) redo the calculation (at least in the older OpenCV) to find the index.

And for this
score += abs(vals_i1[j] - padded.at(target_y - 1, target_x - 1) );
There should be a part where it does the padding, maybe I missed the X-axis part?

@svoros
Copy link
Author

svoros commented Nov 5, 2018 via email

@yangninghua
Copy link

Hi there, I didn't look at computation time as I Just wanted to test the algorithm but indeed it took long minutes for one image (maybe 15-20?) on a somewhat powerful laptop so I was a bit disapointed about thé 'fast' title... Might be a question of parameters space tuning though, Hope it helps and I'm interested if you find à solution. Best, Sandrine
----- Mail d'origine ----- De: yangninghua notifications@github.com À: subokita/FAsT-Match FAsT-Match@noreply.github.com Cc: svoros Sandrine.Voros@univ-grenoble-alpes.fr, Author author@noreply.github.com Envoyé: Fri, 02 Nov 2018 15:06:36 +0100 (CET) Objet: Re: [subokita/FAsT-Match] negative index in padded image? (#4)
For WITHIN(affine_corners...) I modified the code in such way in configsToAffine(): cv::Point2f point0, point1, point2, point3; point0.x = affine_corners.at(0, 0); point0.y = affine_corners.at(0, 1); point1.x = affine_corners.at(1, 0); point1.y = affine_corners.at(1, 1); point2.x = affine_corners.at(2, 0); point2.y = affine_corners.at(2, 1); point3.x = affine_corners.at(3, 0); point3.y = affine_corners.at(3, 1); if (WITHIN(point0, top_left, bottom_right) && WITHIN(point1, top_left, bottom_right) && WITHIN(point2, top_left, bottom_right) && WITHIN(point3, top_left, bottom_right)) { affines[i] = affine; insiders[i] = true; }
Excuse me, after you configure it, use the author's picture, how long does it run in Release?

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: #4 (comment)

Thank you for your answer, my laptop configuration is, CPU: i7-8750H, GPU: GTX1060, I configured it according to your method, running time Release is more than 300 seconds, thank you for your help and advice

@zhoujinhai
Copy link

zhoujinhai commented Aug 22, 2019

@subokita I can't find the tbb file when run the codes.

#include <tbb/tbb.h>

@githubcyy
Copy link

@subokita I meet the same issue, I can't find the tbb file when run the codes.
#include <tbb/tbb.h>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants