Skip to content

Commit 612c43f

Browse files
committed
Cleaning code and adding comments
1 parent 6629771 commit 612c43f

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

sources/find_particules.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ void find_particules(cv::Mat & input, int frame, vector <Points> & points)
7272
{
7373

7474
unsigned int count=0;
75-
uint8_t *myData = input.data;
76-
int width = input.cols;
77-
int height = input.rows;
75+
uint8_t *myData = input.data; //input data are a vector of uint_8, we need to know how many elements we have
76+
int width = input.cols; //to know the size of each element (sizeof(float)) and how many elements are
77+
int height = input.rows; //are in a row to read it as if it was a matrix…
7878
int _stride = input.step;//in case cols != strides
7979
float* ptr = (float*) input.data;
8080
size_t elem_step = input.step / sizeof(float);
@@ -85,28 +85,20 @@ void find_particules(cv::Mat & input, int frame, vector <Points> & points)
8585
for(int j = 0; j < width; j++)
8686
{
8787
// cout<<"j="<<j<<endl;
88-
float val = ptr[i * elem_step + j];
89-
90-
if (val!=0)
91-
{
92-
// cout<<"Particles found at position : "<<i<<" "<<j<<endl;
93-
int partial_count=1;
94-
int current_partial=0;
95-
// cout<<"P1 "<<points.size()<<" ";
88+
float val = ptr[i * elem_step + j]; //value of the current pixel
89+
90+
if (val!=0) //value above threshold: the edge of a particle! (top edge) We will check all its neighbor for other non black pixels (part of the particle) and will
91+
{ //do that recursively for all non-0 pixels until the whole particle is detected…
92+
int partial_count=1; //number of pixels positively detected
93+
int current_partial=0; //number of pixels for which all neighbors have been checked
9694
points.push_back(Points(i,j));
97-
// cout<<"P2 "<<points.size()<<endl;
98-
ptr[i*elem_step+j]=0;
99-
// cout<<"P3 "<<points.size()<<endl;
95+
ptr[i*elem_step+j]=0; //we put the value to zero for the pixel not to be detected again by the algorithm /!\ This is changing the output image /!\
10096
10197
unsigned int _i=i, _j=j;
102-
while(current_partial<partial_count)
98+
while(current_partial<partial_count)
10399
{
104-
105-
// cout<<partial_count<<" count="<<count<<" current_partial="<<current_partial<<" partial count="<<partial_count<<" point size="<<points.size()<<endl;
106-
// test(0);
107100
_i=points[count].x_pixels.at(current_partial);
108101
_j=points[count].y_pixels.at(current_partial);
109-
// test(1);
110102

111103
if (_i<height-1 && _j < width-1 && _j>1)
112104
{
@@ -126,15 +118,13 @@ void find_particules(cv::Mat & input, int frame, vector <Points> & points)
126118

127119
if (ptr[(_i+1) * elem_step + _j]!=0)
128120
{
129-
//cout<<"salut3"<<endl;
130121
points[count].add_pixel(_i+1,_j);
131122
ptr[(_i+1) * elem_step + _j]=0;
132123
partial_count++;
133124
}
134125

135126
if (ptr[(_i+1) * elem_step + _j+1]!=0)
136127
{
137-
//cout<<"salut4"<<endl;
138128
points[count].add_pixel(_i+1,_j+1);
139129
ptr[(_i+1) * elem_step + _j+1]=0;
140130
partial_count++;

0 commit comments

Comments
 (0)