Which is the result of the function fitline() ?

I want to fit a line from a contour. The result of the fitline() function is a 2D vector (resultLine) with 4 elements: vx, vy, x0, y0. Doing resultLine.size() I get [1x4], which make sense given the documentation. Therefore, I don't understand what this line of code does:

resultLine.at<uchar>(i,j,0);

where 'i' goes from 0:1080 and 'j' 0:255

I got this code from an other person, and I'm trying understand it.

Example:

cv::Mat& img
std::vector<cv::Mat> contours;
cv::Mat resultLine;
cv::cvtColor(img, grey,cv::COLOR_BGR2GRAY);
cv::threshold(grey, thresh, 19, 255, cv::THRESH_BINARY);
cv::findContours(thresh, contours, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE);

for(int t = 0; t < contours.size(); t++){
cv::fitLine(contours[t], resultLine, cv::DIST_L2, 0, 0.01, 0.01);
}

for (int i = (img.rows-1); i > (img.rows / 2); i = i - 5){
for (int j = 0; j < img.cols; j++) { //goes across the images
if(img.at<uchar>(i, j, 0) != resultLine.at<uchar>(i, j, 0)){
...}
}
}

edit retag close merge delete

and you need one resultLine per contour, not one for all of them (that person's code is probably just bs)

( 2019-11-12 03:31:34 -0500 )edit

comparing image pixels with line positions is PLAIN bs, really.

please ask back, what should be achieved here, as it is now, we cannot help

( 2019-11-12 03:33:08 -0500 )edit