# convert this program

2 messages
Open this post in threaded view
|
Report Content as Inappropriate

## convert this program

 that's emmergency , how can i convert this c opencv program to cuda program??? and thanks for all the replies in davance .        /*Function to calculate the integral P features */    IplImage** calculateintegralp(IplImage** ifeatures)  {  /* Create an array of 6 images ( note the dimensions of the image,  the cvIntegral() function requires the size to be that), to store the P integral images  calculated from the p images. These 6 integral images together constitute the P tensor */    IplImage** pintegrals = (IplImage**) malloc(6 * sizeof(IplImage*));  for (int j = 0; j < 6 ; j++)  {   pintegrals[j] = cvCreateImage(cvSize(ifeatures[0]->width + 1, ifeatures[0]->height + 1),IPL_DEPTH_64F,1);  }    for (int k = 0; k <6 ; k++){    cvIntegral(ifeatures[k], pintegrals[k]);  }    cvWaitKey( 0 );    return (pintegrals);  }                /* Function to calculate P_cell: */  void calculateP_rect(CvRect cell, CvMat* P_cell, IplImage** pintegrals)  {  /*The following function takes as input the rectangular cell for which the P tensor  has to be calculated, a matrix P_cell  of dimensions 1x6 to store the vector values for the P tensor,  */    /* Calculate the vector values for the P tensor one by one */    for (int i = 0; i < 6 ; i++){  //int i = 1;  float a =((double*)(pintegrals[i]->imageData + (cell.y ) * (pintegrals[i]->widthStep)))[cell.x ]; // si on met (float*) ca donne des fausses valeurs !!  float b = ((double*) (pintegrals[i]->imageData + (cell.y + cell.height-1) * (pintegrals[i]->widthStep)))[cell.x + cell.width - 1]; //jarrreb [cell.x + cell.width-1]  float c = ((double*) (pintegrals[i]->imageData + (cell.y ) * (pintegrals[i]->widthStep)))[cell.x + cell.width - 1];  float d = ((double*) (pintegrals[i]->imageData + (cell.y + cell.height - 1) * (pintegrals[i]->widthStep)))[cell.x ];       ((float*) P_cell->data.fl)[i] = (a + b) - (c + d);   // *( (float*)CV_MAT_ELEM_PTR( *P_cell, 0, i ) )= (a + b) - (c + d);    }  //cvSave("P_cell_init.xml", P_cell);  }            /*Function to calculate the integral Q features */  IplImage** calculateintegralq(IplImage** ifeatures)  {    /* Create an array of 21 images, one for each Q feature .  These Q features images will be then  used to calculate the Q integral images, which will quicken the calculation of covarience matrices descriptors */    IplImage** qfeatures = (IplImage**) malloc(21 * sizeof(IplImage*));  for (int i = 0; i < 21 ; i++)  {  qfeatures[i] = cvCreateImage(cvGetSize(ifeatures[0]),IPL_DEPTH_32F,1);  }    int l=0;  for (int m = 0; m < 6 ; m++)  {  for (int n = 0; n <= m; n++)  {  cvMul(ifeatures[m],ifeatures[n],qfeatures[l]); //lower side (!! cvMul: multiplication element par elemnet)// on va avoir 36 elements  l++;  }  }        /* Create an array of 21 images ( note the dimensions of the image,  the cvIntegral() function requires the size to be that), to store the Q integral images  calculated from the Q features images . These 21 integral images together constitute the Q tensor */    IplImage** qintegrals = (IplImage**) malloc(21 * sizeof(IplImage*));  for (int j = 0; j < 21 ; j++)  {  qintegrals[j] = cvCreateImage(cvSize(ifeatures[0]->width + 1, ifeatures[0]->height + 1),IPL_DEPTH_64F,1);  }    for (int k = 0; k <21 ; k++){  cvIntegral(qfeatures[k], qintegrals[k]);  }      //cvSave("qintegral0.xml", qintegrals[0]);  //cvSave("qintegral1.xml", qintegrals[1]);    cvWaitKey( 0 );  return (qintegrals);  }            /*Function to calculate Q_cell */  void calculateQ_rect(CvRect cell, CvMat* Q_cell, IplImage** qintegrals) //Q_cell_int  {  /* The following function takes as input the rectangular cell for which the Q tensor  has to be calculated, a matrix Q_cell  of dimensions 6x6 to store the vector values for the Q tensor,  */    /* Calculate the vector values for the Q tensor one by one */    CvMat* Q_cell_int = cvCreateMat(1,21,CV_32FC1);    for (int i = 0; i < 21 ; i++){    float a =((double*)(qintegrals[i]->imageData + (cell.y)    * (qintegrals[i]->widthStep)))[cell.x];  float b = ((double*) (qintegrals[i]->imageData + (cell.y + cell.height - 1)  * (qintegrals[i]->widthStep)))[cell.x + cell.width - 1];  float c = ((double*) (qintegrals[i]->imageData + (cell.y)  * (qintegrals[i]->widthStep)))[cell.x + cell.width - 1];  float d = ((double*) (qintegrals[i]->imageData + (cell.y + cell.height - 1)  * (qintegrals[i]->widthStep)))[cell.x];    //((float*) Q_cell_int->data.fl)[i] = (a + b) - (c + d);    *( (float*)CV_MAT_ELEM_PTR( *Q_cell_int, 0, i ) )= (a + b) - (c + d);  }    //conversion from 1*21 to 6*6 :                //elements in lower triangle:  int l=0;  for (int i = 0; i < 6; i++)    {  for (int j = 0; j <= i; j++)   {   *((float*)CV_MAT_ELEM_PTR(*Q_cell,i,j)) = *((float*)CV_MAT_ELEM_PTR(*Q_cell_int,0,l));// ????  l++;     }    }    //duplicate symmetric elements in upper triangle  for (int m=0; m<6; m++)  {  for(int n=5; n > m; n--)  {     *((float*)CV_MAT_ELEM_PTR(*Q_cell,m,n)) = *((float*)CV_MAT_ELEM_PTR(*Q_cell,n,m));  }  //cvSave("Q_cell_init.xml", Q_cell);      }    }              /* fuctuion to calculate covariance feature for a block*/    /*This function takes in a block as a rectangle and  calculates the P and Q  for the block by dividing  it into cells of size cell(the supplied parameter),  calculating the P and Q tensor for each cell using the  functions calculateP_rect(...)and calculateQ_rect(...), summing the so  obtained vectors for each cell to obtain the covariance feature for a block */    void calculatecov_block(CvRect block, CvMat* cov_block,  IplImage** pintegrals,IplImage** qintegrals,CvSize cell)  {  int cell_start_x, cell_start_y;  int startrow = 0;  int startcol = 0;  double s = block.width * block.height;//(==16*16=256)  double s1 = -(1/s);  double s2 = 1/(s-1);   CvMat* P_block = cvCreateMat(1,6,CV_32FC1);   cvSetZero(P_block);   CvMat* Q_block = cvCreateMat(6,6,CV_32FC1);   cvSetZero(Q_block);   CvMat* pvector_cell = cvCreateMat(1,6,CV_32FC1);   CvMat* qvector_cell = cvCreateMat(6,6,CV_32FC1);   CvMat* P_int = cvCreateMat(6,6,CV_32FC1);   CvMat* cov_block_int= cvCreateMat(6,6,CV_32FC1);   CvMat* cov_block_int2= cvCreateMat(6,6,CV_32FC1);   CvMat* UT= cvCreateMat(6,6,CV_32FC1);   CvMat* Ev = cvCreateMat(6,1,CV_32FC1);   CvMat* D= cvCreateMat(6,6,CV_32FC1);   CvMat* LOG_Ev= cvCreateMat(6,1,CV_32FC1);   CvMat* cov_block1= cvCreateMat(6,6,CV_32FC1);   CvMat* cov_block2= cvCreateMat(6,6,CV_32FC1);      for (cell_start_y = block.y; cell_start_y <=        block.y + block.height - cell.height;        cell_start_y += cell.height)   {  for (cell_start_x = block.x; cell_start_x <=           block.x + block.width - cell.width;           cell_start_x += cell.width)      {           cvSetZero(pvector_cell);      cvSetZero(qvector_cell);// enlever tt les éléments dans la matrice qui ont les memems valeurs     calculateP_rect(cvRect(cell_start_x,        cell_start_y, cell.width, cell.height),        pvector_cell, pintegrals);     cvAdd(P_block, pvector_cell, P_block);         calculateQ_rect(cvRect(cell_start_x,        cell_start_y, cell.width, cell.height),        qvector_cell, qintegrals);          cvAdd(Q_block, qvector_cell, Q_block);        }//????    }  //cvSave("P_block.xml", P_block);  //cvSave("Q_block.xml", Q_block);          //// cov_block=1/(s-1)*[Q_block -(1/s)* P_block . P_block_T] , where s = number of pixels inside the block B    //-(1/s)* P_block . P_block_T :  cvGEMM(P_block, P_block, s1, NULL, 0, P_int, CV_GEMM_A_T); //s1=-1/s .//????(a matrix transform)     //cvSave("P_block_int.xml", P_int);       cvAdd(Q_block, P_int, cov_block_int);     //cvSave("cov_block_int.xml", cov_block_int);       cvScale(cov_block_int, cov_block_int2,s2);  //s2=1/s-1     //cvConvertScale(cov_block_int, cov_block_int2,s2);               cvEigenVV(cov_block_int2,UT,Ev); //UT contient les vecteurs propres sous la forme de lignes successives./* Finds eigen values and vectors of a symmetric matrix */     //cvSave("UT.xml", UT);    // cvSave("Ev.xml", Ev);//Ev est un vecteur colonne qui contient les valeurs propres         cvSetZero(D);     cvLog(Ev,LOG_Ev);   //cvSave("LOG_Ev.xml", LOG_Ev);    for (int p = 0; p < 6; p++)    {  *((float*)CV_MAT_ELEM_PTR(*D,p,p)) = *((float*)CV_MAT_ELEM_PTR(*LOG_Ev,p,0)); //Log(D)=Log(Ev)    }         //cvSave("D.xml", D);  //(logId (X) = log(X) = U.log(D).UT )     cvGEMM(UT, D, 1, NULL, 0, cov_block1, CV_GEMM_A_T);   //cvSave("cov_block1.xml", cov_block1);   cvGEMM( cov_block1, UT, 1, NULL, 0, cov_block2);    //cvSave("cov_block2.xml", cov_block2);     //conversion de Mat 6*6 à une Mat 1*21:  int r=0;  for (int q = 0; q < 6; q++)    {   *((float*)CV_MAT_ELEM_PTR(*cov_block,r,q)) = *((float*)CV_MAT_ELEM_PTR(*cov_block2,r,q));    }    int r1=1;    for (int q1 = 0; q1 < 5; q1++)    {       *((float*)CV_MAT_ELEM_PTR(*cov_block,r,q1 + 6)) = *((float*)CV_MAT_ELEM_PTR(*cov_block2,r1,q1 + 1));    }    int r2=2;  for (int q2 = 0; q2 < 4; q2++)    {   *((float*)CV_MAT_ELEM_PTR(*cov_block,r,q2 + 11)) = *((float*)CV_MAT_ELEM_PTR(*cov_block2,r2,q2 + 2));    }    int r3=3;  for (int q3 = 0; q3 < 3; q3++)    {   *((float*)CV_MAT_ELEM_PTR(*cov_block,r,q3 + 15)) = *((float*)CV_MAT_ELEM_PTR(*cov_block2,r3,q3 + 3));    }    int r4=4;  for (int q4 = 0; q4 < 2; q4++)    {   *((float*)CV_MAT_ELEM_PTR(*cov_block,r,q4 + 18)) = *((float*)CV_MAT_ELEM_PTR(*cov_block2,r4,q4 + 4));    }    *((float*)CV_MAT_ELEM_PTR(*cov_block,r,20)) = *((float*)CV_MAT_ELEM_PTR(*cov_block2,5,5));// ????    //cvSave("cov_block.xml", cov_block);      }