Best way to get Contour's extreme points with C++?

asked 2018-03-20 15:58:32 -0600

minh gravatar image

updated 2020-10-23 09:03:13 -0600

Im working on my C++ project, and it require detecting V-shape-like contour.With extreme points i will be able to tell which contour is suitable. Example: the pointy metal bar in the middle of the cross road

image description

This is my current code to find extreme point is doing its job but when i put it into header file and run on jetson tk1, its too slow and i wonder if there is a way to make run faster or maybe another method that work better and faster. The code, here:

vector<Point> exLeft;
vector<Point> exRight;
vector<Point> exTop;
vector<Point> exBott;
for (size_t i = 0; i < cnts.size();i++){
    Point tmpLeft;
    Point tmpRight;
    Point tmpTop;
    Point tmpBott;
    tmpLeft.x = 1000;
    tmpRight.x = -1000;
    tmpBott.y = -1000;
    tmpTop.y = 1000;

    vector<Point> cnt;
    cnt = cnts[i];
    for (size_t j=0; j < cnt.size();j++){
        Point current = cnt[j];
        if (current.x < tmpLeft.x){
            tmpLeft = current;
        }
        if (current.x > tmpRight.x){
            tmpRight = current;
        }
        if (current.y > tmpBott.y){
            tmpBott = current;
        }
        if (current.y < tmpTop.y){
            tmpTop = current;
        }
    }
    exLeft.push_back(tmpLeft);
    exRight.push_back(tmpRight);
    exTop.push_back(tmpTop);
    exBott.push_back(tmpBott);

}
edit retag flag offensive close merge delete

Comments

2

Could you please add the complete code (including the Pre-processing step)? In my opinion you should find Hough Line Transform to find the intersection of these lines!

Balaji R gravatar imageBalaji R ( 2018-03-20 22:45:38 -0600 )edit

I tried with houghLine but its not really accurate, so i though of extreme point in contour and it work very well, but a bit slow for some reason, i need to increase FPS

minh gravatar imageminh ( 2018-03-21 11:13:00 -0600 )edit

"I tried with houghLine but its not really accurate" Can you show us the results so that we can help further?

Balaji R gravatar imageBalaji R ( 2018-03-21 23:22:51 -0600 )edit