@LorenaGdL
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 main(int argc, char** argv)
{
//lettura immagine
Mat background = imread("C:\Users\Fabrizio\Desktop\frame\VIDEO_PER_TESI\Scene1.jpg",CV_LOAD_IMAGE_COLOR);
//controllo di avvenuta lettura corretta
if(! background.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
//mostra immagine riferimento
imshow("background di riferimento", background);
waitKey(1);
//vettori per istogrami sfondo
Mat hB_b[768];
Mat hB_g[768];
Mat hB_r[768];
//vettori per istogrami immagine
Mat hC_b[768];
Mat hC_g[768];
Mat hC_r[768];
/**************variabili necessarie per l'istogrmma da generare*********************************************************************************/
//numero di bins
int histSize = 256;
//range per (b,g,r)
float range[] = { 0, 256 } ;
const float* histRange = { range };
bool uniform = true;
bool accumulate = false;
//**********************************************************************************************************************************************
Mat b_hist_b, g_hist_b, r_hist_b;
Mat b_hist_c, g_hist_c, r_hist_c;
Mat back_hist;
Mat current_hist;
double somma_bkg_b = 0;
double somma_bkg_g = 0;
double somma_bkg_r = 0;
double sommatoria_bkg_b[768];
double sommatoria_bkg_g[768];
double sommatoria_bkg_r[768];
int conteggio = 0;
int conteggio_c = 0;
int cont_hist = 0;
/***********************************************************************************************************************************************/
//*******************inizio raccolta dati di riferimento*****************************************************************************************
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 );
//hB_b[conteggio] = b_hist_b.clone();
//hB_g[conteggio] = g_hist_b.clone();
//hB_r[conteggio] = r_hist_b.clone();
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++;
}
}
//----------------------fine della prima parte (salvataggio dati)--------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------------------------
CvCapture* capture = cvCreateFileCapture("C:\\Users\\Fabrizio\\Desktop\\frame\\VIDEO_PER_TESI\\Scene1.avi");
IplImage* frame;
cout <<"***************************************************************************************** "<< std::endl ;
cout <<"************************inizio parte corrente******************************************** "<< std::endl ;
cout <<"***************************************************************************************** "<< std::endl ;
int A=0;
while(true)
{
frame = cvQueryFrame(capture);
if(!frame) break; //check for valid frame
Mat current(frame);
//---------vettore che serve per ricostruire l'immagine (salvataggio di parti di immagine originali)--------------------------------------
Mat ricostruzione[768];
//matrice che serve per generare output modificato
Mat output = cv::Mat::zeros(240, 320, CV_8UC3);
//vettori per il salvataggio dei punti iniziali di ricostruzione
int aa[768];
int bb[768];
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[conteggio_c] = SUPPORT_2.clone();
aa[conteggio_c] = a;
bb[conteggio_c] = b;
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 );
conteggio_c++;
}
}
float f_chi_squared_b[768];
float f_chi_squared_g[768];
float f_chi_squared_r[768];
bool f_chi_sq[768];
Mat ...
(more)
output
image, so pretty hard to know what's going onjust saying, if you want to chop your image into 10x10 tiles, you have to spare a 10pix border to the right / bottom, else you go out of bounds:
for(int a=0; a<320 - 10; a+=10)
(same for b)@LorenaGdL excuse me if there isn't the modification of output but I think that are not necessary to fix the problem. The modifications are comparing and show a rect grid with red background based on the comparison . @berak Why -10? My image is 320x240. I must read image until last pix. If I use two images and 10x10 grid the program run correctly but if I use one image and a video from which use frame by frame (comparison between reference image and the current frame of video) don't run. My output is black.
@baro start by modifying your code to only use C++. And call me crazy, but if you show some lines where
output
is initialized to a black image, you hide the possible modifications to the matrix, and then you asked whyoutput
is black... well, I do find the missing parts neccesary. And you're lucky to not run into out of bounds problems because your image dimensions are perfectly divisible by 10. @berak's comment should be taken into account in any code with a minimum level of reusability