# How to store points cordinats

hi,

I'm new in openCV and c++ and I am stuck at one problem.

For now I would like to make program which will store centerpoints coordinates (x,y) of white blob and then after that draw straight line through them.

This code will calculate center of every white segment per column (po)

```
for (j = 0; j < slikica.cols; j++) {
for (i = 0; i < slikica.rows; i++) {
if (slikica.at<uchar>(i,j) == 255) {
tc = tc + i;
stup = stup + 1;
po = tc / stup;
//HERE I NEED TO STORE POINT (po,j)//
br = br + 1;
}
}
}
```

This is my picture and red line is what i'm looking for.

Thanks

How about a

Thanks, I managed to solve that yesterday but now the next problem is how to fitline? I'm trying something like this ...

That should work. What is your problem now?

The thing is I don't know how to draw that line form start of the blob to the end. I'm using line function to draw it.

"

Output line parameters. In case of 2D fitting, it should be a vector of 4 elements (like Vec4f) - (vx, vy, x0, y0), where (vx, vy) is a normalized vector collinear to the line and (x0, y0) is a point on the line.In case of 3D fitting, it should be a vector of 6 elements (like Vec6f) - (vx, vy, vz, x0, y0, z0), where (vx, vy, vz) is a normalized vector collinear to the line and (x0, y0, z0) is a point on the line"Ok, you found your line as a ´cv::Vec4f´ where you have a starting point (x0, y0) and a vector collinear to the line (vx, vy). Now you can draw your line with (simple line equation):

Choose an appropriate "m".

maybe I don't use your code correctly but what I see "m" is parameter which defines length. My goal is to automatically draw line form the first white column to the last one, like I showed on img.

P.S but yes your code works fine for drawing.

Ok, my bad. So the actual problem is finding the start and end point of the fitted line? If so, you could use findContours to get a contour line around your points. Then you look for the intersection points of the contour (stored as vector<point>) and your line.