Hello to all!!!
I'm doing a little project for rebuild une image.
I must load image from my path then. I used a grid 40x40 pixels for divide image in some little images.
I must then rebuild image in order adding a red background.
I think that this project is a bit useless but this is for another project.
For my project is very important the division of the image and its orderly reconstruction. I post below my solution:
include <iostream>
include <stdio.h>
include <math.h>
include <opencv2\opencv.hpp>
include "opencv\highgui.h"
include "opencv\cv.h"
#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; std;
Mat add_piece_of_frame(Mat, Mat, int, int);
Mat add_piece_of_frame_red(Mat, Mat, int,
int); int);
int main(int argc, char** argv)
{
Mat bkg_read =
imread("C:\Users\Fabrizio\Desktop\frame\VIDEO_PER_TESI\Scene1.jpg",CV_LOAD_IMAGE_COLOR);
imread("C:\\Users\\Fabrizio\\Desktop\\frame\\VIDEO_PER_TESI\\Scene1.jpg",CV_LOAD_IMAGE_COLOR);
IplImage * bkg = cvCloneImage( &(IplImage)bkg_read );
namedWindow("original", 1);
cvShowImage("original", bkg);
cvWaitKey(3333);
cvWaitKey(3333);
//Mat background(bkg_read);
Mat ricostruzione[48];
int aa[48];
int bb[48];
int m = 0;
for(int a=0; a<320; a+=40)
{
for(int b=0; b<240; b+=40)
{
Mat SUPPORT (bkg_read, Rect(a,b,40,40));
ricostruzione[m] = SUPPORT.clone();
aa[m] = a;
bb[m] = b;
cout<<"coordinate: "<<endl;
cout<<"a: "<<aa[m];
cout<<" b: "<<bb[m]<<endl;
m++;
}
}
int A=0;
while(A<1)
{
Mat output = cv::Mat::zeros(240, 320, CV_32FC3);
Mat output_red = cv::Mat::zeros(240, 320, CV_32FC3);
for ( int t=0; t<48; t++)
{
output_red = add_piece_of_frame_red(ricostruzione[t] , output_red, aa[t] , bb[t]);
}
IplImage * exit_red = cvCloneImage( &(IplImage)output_red );
namedWindow("output_red", 1);
cvShowImage("output_red",exit_red);
cvWaitKey(3333);
for ( int u=0; u<48; u++)
{
output = add_piece_of_frame(ricostruzione[u] , output, aa[u] , bb[u]);
}
IplImage * exit = cvCloneImage( &(IplImage)output );
namedWindow("output", 1);
cvShowImage("output",exit);
cvWaitKey(3333);
}
}
}
Mat add_piece_of_frame(Mat A , Mat B, int r, int c)
{
Rect Roi(r, c, 40, 40);
B(Roi) = B(Roi) + A.clone();
return B;
} }
Mat add_piece_of_frame_red(Mat A, Mat B, int r, int c)
{
Scalar color = Scalar(0, 0, 255);
Mat mask = Mat(40, 40, CV_32FC3, color);
Mat result;
addWeighted(A, 0.5, mask, 0.5, 0, result, CV_32FC3);
Rect Roi(r, c, 40, 40);
B(Roi) = B(Roi) + result.clone();
return B;
}
}