double CalcVectorDist( CvMat *target, CvMat *query ) { // use histogram intersection on each block // then fuse them in score level, with the weight of subspace dim of each block. double score = 0; if (! g_bNoWeights) { CvMat subT, subQ; int prjCnt = 0; for (int i = 0; i < g_blkCnt; i++) { cvGetRows(target, &subT, prjCnt, prjCnt+g_blkInputDim); cvGetRows(query, &subQ, prjCnt, prjCnt+g_blkInputDim); prjCnt += g_blkInputDim; cvMin(&subT,&subQ, g_tm); score += (cvSum(g_tm).val[0] * g_blkWeights[i]); } } else { cvMin(target,query, g_tm); score = +cvSum(g_tm).val[0]; } double normSum = cvSum(target).val[0]; //double norm1Sum = cvSum(query).val[0]; score /= normSum; return 1-score; }
void RGBThresholdFilter::mask_threshold(IplImage *src, IplImage *dst){ IplImage *tmp1, *tmp2; StorageObject *so_rgb_c1 = getStorageObject(std::string("rgb_c1")); IplImage *c1 = (IplImage*)so_rgb_c1->data; StorageObject *so_rgb_c2 = getStorageObject(std::string("rgb_c2")); IplImage *c2 = (IplImage*)so_rgb_c2->data; StorageObject *so_rgb_c3 = getStorageObject(std::string("rgb_c3")); IplImage *c3 = (IplImage*)so_rgb_c3->data; tmp1 = cvCreateImage(cvSize(c1->width, c1->height), src->depth, 1); //tmp2 = cvCreateImage(cvSize(dst->width, dst->height), src->depth, 1); cvZero(tmp1); cvZero(dst); cvMin(c1, c2, c2); cvMin(c2, c3, tmp1); //cvResize(tmp1, tmp2); cvCopy(src, dst, tmp1); cvReleaseImage(&tmp1); //cvReleaseImage(&tmp2); cvReleaseImage(&c1); so_rgb_c1->data = 0; cvReleaseImage(&c2); so_rgb_c2->data = 0; cvReleaseImage(&c3); so_rgb_c3->data = 0; }
/** * \brief Takes frame and applies image processing techniques to filter out non-laser line points. Updates images used for runtime display. */ int filterFrame() { args[0] = frame; cvCvtColor(frame, frameHSV, CV_BGR2HSV); //convert RGB values of frame to HSV and place in frameHSV cvSplit(frameHSV, hue, saturation, value, NULL); //split frameHSV into constituent components and place appropriately; we are done with frameHSV args[1] = hue; args[2] = value; cvCopy(saturation, saturation2); //make an additional copy of saturation for display //args[8] = saturation2; //cvShowImage("saturation", saturation2); cvSmooth(frame, frameHSV, CV_BLUR, 20, 20 ); //smooth frame and store in frameHSV //cvShowImage("Smoothed frame", frameHSV); cvSplit(frame, blue, green, red, NULL); //split frame into its RGB components cvSplit(frameHSV, blue2, green2, red2, NULL); //split the smoothed version into its RGB components cvMin(blue, green, min_bg); //take the min of blue and green and store in min_bg args[3] = min_bg; //cvShowImage("minimum of blue and green", min_bg); cvSub(red, min_bg, red_last); //take red less the min of the blue and green //cvShowImage("red_last = red - min_bg", red_last); cvThreshold(red_last, red_last, thresholdValue, 255, CV_THRESH_BINARY_INV); //threshold the red_last //cvShowImage("threshold of red_last", red_last); args[4] = red_last; cvSub(red, red2, deltaRed); //cvShowImage("deltaRed = Original red - smooth red", deltaRed); cvThreshold(deltaRed, deltaRed, thresholdValue, 255, CV_THRESH_BINARY); //cvShowImage("threshold(deltaRed)", deltaRed); cvCopy(deltaRed, alpha); cvInRangeS(saturation, cvScalar(0), cvScalar(25), saturation); //cvShowImage("Low saturation in original frame", saturation); cvInRangeS(hue, cvScalar(49), cvScalar(125), beta); //cvShowImage("Mixed hue in original frame", beta); cvOr(beta, saturation, beta); //cvShowImage("beta = Low saturation OR mixed hue", beta); cvOr(beta, red_last, beta); //cvShowImage("beta = beta OR red_last", beta); //args[5] = alpha; args[5] = beta; IplConvKernel*mask= cvCreateStructuringElementEx(5, 5, 2, 2, 2, NULL ); cvDilate(saturation2,dialated, mask, 20); //cvShowImage("dilate original saturation", dialated); args[6] = dialated; cvThreshold(dialated, dialated, 100, 255, CV_THRESH_BINARY); cvErode(dialated,eroded, mask, 30); args[7] = eroded; cvSub(alpha, beta, orig_filter); args[8] = orig_filter; cvAnd(orig_filter, eroded, zeta); args[9] = zeta; return 0; }
//形态学测地膨胀和膨胀重建运算 void lhMorpRDilate(const IplImage* src, const IplImage* msk, IplImage* dst, IplConvKernel* se = NULL, int iterations=-1) { assert(src != NULL && msk != NULL && dst != NULL && src != dst ); if(iterations < 0) { //膨胀重建 cvMin(src, msk, dst); cvDilate(dst, dst, se); cvMin(dst, msk, dst); IplImage* temp1 = cvCreateImage(cvGetSize(src), 8, 1); //IplImage* temp2 = cvCreateImage(cvGetSize(src), 8, 1); do { //record last result cvCopy(dst, temp1); cvDilate(dst, dst, se); cvMin(dst, msk, dst); //cvCmp(temp1, dst, temp2, CV_CMP_NE ); } //while(cvSum(temp2).val[0] != 0); while(lhImageCmp(temp1, dst)!= 0); cvReleaseImage(&temp1); //cvReleaseImage(&temp2); return; } else if (iterations == 0) { cvCopy(src, dst); } else { //普通测地膨胀 p136(6.1) cvMin(src, msk, dst); cvDilate(dst, dst, se); cvMin(dst, msk, dst); for(int i=1; i<iterations; i++) { cvDilate(dst, dst, se); cvMin(dst, msk, dst); } } }
void Utils::geoDilate(IplImage* src, IplImage* mask, IplImage* dst) { cvDilate(src, dst); cvMin(dst, mask, dst); }