double pixelDistance_3d(const double *p_img, const int p, int q, const int n_channels, const int num_pixels, const int Img_height, const double sigma) { int p_x = p/Img_height; int p_y = p-p_x*Img_height; int q_x = q/Img_height; int q_y = q-q_x*Img_height; double distance = (p_x-q_x)*(p_x-q_x) + (p_y-q_y)*(p_y-q_y); //compute distance: double intensity_distance = 0; int i; double d; for(i=0; i<n_channels; i++) { d = pixelDistance(p_img+i*num_pixels, p, q, distance, sigma); if(d > intensity_distance) { intensity_distance = d; } } return intensity_distance; }
FkInt32S FkSilhDetector_PaintedFlies::segmentFrame(const IplImage *thisFrame) // I want to keep it void { FILE_LOG(logDEBUG1)<< "\nbegin of FkSilhDetector_PaintedFlies::segmentFrame"; if(m_isInited!=1) { FILE_LOG(logDEBUG1)<< "\nsilhDetector is not init"; return(FK_ERR_SILH_DETECT_IS_NOT_INIT); } CvPoint pt1, pt2; //this is for ROI, TODO: get this exposed pt1 = cvPoint(1,1); pt2 = cvPoint(thisFrame->width, thisFrame->height); //setting ROI the whole image cvZero(m_rawChangeMask); int i, j, minX,maxX,minY,maxY; minX = FK_MIN(pt1.x, pt2.x); maxX = FK_MAX(pt1.x, pt2.x); minY = FK_MIN(pt1.y, pt2.y); maxY = FK_MAX(pt1.y, pt2.y); #if __USE_OPENMP_FOR_SEGMENTATION #pragma omp parallel shared(i,j,maxX,maxY,minX,minY)//, thisFrame, m_bgModel, m_threshold, m_rawChangeMask) { #pragma omp for schedule(dynamic) #endif for(i= minY+1; i<maxY-1; ++i) //just look for silhouettes in ROI { for(j=minX+1; j<maxX-1; ++j) { if( pixelDistance( &UPIXEL(thisFrame, i, j, 0), &UPIXEL(m_bgModel, i, j, 0), 3 ) > -m_threshold ) { //for(int k = 0; k < m_bgModel->nChannels; ++k) //{ // //if (parentCamView->frameNum % 1000 == 0) // // UPIXEL(m_bgModel, i, j, k) = (unsigned char) (alpha * UPIXEL(thisFrame, i, j, k) + (1-alpha) * UPIXEL(m_bgModel, i, j, k)); //} } else { PIXEL(m_rawChangeMask,i, j, 0) |= 0xFF; } } } #if __USE_OPENMP_FOR_SEGMENTATION } #endif FILE_LOG(logDEBUG1)<< "\nEnd of FkSilhDetector_PaintedFlies::segmentFrame"; return (FK_OK); }
//#pragma acc routine seq void compFitness (const RGB *A, Individual *B, int width, int height) { int i, j; double f = 0; #define num threads j = width*height; RGB * ptr = B->image; #pragma acc data copyin(A[0:j], ptr[0:j]) #pragma acc loop reduction(+:f) vector #pragma omp parallel for reduction(+:f) firstprivate(A, B, j) private(i) for (i = 0; i < j; i++) f += pixelDistance(&A[i], &(ptr[i])); B->fitness = f; }
double pixelDistance_3d(const double *p_img, const int p, int q, const int n_channels, const int num_pixels) { double intensity_distance = 0; int i; double d; for(i=0; i<n_channels; i++) { d = pixelDistance(p_img+i*num_pixels, p, q); if(d > intensity_distance) { intensity_distance = d; } } return intensity_distance; }