Exemple #1
0
void prepareBuffer(IplImage* imgSrc,int iterTime)
{
    struct param par;
    par.iWidth  = imgSrc->width;
    par.iHeight = imgSrc->height;
    par.it      = iterTime;
    par.mean    = imgMean(imgSrc);
    par.q0      = imgQ0(imgSrc,par.mean);
    cl_int ret;
    cmPar = clCreateBuffer(cxGPUContext, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,sizeof(struct param),&par,&ret);
    openclRetTackle(ret,"clCreateBuffer const");
    
    int iStep       = imgSrc->widthStep;
    float* initMem  = (float*)malloc(sizeof(float) * par.iWidth * par.iHeight);
    memset(initMem,0,sizeof(float)* par.iWidth * par.iHeight);
    for(int i=0;i<imgSrc->height;i++)
    {
        for(int j=0;j<imgSrc->widthStep;j++)
        {
            initMem[i*par.iWidth+j]=(unsigned char)imgSrc->imageData[i*iStep+j];
        }
    }
    cmImgSrc = clCreateBuffer(cxGPUContext, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,sizeof(float) * par.iWidth * par.iHeight,initMem,&ret);
    openclRetTackle(ret,"clCreateBuffer cmImgSrc");
    cmImgDes = clCreateBuffer(cxGPUContext, CL_MEM_READ_WRITE, sizeof(float) * par.iWidth * par.iHeight,0,&ret);
    openclRetTackle(ret,"clCreateBuffer cmImgDes");
    cmCqM = clCreateBuffer(cxGPUContext, CL_MEM_READ_WRITE, sizeof(float) * par.iWidth * par.iHeight, 0, &ret);
    openclRetTackle(ret,"clCreateBuffer cmCqM");
}
 utils::Point CurvatureFeatureExtractor::computeMean(std::vector<int> &imgIDs, int w){
   std::vector<utils::Point> points = createPointsFromIDs(imgIDs, w);
   utils::Point imgMean(0,0);
   
   for(unsigned int i=0; i<points.size(); i++){
     imgMean.x+=points[i].x;
     imgMean.y+=points[i].y;
   }
   imgMean.x/=points.size();
   imgMean.y/=points.size();
   return imgMean;
 }