I need to make a "face detection" program in C. The inputs are the number of "faces" detected, height and width of the picture (not larger than 120), and then the coordinates of the face. After that, the next inputs are three arrays which represent the RGB values of the picture.
The output of the program should be the original picture, but with the coordinates connecting as a green rectangle. The alpha value in the rectangle should be 255, and outside should be 127.
We get a few test cases to work with. The first test case is a simple 5x5 black square with random coordinates, the output for this test case is fine.
The problem arises in the other 3 test cases, which are actual pictures. What happens is, instead of a green rectangle, there are random green lines and dots all around the picture (not even on the coordinates). And the alpha values are seemingly radom as well, where a few lines are alpha 127, and a few 255.
Edit: I definitely worded everything wrong. The program needs to draw a green rectangle and modify the alpha values around the coordinates in the input. The program itself doesn't identify the face.
#include <stdio.h>
#define MAX 120
int main() {
FILE* fin = fopen("input.txt", "r");
FILE* fout = fopen("output.txt", "w");
int R[MAX][MAX], G[MAX][MAX], B[MAX][MAX], x1[MAX], y1[MAX], x2[MAX], y2[MAX], A[MAX][MAX];
int h, w, n, i, j, k;
fscanf(fin, "%d %d %d", &n, &h, &w);
for (i = 0; i < n; i++) {
fscanf(fin, "%d %d %d %d", &x1[i], &y1[i], &x2[i], &y2[i]);
}
for (i = 0; i < w; i++) {
for (j = 0; j < h; j++) {
fscanf(fin, "%d ", &R[i][j]);
}
}
for (i = 0; i < w; i++) {
for (j = 0; j < h; j++) {
fscanf(fin, "%d ", &G[i][j]);
}
}
for (i = 0; i < w; i++) {
for (j = 0; j < h; j++) {
fscanf(fin, "%d ", &B[i][j]);
}
}
for (i = 0; i < w; i++) {
for (j = 0; j < h; j++) {
A[i][j] = 127;
}
}
for (k = 0; k < n; k++) {
for (i = x1[k]; i <= x2[k]; ++i) {
G[i][y1[k]] = 255;
G[i][y2[k]] = 255;
A[i][y1[k]] = 255;
A[i][y2[k]] = 255;
R[i][y1[k]] = 0;
R[i][y2[k]] = 0;
B[i][y1[k]] = 0;
B[i][y2[k]] = 0;
}
for (j = y1[k]; j <= y2[k]; ++j) {
G[x1[k]][j] = 255;
G[x2[k]][j] = 255;
A[x1[k]][j] = 255;
A[x2[k]][j] = 255;
R[x1[k]][j] = 0;
R[x2[k]][j] = 0;
B[x1[k]][j] = 0;
B[x2[k]][j] = 0;
}
}
for (k = 0; k < n; k++) {
for (i = x1[k] + 1; i <= x2[k] - 1; i++) {
for (j = y1[k] + 1; j <= y2[k] - 1; j++) {
A[i][j] = 255;
}
}
}
fprintf(fout, "/image %d %d RGBA\n", h, w);
for (i = 0; i < w; i++) {
for (j = 0; j < h; j++) {
fprintf(fout, "%d %d %d %d ", R[i][j], G[i][j], B[i][j], A[i][j]);
}
}
return 0;
}
What I have tried:
The inputs of the program are read correctly, as I've tried printing them out and they come out fine. So I've tried rewriting the for loops in several different ways, but no matter what paremeters I set, the result comes out the same.