compareHist threshold
Hi at all!!! I'm doing a comparison between two different images but I have a problem to set the threshold for three color: blue, green and red. Could anyone tell me how I set these thresholdes? Below I post my program and I am attaching the two different images. The scope of my program is detect object or people doing a comparison with background image and show parts that are different in red.
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <opencv2\opencv.hpp>
#include "opencv\highgui.h"
#include "opencv\cv.h"
using namespace cv;
using namespace std;
void add_piece_of_frame(const Mat&, Mat&, int, int);
void add_piece_of_frame_red(const Mat&, Mat&, int, int);
int const dim = 20;
int main(int argc, char** argv)
{
int const block = 80;
//read image
Mat background = imread("Scene1.jpg",CV_LOAD_IMAGE_COLOR);
//check read image
if(! background.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
//shows reference image
imshow("background di riferimento", background);
waitKey(1);
//vectors for background histograms
Mat hB_b[block];
Mat hB_g[block];
Mat hB_r[block];
//vectors for image histograms
Mat hC_b[block];
Mat hC_g[block];
Mat hC_r[block];
//**************variables for histograms*********************************************************************************
//number of histogram bins
int histSize = 256;
//range per (b,g,r)
float range[] = { 0, 256 } ;
const float* histRange = { range };
bool uniform = true;
bool accumulate = false;
//**********************************************************************************************************************************************
int count = 0; //counter variable for background cycle
int count_c = 0; //counter variable for current cycle
int nFrame = 0; //counter variable for numerated frames
for(int a=0; a<320; a+=dim)
{
for(int b=40; b<140; b+=dim)
{
//block
Mat SUPPORT (background, Rect(a,b,dim,dim));
//split block to obtain color elements
vector<Mat> bgr_planes;
split( SUPPORT, bgr_planes );
//calculate histograms for each color
calcHist( &bgr_planes[0], 1, 0, Mat(), hB_b[count], 1, &histSize, &histRange, uniform, accumulate );//blu
calcHist( &bgr_planes[1], 1, 0, Mat(), hB_g[count], 1, &histSize, &histRange, uniform, accumulate );//green
calcHist( &bgr_planes[2], 1, 0, Mat(), hB_r[count], 1, &histSize, &histRange, uniform, accumulate );//red
count++;
}
}
//VideoCapture cap("tagliato.avi");
Mat current_frame = imread("Scene1_2.jpg",CV_LOAD_IMAGE_COLOR);
//while(1)
//{
//Mat current_frame;
//bool img = cap.read(current_frame);
//if(!img)
//break;
//---------Mats' vector for recostruction image (save parts of original image) ---------------------
Mat recostruct[block];
//matrix for modified output
//Mat output = cv::Mat::zeros(240, 320, CV_8UC3);
Mat output_chi_sq = current_frame.clone();
Mat output_correl = current_frame.clone();
Mat output_intersect = current_frame.clone();
//vettori per il salvataggio dei punti iniziali di ricostruzione
int aa[block];
int bb[block];
for(int a=0; a<320; a+=dim)
{
for(int b=40; b<140; b+=dim)
{
Mat SUPPORT_2 (current_frame, Rect(a,b,dim,dim));
//save block to recostruction
recostruct[count_c] = SUPPORT_2.clone();
//save block's points
aa[count_c] = a;
bb[count_c] = b;
//split current block
vector<Mat> bgr_planes_c;
split( SUPPORT_2, bgr_planes_c );
//calculate histograms for each color
calcHist( &bgr_planes_c[0], 1, 0, Mat(), hC_b[count_c], 1, &histSize, &histRange, uniform, accumulate );//blu
calcHist( &bgr_planes_c[1], 1, 0, Mat(), hC_g[count_c], 1, &histSize, &histRange, uniform, accumulate );//gren
calcHist( &bgr_planes_c[2], 1, 0, Mat(), hC_r[count_c], 1, &histSize, &histRange, uniform, accumulate );//red ...
I have more problems to set correlation thresholds!! Thanks you soo much