jeudi 19 mars 2015

how to sort vector of points based on X axis in opencv using c?


suppose i have two vectors. one contain data in ascending order(0,106),(0,107),(1,5),(1,6),(2,8).... another vector has points (0,2),(0,5),(0,106),(0,107),(0,108),(1,6),(2,1).....and so on.. I want output as (0,2),(0,5),(0,106),(0,107),(0,108),(1,5),(1,6),(2,1),(2,8). here the code:



float x1[1500],y1[1500],x2[1500],y2[1500];
float x3[2500],y3[2500];
int ik=0,kk=0;

int p1=0;

int j = 0;
k = 0;
int i=0;

for(int o=0;o<l+l1;)
{
if(i<l && j<l1)
{
if(x1[i]==x2[j])
{
if(y1[i]==y2[j])
{
x3[p1]=x1[i];

y3[p1]=y1[i];

p1++;
i++;
j++;
}

else if(y1[i]<y2[j])
{
x3[p1]=x1[i];
y3[p1]=y1[i];

p1++;
i++;}

else
{
x3[p1]=x2[j];
y3[p1]=y2[j];
fs1<<"=x3="<<x3[p1]<<" y3="<<y3[p1]<<endl;
p1++;
j++;}


}
else if(x1[i]<x2[j])
{
x3[p1]=x1[i];
y3[p1]=y1[i];

p1++;
i++;

}
else
{
x3[p1]=x2[j];
y3[p1]=y2[j];

p1++;
j++;

}o++;
}
if(i==l && j<l1)
{
x3[p1]=x2[j];
y3[p1]=y2[j];

p1++;
j++;
o++;
}


if(i<l && j==l1)
{
x3[p1]=x1[i];
y3[p1]=y1[i];
p1++;
i++;
o++;}

}


Thank you in advance




Aucun commentaire:

Enregistrer un commentaire