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
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 somma_bkg_b = 0;
float somma_bkg_g = 0;
float somma_bkg_r = 0;
float sommatoria_bkg_b[block];
float sommatoria_bkg_g[block];
float sommatoria_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<mat> bgr_planes;
split( SUPPORT, bgr_planes );
calcHist( &bgr_planes[0], 1, 0, Mat(), hB_b[conteggio], 1, &histSize, &histRange, uniform, accumulate );
calcHist( &bgr_planes[1], 1, 0, Mat(), hB_g[conteggio], 1, &histSize, &histRange, uniform, accumulate );
calcHist( &bgr_planes[2], 1, 0, Mat(), hB_r[conteggio], 1, &histSize, &histRange, uniform, accumulate );
for(int b=0; b<256; b++)
{
somma_bkg_b = somma_bkg_b + hB_b[conteggio].at<int>(b);
somma_bkg_g = somma_bkg_g + hB_g[conteggio].at<int>(b);
somma_bkg_r = somma_bkg_b + hB_r[conteggio].at<int>(b);
}
sommatoria_bkg_b[conteggio] = somma_bkg_b;
sommatoria_bkg_g[conteggio] = somma_bkg_g;
sommatoria_bkg_r[conteggio] = somma_bkg_r;
conteggio++;
}
}
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_frame, Rect(a,b,10,10));
ricostruzione[conteggio_c] = SUPPORT_2.clone();
vector<mat> bgr_planes_c;
split( SUPPORT_2, bgr_planes_c );
calcHist( &bgr_planes_c[0], 1, 0, Mat(), hC_b[conteggio_c], 1, &histSize, &histRange, uniform, accumulate );
calcHist( &bgr_planes_c[1], 1, 0, Mat(), hC_g[conteggio_c], 1, &histSize, &histRange, uniform, accumulate );
calcHist( &bgr_planes_c[2], 1, 0, Mat(), hC_r[conteggio_c], 1, &histSize, &histRange, uniform, accumulate );
double f_intersezione_b[block];
double f_intersezione_g[block];
double f_intersezione_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 somma_minimi_b = 0;
float pos_min_g = 0;
float somma_minimi_g = 0;
float pos_min_r = 0;
float somma_minimi_r = 0;
for (int t=0; t<block; t++)="" {="" for="" (int="" u="0;" u<256;="" u++)="" {="" intersect="" formula="" (blu)***************************************************="" if="" (hb_b[t].at<int="">(u) <= hC_b[t].at<int>(u))
pos_min_b = hB_b[t].at<int>(u);
else
pos_min_b = hC_b[t].at<int>(u);
somma_minimi_b += pos_min_b;
//intersect formula (GREEN)***************
if (hB_g[t].at<int>(u) <= hC_g[t].at<int>(u))
pos_min_g = hB_g[t].at<int>(u);
else
pos_min_g = hC_g[t].at<int>(u);
somma_minimi_g += pos_min_g;
//intersect formula (RED)*****************
if (hB_r[t].at<int>(u) <= hC_r[t].at<int>(u))
pos_min_r = hB_r[t].at<int>(u);
else
pos_min_r = hC_r[t].at<int>(u);
somma_minimi_r += pos_min_r;
}
f_intersezione_b[t] = somma_minimi_b / sommatoria_bkg_b[t];
f_intersezione_g[t] = somma_minimi_g / sommatoria_bkg_g[t];
f_intersezione_r[t] = somma_minimi_r / sommatoria_bkg_r[t];
}
thanks at all for your time!