-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathimage.cpp
88 lines (75 loc) · 1.77 KB
/
image.cpp
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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "image.h"
#define MYDEBUG
char* strrev(char* str)
{
char *p1, *p2;
if (!str || !*str)
return str;
for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
{
*p1 ^= *p2;
*p2 ^= *p1;
*p1 ^= *p2;
}
return str;
}
void itochar(int x, char* szBuffer, int radix)
{
int i = 0, n, xx;
n = x;
while (n > 0)
{
xx = n%radix;
n = n/radix;
szBuffer[i++] = '0' + xx;
}
szBuffer[i] = '\0';
strrev(szBuffer);
}
/* Writes a Pgm file using the hex image */
int writePgm(char *fileName, unsigned char Data[IMAGE_HEIGHT][IMAGE_WIDTH] )
{
char parameters_str[5];
int i;
const char *format = "P5";
FILE *fp = fopen(fileName, "w");
if (!fp){
printf("Unable to open file %s\n", fileName);
return -1;
}
fputs(format, fp);
fputc('\n', fp);
itochar(IMAGE_WIDTH, parameters_str, 10);
fputs(parameters_str, fp);
parameters_str[0] = 0;
fputc(' ', fp);
itochar(IMAGE_HEIGHT, parameters_str, 10);
fputs(parameters_str, fp);
parameters_str[0] = 0;
fputc('\n', fp);
itochar(IMAGE_MAXGREY, parameters_str, 10);
fputs(parameters_str, fp);
fputc('\n', fp);
for (i = 0; i < IMAGE_HEIGHT; i++)
for (int j = 0; j < IMAGE_WIDTH ; j++)
fputc(Data[i][j], fp);
fclose(fp);
return 0;
}
/* draw white bounding boxes around detected faces */
void drawRectangle(unsigned char Data[IMAGE_HEIGHT][IMAGE_WIDTH], MyRect r)
{
int i;
int col = IMAGE_WIDTH;
for (i = 0; i < r.width; i++)
Data[r.y][r.x + i] = 255;
for (i = 0; i < r.height; i++)
Data[r.y+i][r.x + r.width] = 255;
for (i = 0; i < r.width; i++)
Data[r.y + r.height][r.x + r.width - i] = 255;
for (i = 0; i < r.height; i++)
Data[r.y + r.height - i][r.x] = 255;
}