forked from jedbrooke/FPGA-face-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_img.cpp
45 lines (36 loc) · 1.05 KB
/
read_img.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
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include "read_img.h"
#define THRESH 100
bool readImage(char* path, uint8_t pixels[IMG_WIDTH * IMG_HEIGHT][3]) {
std::string temp_str;
std::ifstream img(path);
//store the bitmask for the pixels read from the text file
int count = 0;
if(img.is_open()) {
while(getline(img,temp_str)){
std::stringstream parse_pixel(temp_str);
for (int i = 0; i < 3; i++) {
getline(parse_pixel,temp_str,',');
pixels[count][i] = atoi(temp_str.c_str());
}
count++;
}
img.close();
} else {
return 1;
}
return 0;
}
bool readImageBool(char* path, bool pixels[IMG_WIDTH * IMG_HEIGHT]) {
uint8_t pixels_rgb[IMG_WIDTH * IMG_WIDTH][3];
if(readImage(path,pixels_rgb) != 0) {
return 1;
}
for(int i = 0; i < (IMG_WIDTH * IMG_HEIGHT); i++) {
pixels[i] = ((pixels_rgb[i][0] + pixels_rgb[i][1] + pixels_rgb[i][2]) / 3 ) / THRESH;
}
return 0;
}