Commit 7a705629 authored by Charron Maxime's avatar Charron Maxime
Browse files

CPU : nettoyage du code

parent ba20db3f
run.sh
./img*
\ No newline at end of file
......@@ -130,11 +130,12 @@ unsigned char* generateRedBox(int x, int y, unsigned char *image){
}
unsigned char* calculateDiff(unsigned char* input, unsigned char* search) {
double compute_diff = omp_get_wtime();
unsigned char *diff = (unsigned char *) malloc( (inputImgWidth-searchImgWidth) * (inputImgHeight-searchImgHeight) * sizeof(unsigned char));
for ( int y = 0; y < inputImgHeight - searchImgHeight; y ++ ) {
for ( int x = 0; x < inputImgWidth - searchImgWidth; x++ ) {
// print the process
printf("%.2f %\r",(float) ((y * (inputImgWidth-searchImgWidth) + x) *100) / ((inputImgWidth-searchImgWidth) * (inputImgHeight-searchImgHeight)));
printf("%.2f% (%.0f seconds)\r",(float) ((y * (inputImgWidth-searchImgWidth) + x) *100) / ((inputImgWidth-searchImgWidth) * (inputImgHeight-searchImgHeight)), (float) (omp_get_wtime() - compute_diff));
fflush(stdout);
int sum = 0;
for ( int yBox = 0; yBox < searchImgHeight; yBox++ ) {
......@@ -162,7 +163,8 @@ unsigned char* calculateDiff(unsigned char* input, unsigned char* search) {
}
}
}
printf("\n");
fflush(stdout);
printf("\rDone in \033[0;31m %f \033[0m seconds\n",omp_get_wtime() - compute_diff);
return diff;
}
......
......@@ -5,10 +5,12 @@
#include <omp.h>
#include "functions.h"
static const int IS_INPUT = 1;
static const int IS_SEARCH = 0;
int main (int argc, char *argv[])
{
printf("CPU\n");
printf("Version : CPU\n");
double temps_initial = omp_get_wtime();
if (argc != 3)
......@@ -22,27 +24,12 @@ int main (int argc, char *argv[])
const char *searchImgPath = argv[2];
// ==================================== Loading input image.
unsigned char *inputImg = load_img(inputImgPath, 1);
unsigned char *searchImg = load_img(searchImgPath, 0);
/*
int dummyNbChannels; // number of channels forced to 3 in stb_load.
unsigned char *inputImg = stbi_load(inputImgPath, &inputImgWidth, &inputImgHeight, &dummyNbChannels, 3);
if (inputImg == NULL)
{
printf("Cannot load image %s", inputImgPath);
return EXIT_FAILURE;
}
printf("Input image %s: %dx%d\n", inputImgPath, inputImgWidth, inputImgHeight);
// ==================================== Loading search image.
unsigned char *searchImg = stbi_load(searchImgPath, &searchImgWidth, &searchImgHeight, &dummyNbChannels, 3);
if (searchImg == NULL)
{
printf("Cannot load image %s", searchImgPath);
return EXIT_FAILURE;
}
printf("Search image %s: %dx%d\n", searchImgPath, searchImgWidth, searchImgHeight);
*/
double init_input = omp_get_wtime();
unsigned char *inputImg = load_img(inputImgPath, IS_INPUT);
printf("Done in \033[0;31m %f \033[0m seconds\n", omp_get_wtime() - init_input);
double init_search = omp_get_wtime();
unsigned char *searchImg = load_img(searchImgPath, IS_SEARCH);
printf("Done in \033[0;31m %f \033[0m seconds\n", omp_get_wtime() - init_search);
......@@ -52,16 +39,18 @@ int main (int argc, char *argv[])
// ==================================== Convert input image to grey scale
printf("Convert input to grey\n");
unsigned char *inputGrey = rgb2grey(inputImg, 1);
double input_to_grey = omp_get_wtime();
unsigned char *inputGrey = rgb2grey(inputImg, IS_INPUT);
//saveGreyPicture(inputImgHeight, inputImgWidth, inputGrey, "input");
printf("Done\n");
printf("Done in \033[0;31m %f \033[0m seconds\n",omp_get_wtime() - input_to_grey);
// ==================================== Convert search image to grey scale
printf("Convert search to grey\n");
unsigned char *searchGrey = rgb2grey(searchImg, 0);
double search_to_grey = omp_get_wtime();
unsigned char *searchGrey = rgb2grey(searchImg, IS_SEARCH);
//saveGreyPicture(inputImgHeight, inputImgWidth, inputGrey, "search");
printf("Done\n");
printf("Done in \033[0;31m %f \033[0m seconds\n",omp_get_wtime() - search_to_grey);
// ============================================================================================================
......@@ -69,16 +58,22 @@ int main (int argc, char *argv[])
// ============================================================================================================
// ==================================== Calculate compability
printf("===================== Methode 1 =====================\n");
//printf("===================== Methode 1 =====================\n");
printf("Calculate difference\n");
// time execution managed in the function
unsigned char *diff = calculateDiff(inputGrey,searchGrey);
//saveGreyPicture(inputImgHeight-searchImgHeight, inputImgWidth-searchImgWidth, diff, (char*)"debug_m1");
// ==================================== Search max compability
double find_compa = omp_get_wtime();
int* coord = findBestCompability(diff);
printf("Done in \033[0;31m %f \033[0m seconds\n",omp_get_wtime() - find_compa);
free(diff);
// ==================================== Save a copy of 'inputImg' with the red box
printf("Save picture with red box\n");
double box = omp_get_wtime();
unsigned char *final_m1 = generateRedBox(coord[0], coord[1], inputImg);
printf("Done in \033[0;31m %f \033[0m seconds\n",omp_get_wtime() - box);
savePicture(final_m1, (char*)"final_m1", 1);
free(final_m1);
printf("======================================================\n");
......@@ -108,9 +103,7 @@ int main (int argc, char *argv[])
free_img(inputImg);
free_img(searchImg);
//stbi_image_free(inputImg);
//stbi_image_free(searchImg);
printf("The program took %f seconds to execute\n", omp_get_wtime() - temps_initial);
printf("The program took \033[0;31m %f \033[0m seconds to execute\n", omp_get_wtime() - temps_initial);
printf("Good bye!\n");
return EXIT_SUCCESS;
......
......@@ -12,7 +12,7 @@ chmod 755 ./tp_projet
: '
Image espace
'
#./tp_projet ./img/space.png ./img/goat.png
./tp_projet ./img/space.png ./img/goat.png
: '
Image jungle
......@@ -22,5 +22,5 @@ Image jungle
: '
Image plage
'
./tp_projet ./img/beach.png ./img/goat.png
#./tp_projet ./img/beach.png ./img/goat.png
No preview for this file type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment