Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

histogram comparison

$
0
0
Hi at all! I must do an histogram comparison with a formula that computes the intersection of histograms. My histograms have 256 bins. How I realize this formula correctly? I 'm using this for object tracking with colors. enter code here ![image description](/upfiles/14522442339857565.jpg) Post below one my possible solution but I think that this not execute exactly the formula int const block = 768; Mat background = imread("Scene.jpg",CV_LOAD_IMAGE_COLOR);\\Scene1.jpg",CV_LOAD_IMAGE_COLOR); //bacground histograms Mat hB_b[block]; Mat hB_g[block]; Mat hB_r[block]; //currents histogram Mat hC_b[block]; Mat hC_g[block]; Mat hC_r[block]; float sum_bkg_b = 0; float sum_bkg_g = 0; float sum_bkg_r = 0; float summ_bkg_b[block]; float summ_bkg_g[block]; float summ_bkg_r[block]; for(int a=0; a<320; a+=10) { for(int b=0; b<240; b+=10) { Mat SUPPORT (background, Rect(a,b,10,10)); vector bgr_planes; split( SUPPORT, bgr_planes ); calcHist( &bgr_planes[0], 1, 0, Mat(), hB_b[count], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes[1], 1, 0, Mat(), hB_g[count], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes[2], 1, 0, Mat(), hB_r[count], 1, &histSize, &histRange, uniform, accumulate ); for(int b=0; b<256; b++) { sum_bkg_b = sum_bkg_b + hB_b[count].at(b); sum_bkg_g = sum_bkg_g + hB_g[count].at(b); sum_bkg_r = sum_bkg_b + hB_r[count].at(b); } summ_bkg_b[count] = sum_bkg_b; summ_bkg_g[count] = sum_bkg_g; summ_bkg_r[count] = sum_bkg_r; count++; } } Mat current = imread("Scene2.jpg",CV_LOAD_IMAGE_COLOR); for(int a=0; a<320; a+=10) { for(int b=0; b<240; b+=10) { Mat SUPPORT_2 (current, Rect(a,b,10,10)); ricostruzione[count_c] = SUPPORT_2.clone(); vector bgr_planes_c; split( SUPPORT_2, bgr_planes_c ); calcHist( &bgr_planes_c[0], 1, 0, Mat(), hC_b[count_c], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes_c[1], 1, 0, Mat(), hC_g[count_c], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes_c[2], 1, 0, Mat(), hC_r[count_c], 1, &histSize, &histRange, uniform, accumulate ); double f_intersect_b[block]; double f_intersect_g[block]; double f_intersect_r[block]; float min_Bb = 0; float min_Bg = 0; float min_Br = 0; float min_Cb = 0; float min_Cg = 0; float min_Cr = 0; float min_num_b = 0; float min_num_g = 0; float min_num_r = 0; float min_sum_b = 0; float min_sum_g = 0; float min_sum_r = 0; float pos_min_b = 0; float sum_min_b = 0; float pos_min_g = 0; float sum_min_g = 0; float pos_min_r = 0; float sum_min_r = 0; for (int t=0; t(u) <= hC_b[t].at(u)) pos_min_b = hB_b[t].at(u); else pos_min_b = hC_b[t].at(u); sum_min_b += pos_min_b; //intersect formula (GREEN)************************************************* if (hB_g[t].at(u) <= hC_g[t].at(u)) pos_min_g = hB_g[t].at(u); else pos_min_g = hC_g[t].at(u); sum_min_g += pos_min_g; //intersect formula (RED)*************************************************** if (hB_r[t].at(u) <= hC_r[t].at(u)) pos_min_r = hB_r[t].at(u); else pos_min_r = hC_r[t].at(u); sum_mini_r += pos_min_r; } f_intersect_b[t] = sum_min_b / summ_bkg_b[t]; f_intersect_g[t] = sum_min_g / summ_bkg_g[t]; f_intersect_r[t] = sum_min_r / summ_bkg_r[t]; } thanks at all for your time!

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>