Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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 at the crossing point

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);

}

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

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 at metal bar in the crossing pointmiddle 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);

}

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

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);

}