Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I followed both approaches as mentioned in the comments above. First I generate a LineIterator for every single line. Then I get the magnitude values out of the magnitude Mat. After that it is possible to calculate the sum/normalized sum etc. Thanks for the help.

Here is the code:

void computeStrengthOfEdges(Mat magn, vector<Vec4f> lines) {

    vector<float> magnitude_of_line;
        vector<float> strength;

    for (size_t i = 0; i < lines.size(); i++) {

        // Generate a LineIterator for every line
        LineIterator line_iterator(magn, Point2f(lines[i][0], lines[i][1]), Point2f(lines[i][2], lines[i][3]), 8, true);

        for (int j = 0; j < line_iterator.count; j++, ++line_iterator) {
        // Get all values the line hits (8 way-connection) in the magnitude image
            float magnitude_value = magn.at<float>(line_iterator.pos()); 
            magnitude_of_line.push_back(magnitude_value);
        }
        // Calculate the sum all values
        float sum = accumulate(magnitude_of_line.begin(), magnitude_of_line.end(), 0.0);    
        strength.push_back(sum);
        magnitude_of_line.clear();      
    }   
}

I followed both approaches as mentioned in the comments above. First I generate a LineIterator for every single line. Then I get the magnitude values out of the magnitude Mat. After that it is possible to calculate the sum/normalized sum etc. Thanks for the help.

Here is the code:

void computeStrengthOfEdges(Mat magn, vector<Vec4f> lines) {

    vector<float> magnitude_of_line;
     vector<float> strength;

    for (size_t i = 0; i < lines.size(); i++) {

        // Generate a LineIterator for every line
        LineIterator line_iterator(magn, Point2f(lines[i][0], lines[i][1]), Point2f(lines[i][2], lines[i][3]), 8, true);

        for (int j = 0; j < line_iterator.count; j++, ++line_iterator) {
        // Get all values the line hits (8 way-connection) in the magnitude image
            float magnitude_value = magn.at<float>(line_iterator.pos()); 
            magnitude_of_line.push_back(magnitude_value);
        }
        // Calculate the sum all values
        float sum = accumulate(magnitude_of_line.begin(), magnitude_of_line.end(), 0.0);    
        strength.push_back(sum);
        magnitude_of_line.clear();      
    }   
}