PABOD_EXPORT float makeDetection (CvMat **results, IplImage *img, Model * model, float thresh, double iouNms) { CvMat *dets = NULL; CvMat *boxes = NULL; CvMatND *info = NULL; if (thresh == POSITIVE_INF) thresh = (float)model->getThresh(); bool found = imgDetect (img, model, thresh, NULL, NEGATIVE_INF, &dets, &boxes, &info); int detected = 0; if (found) { int *pick; int pickDim; nms (&pick, &pickDim, dets, iouNms); (*results) = cvCreateMat (pickDim, 6, CV_32FC1); for (int i = 0; i < pickDim; i++) { cvSetReal2D ((*results), i, 0, cvGetReal2D (dets, pick[i], 0)); cvSetReal2D ((*results), i, 1, cvGetReal2D (dets, pick[i], 1)); cvSetReal2D ((*results), i, 2, cvGetReal2D (dets, pick[i], 2)); cvSetReal2D ((*results), i, 3, cvGetReal2D (dets, pick[i], 3)); //cout << cvGetReal2D (dets, pick[i], 4) << "+ " << cvGetReal2D (dets, pick[i], 5) << " |"; cvSetReal2D ((*results), i, 4, cvGetReal2D (dets, pick[i], 5)); cvSetReal2D ((*results), i, 5, cvGetReal2D (dets, pick[i], 4)); } detected = pickDim; delete[] pick; } else (*results) = NULL; if (dets != NULL) { cvReleaseMat(&dets); dets = NULL; } if (boxes != NULL) { cvReleaseMat(&boxes); boxes = NULL; } if (info != NULL) { cvReleaseMatND(&info); info = NULL; } return thresh; }
int main(int argc, char * argv[]) { typedef struct {char buffer[512];char fn[256];float x,y,w,h;} CvTrainData; char imagelistfn[2][256]; sprintf(imagelistfn[0],"../dataset/palm/open.txt"); sprintf(imagelistfn[1],"../dataset/palm/close.txt"); char featurefn[2][256]; sprintf(featurefn[0],"../data/open.bin"); sprintf(featurefn[1],"../data/close.bin"); int statusiter=0; for (statusiter=0;statusiter<2;statusiter++) { int i,j,N; CvTrainData dat[MAX_SAMPLES]; { FILE * fp = fopen(imagelistfn[statusiter], "r"); for (i=0;i<MAX_SAMPLES;i++) { fgets(dat[i].buffer,512,fp); if (dat[i].buffer[0]=='-'){break;} if (dat[i].buffer[0]=='#'){i--;continue;} sscanf(dat[i].buffer, "%s %f %f %f %f\n", dat[i].fn,&dat[i].x,&dat[i].y,&dat[i].w,&dat[i].h); #if WITH_TZG dat[i].x=dat[i].x+cvRound(dat[i].w*.15); dat[i].y=dat[i].y+cvRound(dat[i].h*.15); dat[i].w=cvRound(dat[i].w*.7); dat[i].h=cvRound(dat[i].h*.7); #endif } fprintf(stderr, "INFO: %d training dat collected!\n", i); fclose(fp); } N=i; float * hogfts_data = new float[378*MAX_SAMPLES]; CvMat hogfts = cvMat(MAX_SAMPLES,378,CV_32F,hogfts_data); int hogsizes[]={7,6,9}; int hogszprod = hogsizes[0]*hogsizes[1]*hogsizes[2]; for (i=0;i<N;i++) { IplImage * img = cvLoadImage(dat[i].fn,0); CvMat mat_stub; CvMat * mat = cvGetMat(img,&mat_stub); CvMatND * hog = cvCreateMatND(3,hogsizes,CV_32F); int nr=mat->rows,nc=mat->cols; CvMat * dx = cvCreateMat(nr,nc,CV_16S); CvMat * dy = cvCreateMat(nr,nc,CV_16S); CvMat * magni = cvCreateMat(nr,nc,CV_32F); cvZero(magni); CvMat * angle = cvCreateMat(nr,nc,CV_32F); cvZero(angle); float warp_p_data[]={dat[i].w/36.,dat[i].x-3.,dat[i].y-3.}; CvMat warp_p = cvMat(3,1,CV_32F,warp_p_data); // cvSobel(img,dx,1,0,1); // cvSobel(img,dy,0,1,1); cvPrepareGradientROI(mat, dx, dy, warp_p_data[0], cvRect(dat[i].x,dat[i].y,dat[i].w,dat[i].h)); cvSet(magni,cvScalar(-1)); icvCalcWarpHOG(mat,&warp_p,hog,6,2,dx,dy,magni,angle); // for (j=0;j<hogszprod;j++){ fprintf(stderr, "%ff,", hog->data.fl[j]); } // icvShowHOG(hog); CV_WAIT(); memcpy(hogfts_data+378*i,hog->data.fl,sizeof(float)*378); // icvShowHOG(hog); CV_WAIT(); // fprintf(stderr, "scale: %f\n", warp_p_data[0]); if (argc>1) { if (!strcmp(argv[1],"-show")){ // fprintf(stderr, "INFO: file %s loaded!\n", dat[i].fn); cvRectangle(mat,cvPoint(dat[i].x,dat[i].y), cvPoint(dat[i].x+dat[i].w,dat[i].y+dat[i].h),CV_RED); fprintf(stderr, "INFO: display %s\n",dat[i].fn); CV_SHOW(mat); } } // CV_SHOW(magni); // CV_SHOW(angle); cvReleaseMat(&dx); cvReleaseMat(&dy); cvReleaseMat(&magni); cvReleaseMat(&angle); cvReleaseMatND(&hog); } { FILE * fp=fopen(featurefn[statusiter],"w"); fwrite(hogfts_data,4,378*i,fp); fclose(fp); } delete [] hogfts_data; } return 0; }
HoughAccumulator::~HoughAccumulator() { // cvReleaseSparseMat(&acc); cvReleaseMatND(&acc); delete[] indices; }
void cvReleaseMatND_wrap(CvMatND * * mat ){ cvReleaseMatND(/*CvMatND*//***//***/mat); }