static void cvTsCalcBackProjectPatch( IplImage** images, IplImage* dst, CvSize patch_size, CvHistogram* hist, int method, double factor, int* channels ) { CvHistogram* model = 0; IplImage imgstub[CV_MAX_DIM], *img[CV_MAX_DIM]; IplROI roi; int i, dims; int x, y; CvSize size = cvGetSize(dst); dims = cvGetDims( hist->bins ); cvCopyHist( hist, &model ); cvNormalizeHist( hist, factor ); cvZero( dst ); for( i = 0; i < dims; i++ ) { CvMat stub, *mat; mat = cvGetMat( images[i], &stub, 0, 0 ); img[i] = cvGetImage( mat, &imgstub[i] ); img[i]->roi = &roi; } roi.coi = 0; for( y = 0; y < size.height; y++ ) { for( x = 0; x < size.width; x++ ) { double result; roi.xOffset = x; roi.yOffset = y; roi.width = patch_size.width; roi.height = patch_size.height; cvTsCalcHist( img, model, 0, channels ); cvNormalizeHist( model, factor ); result = cvCompareHist( model, hist, method ); CV_IMAGE_ELEM( dst, float, y, x ) = (float)result; } } cvReleaseHist( &model ); }
Histogram::Histogram(const Histogram& hist) { cvCopyHist(hist.m_histogram, &m_histogram); }
Histogram* Histogram::copy() const { Histogram* hist = new Histogram(); cvCopyHist(m_histogram, &(hist->m_histogram)); return hist; }
static GstFlowReturn kms_pointer_detector_transform_frame_ip (GstVideoFilter * filter, GstVideoFrame * frame) { KmsPointerDetector *pointerdetector = KMS_POINTER_DETECTOR (filter); GstMapInfo info; double min_Bhattacharyya = 1.0, bhattacharyya = 1, bhattacharyya2 = 1, bhattacharyya3 = 1; int i = 0; pointerdetector->frameSize = cvSize (frame->info.width, frame->info.height); kms_pointer_detector_initialize_images (pointerdetector, frame); gst_buffer_map (frame->buffer, &info, GST_MAP_READ); pointerdetector->cvImage->imageData = (char *) info.data; if ((pointerdetector->iteration > FRAMES_TO_RESET) && (pointerdetector->state != CAPTURING_SECOND_HIST)) { get_histogram (pointerdetector->cvImage, pointerdetector->upCornerRect1, pointerdetector->trackinRectSize, pointerdetector->histSetUpRef); pointerdetector->histRefCapturesCounter = 0; pointerdetector->secondHistCapturesCounter = 0; pointerdetector->state = CAPTURING_REF_HIST; pointerdetector->colorRect1 = WHITE; pointerdetector->colorRect2 = WHITE; pointerdetector->iteration = 6; } if (pointerdetector->iteration == 5) { get_histogram (pointerdetector->cvImage, pointerdetector->upCornerRect1, pointerdetector->trackinRectSize, pointerdetector->histSetUpRef); pointerdetector->state = CAPTURING_REF_HIST; goto end; } if (pointerdetector->iteration < 6) goto end; get_histogram (pointerdetector->cvImage, pointerdetector->upCornerRect1, pointerdetector->trackinRectSize, pointerdetector->histSetUp1); bhattacharyya2 = cvCompareHist (pointerdetector->histSetUp1, pointerdetector->histSetUpRef, CV_COMP_BHATTACHARYYA); if ((bhattacharyya2 >= COMPARE_THRESH_SECOND_HIST) && (pointerdetector->state == CAPTURING_REF_HIST)) { pointerdetector->histRefCapturesCounter++; if (pointerdetector->histRefCapturesCounter > 20) { pointerdetector->histRefCapturesCounter = 0; pointerdetector->colorRect1 = CV_RGB (0, 255, 0); pointerdetector->state = CAPTURING_SECOND_HIST; } } if (pointerdetector->state == CAPTURING_SECOND_HIST) { get_histogram (pointerdetector->cvImage, pointerdetector->upCornerRect2, pointerdetector->trackinRectSize, pointerdetector->histSetUp2); bhattacharyya3 = cvCompareHist (pointerdetector->histSetUp1, pointerdetector->histSetUp2, CV_COMP_BHATTACHARYYA); if (bhattacharyya3 < COMPARE_THRESH_2_RECT) { pointerdetector->secondHistCapturesCounter++; if (pointerdetector->secondHistCapturesCounter > 15) { pointerdetector->secondHistCapturesCounter = 0; pointerdetector->state = BOTH_HIST_SIMILAR; pointerdetector->colorRect2 = CV_RGB (0, 255, 0); cvCopyHist (pointerdetector->histSetUp2, &pointerdetector->histModel); pointerdetector->upCornerFinalRect.x = 10; pointerdetector->upCornerFinalRect.y = 10; pointerdetector->histRefCapturesCounter = 0; pointerdetector->secondHistCapturesCounter = 0; } } } for (i = 0; i < pointerdetector->numOfRegions; i++) { int horizOffset = pointerdetector->upCornerFinalRect.x + pointerdetector->windowScale * (rand () % pointerdetector->trackinRectSize.width - pointerdetector->trackinRectSize.width / 2); int vertOffset = pointerdetector->upCornerFinalRect.y + pointerdetector->windowScale * (rand () % pointerdetector->trackinRectSize.height - pointerdetector->trackinRectSize.height / 2); pointerdetector->trackingPoint1Aux.x = horizOffset; pointerdetector->trackingPoint1Aux.y = vertOffset; pointerdetector->trackingPoint2Aux.x = horizOffset + pointerdetector->trackinRectSize.width; pointerdetector->trackingPoint2Aux.y = vertOffset + pointerdetector->trackinRectSize.height; if ((horizOffset > 0) && (pointerdetector->trackingPoint2Aux.x < pointerdetector->cvImage->width) && (vertOffset > 0) && (pointerdetector->trackingPoint2Aux.y < pointerdetector->cvImage->height)) { if (pointerdetector->show_debug_info) cvRectangle (pointerdetector->cvImage, pointerdetector->trackingPoint1Aux, pointerdetector->trackingPoint2Aux, CV_RGB (0, 255, 0), 1, 8, 0); cvSetImageROI (pointerdetector->cvImage, cvRect (pointerdetector->trackingPoint1Aux.x, pointerdetector->trackingPoint1Aux.y, pointerdetector->trackinRectSize.width, pointerdetector->trackinRectSize.height)); cvCopy (pointerdetector->cvImage, pointerdetector->cvImageAux1, 0); cvResetImageROI (pointerdetector->cvImage); calc_histogram (pointerdetector->cvImageAux1, pointerdetector->histCompare); bhattacharyya = cvCompareHist (pointerdetector->histModel, pointerdetector->histCompare, CV_COMP_BHATTACHARYYA); if ((bhattacharyya < min_Bhattacharyya) && (bhattacharyya < COMPARE_THRESH_HIST_REF)) { min_Bhattacharyya = bhattacharyya; pointerdetector->trackingPoint1 = pointerdetector->trackingPoint1Aux; pointerdetector->trackingPoint2 = pointerdetector->trackingPoint2Aux; } } } cvRectangle (pointerdetector->cvImage, pointerdetector->upCornerRect1, pointerdetector->downCornerRect1, pointerdetector->colorRect1, 1, 8, 0); cvRectangle (pointerdetector->cvImage, pointerdetector->upCornerRect2, pointerdetector->downCornerRect2, pointerdetector->colorRect2, 1, 8, 0); if (min_Bhattacharyya < 0.95) { pointerdetector->windowScale = pointerdetector->windowScaleRef; } else { pointerdetector->windowScale = pointerdetector->cvImage->width / 8; } CvPoint finalPointerPositionAux; finalPointerPositionAux.x = pointerdetector->upCornerFinalRect.x + pointerdetector->trackinRectSize.width / 2; finalPointerPositionAux.y = pointerdetector->upCornerFinalRect.y + pointerdetector->trackinRectSize.height / 2; if (abs (pointerdetector->finalPointerPosition.x - finalPointerPositionAux.x) < 55 || abs (pointerdetector->finalPointerPosition.y - finalPointerPositionAux.y) < 55) { finalPointerPositionAux.x = (finalPointerPositionAux.x + pointerdetector->finalPointerPosition.x) / 2; finalPointerPositionAux.y = (finalPointerPositionAux.y + pointerdetector->finalPointerPosition.y) / 2; } pointerdetector->upCornerFinalRect = pointerdetector->trackingPoint1; pointerdetector->downCornerFinalRect = pointerdetector->trackingPoint2; pointerdetector->finalPointerPosition.x = finalPointerPositionAux.x; pointerdetector->finalPointerPosition.y = finalPointerPositionAux.y; cvCircle (pointerdetector->cvImage, pointerdetector->finalPointerPosition, 10.0, WHITE, -1, 8, 0); kms_pointer_detector_check_pointer_position (pointerdetector); end: pointerdetector->iteration++; gst_buffer_unmap (frame->buffer, &info); return GST_FLOW_OK; }
// ------------------------------------------------------------------------ LABHistogram2D& LABHistogram2D::operator=(const LABHistogram2D& that) { cvCopyHist(that.h, &this->h); return *this; }
// ------------------------------------------------------------------------ LABHistogram2D::LABHistogram2D(const LABHistogram2D& that) { cvCopyHist(that.h, &this->h); }
/* bool FeatureHistogram::eval(ImageRepresentation* image, Rect ROI, float* result) { *result = -1.0f; if(initflag)//cap nhat lan dau { if(!image->getimcolor()) { initflag=false; return false; } *result=cvCompareHist(ref_histos,image->getimcolor(),CV_COMP_CORREL); } else //lan dau la cap nhat hsv { if(!image->getimcolor()) { initflag=false; return false; } initflag=true; //khoi tao lai *result = 1.0f; //ket qua cao nhat ref_histos=copyhistogram(image->getimcolor()); } return true; } */ CvHistogram* copyhistogram3(CvHistogram*t) { CvHistogram*tt=NULL; cvCopyHist(t,&tt); return tt; }