二重の値の配列を作成していますが、作成した配列をCvSeqに追加します。私はこの目的のためにcvSeqPushを使用しました。しかし、私はこの配列を取得するときに配列の最初の要素のみを表示し、残りは不要です。次のようにコードは、私は、問題がどこにあるか誰が私に教えCV_GET_SEQ_ELEM.Can使用していますどこに問題が行で発生..CvSeqに配列を追加する方法と配列を取得する方法
int Ts = 45;
int count = 0;
//Creating a mtrix CL for clusters
CvMat * CL = cvCreateMat(1,newCP->cols,newCP->type);
//Array for storing the clusters
double * arrClust = (double*)malloc(3*sizeof(double));
//Copying 1st row of newCP to arrClust
arrClust[0] = cvmGet(newCP,0,0);
arrClust[1] = cvmGet(newCP,0,1);
arrClust[2] = cvmGet(newCP,0,2);
//array of distances
double * distance = (double*)malloc(1*sizeof(double));
//array of results
double * result = (double*)malloc(1*sizeof(double));
//Creating a seq to store various clusters
CvMemStorage * strgeClust = cvCreateMemStorage(0);
CvSeq * seqClust = cvCreateSeq(0,sizeof(CvSeq),sizeof(double),strgeClust);
CvSeq * s ;
for(int i=2 ; i<newCP->rows ; i++)
{
for(int j=0;j<=count;j++)
{
double a = arrClust[0] - cvmGet(newCP,i,0); //a = CL0-newCP0
double b = arrClust[1] - cvmGet(newCP,i,1); //b = CL1-newCP1
double c = arrClust[2] - cvmGet(newCP,i,2); //c = CL2-newCP2
double sum = (a*a)+(b*b)+(c*c); //(a^2 + b^2 + c^2)
double sqrtSum = sqrt(sum);
distance[j] = sqrtSum ;
if(distance[j]<=Ts)
result[j] = 0;
else
result[j] = 1;
}
//Checking for zero in result array
int isZero = 1;
for(int k =0;k<=count;k++)
{
if(result[k] == 0)
{
isZero =0;
break;
}
}
if(isZero!=0)
{
count = count+1;
cvSeqPush(seqClust,arrClust);
arrClust = (double*)malloc(3*sizeof(double));
arrClust[0] = cvmGet(newCP,i,0);
arrClust[1] = cvmGet(newCP,i,1);
arrClust[2] = cvmGet(newCP,i,2);
}
else
{
double minElement = fnSortForMin(distance,count+1); //Getting the minimum value from distance array
int index = fnSearchIndexOfMin(distance,minElement,count+1); //Getting the index of minElement
if(index == count)
{
arrClust[0] = (arrClust[0]+cvmGet(newCP,i,0))/2;
arrClust[1] = (arrClust[1]+cvmGet(newCP,i,1))/2;
arrClust[2] = (arrClust[2]+cvmGet(newCP,i,2))/2;
}
else
{
s = seqClust;
for(int i = 1;i<index;i++)
{
s = seqClust->h_next;
}
double * arr = CV_GET_SEQ_ELEM(double,s,index);
arr[0] = (arr[0]+cvmGet(newCP,i,0))/2;
arr[1] = (arr[1]+cvmGet(newCP,i,1))/2;
arr[2] = (arr[2]+cvmGet(newCP,i,2))/2;
}
}//End of outer If Block
}//End Of outer For loop
あります?
ご返信ありがとうございます。 私はCV_GET_SEQ_ELEMでいくつか修正しました。 実際には、配列の各要素に1バイト3次元の配列を1つ格納しています。シーケンスから一度に1つの配列を取り出して値を更新できるようにしたいのです。 配列が取得されていますが、残りの配列の最初の要素のみが取得されています.2つの値は不要です。 なぜそれは..? – ATG
あなたの助けをありがとう.. !!! – ATG