Last active
December 20, 2015 02:49
-
-
Save fabiocarneiro/6059217 to your computer and use it in GitHub Desktop.
daniel cara de pastel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* File: main.cpp | |
* Author: Fabio | |
* | |
* Created on July 22, 2013, 9:52 PM | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
using namespace std; | |
struct movimento { | |
int i; | |
int j; | |
}; | |
int calc_sad(int *V1, int *V2) { | |
int SAD; | |
SAD = (V1[0] + V1[1] + V1[2] + V1[3])-(V2[0] + V2[1] + V2[2] + V2[3]); | |
return SAD; | |
} | |
int main(int argc, char *argv[]) { | |
//Declaracao de Valores | |
FILE *fp, *fp2; | |
int altura, largura, F0[10][10], F1[10][10], SAD_AUX[8][8], lastaux = 0, m = 0, n = 0, c = 0, V1[3], V2[3]; | |
struct movimento mov[24]; | |
//end | |
//Abrindo o arquivo | |
if (argc != 2) { | |
printf("Voce esqueceu de colocar o nome do arquivo.\n"); | |
exit(1); | |
} | |
if ((fp = fopen(argv[1], "r")) == NULL) { | |
printf("Nao foi possivel abrir o arquivo.\n"); | |
exit(1); | |
} | |
//end | |
//Salvando os valores | |
fscanf(fp, "%d", &altura); | |
fscanf(fp, "%d", &largura); | |
for (int k = 0; k < altura; k++) { | |
for (int l = 0; l < largura; l++) { | |
fscanf(fp, "%d", &F0[k][l]); | |
} | |
} | |
for (int k = 0; k < altura; k++) { | |
for (int l = 0; l < largura; l++) { | |
fscanf(fp, "%d", &F1[k][l]); | |
} | |
} | |
//end | |
//Calculos | |
int v = 0; | |
for (int p = 0; p < 5; p += 2) { | |
for (int q = 0; q < 5; q += 2) { | |
V2[0] = F0[p][q]; | |
V2[1] = F0[p][q + 1]; | |
V2[2] = F0[p + 1][q]; | |
V2[3] = F0[p + 1][q + 1]; | |
for (int k = 0; k < 10; k += 1) { | |
for (int l = 0; l < 10; l += 1) { | |
V1[0] = F0[k][l]; | |
V1[1] = F0[k][l + 1]; | |
V1[2] = F0[k + 1][l]; | |
V1[3] = F0[k + 1][l + 1]; | |
SAD_AUX[k][l] = calc_sad(V1, V2); | |
} | |
} | |
for (int k = 0; k < 8; k += 1) { | |
for (int l = 0; l < 8; l += 1) { | |
if (SAD_AUX[k][l] < lastaux) { | |
lastaux = SAD_AUX[k][l]; | |
mov[v].i = k; | |
mov[v].j = l; | |
} | |
} | |
} | |
v++; | |
} | |
} | |
//end | |
//Criar binario | |
fp2 = fopen("movimento.bin", "wb"); | |
for (int k = 0; k < 25; k++) { | |
printf("%d\n", mov[k].i); | |
printf("%d\n", mov[k].j); | |
fwrite(&mov[k].i, sizeof (int), 25, fp2); | |
fwrite(&mov[k].j, sizeof (int), 25, fp2); | |
} | |
rewind(fp2); | |
//end | |
//Mostrar Binario | |
unsigned char info[50]; | |
fread(&info, sizeof (int), 1, fp2); | |
for (int k = 0; k < 50; k++) { | |
printf("%d ", *(int*) &info[k]); | |
} | |
//end | |
fclose(fp); | |
fclose(fp2); | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment