1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
| #include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <SDL2/SDL.h>
#include <string.h>
//#include "tools/bin/resize.h"
//#include "separator/separator.h"
#include "binarization/binarize.h"
#include "SDL_Manager/import-export.h"
#include "skew/skew.h"
//Safety test env
#ifndef ENV_TEST
double abse(double x){
if (x < 0)
return -x;
return x;
}
double lemax(double x, double y){
if (x > y)
return x;
else
return y;
}
double lemin(double x, double y){
if (x < y)
return x;
else
return y;
}
int main(int argc, char ** argv)
{
int x;
int * px = &x;
int y;
int * py = &y;
SDL_Surface * image = load_image("ANT.BMP", px, py);
double * ptdr = NULL;
ptdr = malloc(8*sizeof(double));
//x1,y1,...
ptdr[0] = 37;
ptdr[4] = 381;
ptdr[1] = 647;
ptdr[5] = 441;
ptdr[2] = 115;
ptdr[6] = 1219;
ptdr[3] = 787;
ptdr[7] = 1200;
int l = 8;
double * boardg = NULL;
boardg = malloc(l * l * sizeof(double));
double * inv = NULL;
inv = malloc(l * l * sizeof(double));
for(int i = 0;i<l*l;i++){
if (i%(l+1) == 0)
inv[i] = 1;
else
inv[i] = 0;
}
for(int i = 0;i<l*l;i++)
boardg[i] = 0;
for(int i = 0;i<4;i++){
boardg[l*i] = boardg[l*(i+4)+3] = boardg[l*i+6] = boardg[l*(i+4)+6] = ptdr[i];
boardg[l*i+1] = boardg[l*(i+4)+4] = boardg[l*i+7] = boardg[l*(i+4)+7] = ptdr[i+4];
boardg[l*i+2] = boardg[l*(i+4)+5] = 1;
}//*/
//Transformation de x,y en X,Y
ptdr[0] = ptdr[2] = lemin(ptdr[0],ptdr[2]);
ptdr[4] = ptdr[5] = lemin(ptdr[4],ptdr[5]);
ptdr[1] = ptdr[3] = lemax(ptdr[1],ptdr[3]);
ptdr[7] = ptdr[6] = lemax(ptdr[7],ptdr[6]);
/*
ptdr[0] = ptdr[2] = 10;
ptdr[4] = ptdr[5] = 10;
ptdr[1] = ptdr[3] = x-10;
ptdr[7] = ptdr[6] = y-10; */
for(int i = 0;i<4;i++){
boardg[l*i+6] *= -1 * ptdr[i];
boardg[l*i+7] *= -1 * ptdr[i];
boardg[l*(i+4)+6] *= -1 * ptdr[i+4];
boardg[l*(i+4)+7] *= -1 * ptdr[i+4];
}
/*
for(int i = 0; i < l*l;i++){
if (i %l == 0)
printf("\n");
printf(" %f ,",boardg[i]);
} //*/
//Calcul inverse
int r = -1;
for (int j = 0; j < l;j++){
int k = r+1;
for(int i = k;i< l;i++){
if (abse(boardg[l*i + j]) > abse(boardg[l*k + j]))
k = i;
}
if (boardg[l*k+j] != 0){
r += 1;
double divisor = boardg[k*l+j];
for(int i = 0; i < l;i++){
boardg[k*l+i] /= divisor;
inv[k*l+i] /= divisor;
}
if (k != r){
for(int i = 0; i < l;i++){
double tmp = boardg[r*l+i];
boardg[r*l+i] = boardg[k*l+i];
boardg[k*l+i] = tmp;
double tmp2 = inv[r*l+i];
inv[r*l+i] = inv[k*l+i];
inv[k*l+i] = tmp2;
}
}
for (int i = 0; i < l;i++){
if (i != r){
double tmp = boardg[i*l+j];
for (int wow = 0; wow < l;wow++){
boardg[i*l+wow] -= boardg[r*l+wow] * tmp;
inv[i*l+wow] -= inv[r*l+wow] * tmp;
}
}
}
}
} //*/
//Multiplication matrice
double res[l];
for (int i=0;i<l;i++){
res[i] = 0;
for(int j = 0;j<l;j++)
res[i] += inv[l*i+j] * ptdr[j];
//printf("%f\n",ptdr[i]);
printf("%f\n",res[i]);
}
//Initialisation SDL
printf("\nui\n");
Uint8 * board3 = NULL;
board3 = malloc(x * y * sizeof(Uint8));
gray(image,board3);
Uint8 * board2 = NULL;
board2 = malloc(x * y * sizeof(Uint8));
//Application nouvelles coordonnées
for(Uint16 i = 0; i < x;i++){
for(Uint16 j = 0; j < y;j++){
int ppx = (int) ((res[0]*i+res[1]*j+res[2])/(res[6]*i+res[7]*j+1));
int ppy = (int) ((res[3]*i+res[4]*j+res[5])/(res[6]*i+res[7]*j+1));
if (ppy>0 && ppy < y && ppx >0 && ppx < x)
board2[j*x + i] = board3[ppy*x+ppx];
}
}
save(board2,x,y,"/home/user/Bureau/ocr/src/main/c/oui.bmp");
printf("\nChaussette\n\n");
free(board3);
free(board2);
free(boardg);
free(ptdr);
return 0;
}
#endif |
Partager