-
Notifications
You must be signed in to change notification settings - Fork 2
/
face_reader.v
127 lines (115 loc) · 3.81 KB
/
face_reader.v
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
`timescale 1ns / 1ps
/*
*/
module face_reader #(
parameter WIDTH = 256,
parameter DEPTH = 256,
parameter FILTER_SIZE = 5,
parameter COLOR_DEPTH = 8
) (
image_in_R, image_in_G, image_in_B, enable, enable_process, clk,
image_output, centroid_x, centroid_y, done, finish
);
input [COLOR_DEPTH-1:0] image_in_R, image_in_G, image_in_B;
input enable, enable_process, clk;
reg [COLOR_DEPTH-1:0] image [0:(WIDTH * DEPTH) - 1];
output reg [COLOR_DEPTH-1:0] image_output; // single bit (black or white)
output reg finish = 1'b0;
reg [8:0] posx, posy;
parameter WAIT_FOR_IMAGE = 4'd0;
parameter RECIEVE_IMAGE = 4'd1;
parameter WAIT_FOR_PROCESS = 4'd2;
parameter PROCESS = 4'd3;
parameter SEND_DATA = 4'd4;
parameter WAIT_FOR_CENTROID = 4'd5;
reg [3:0] state = WAIT_FOR_IMAGE;
reg end_of_image;
reg isWhite;
output reg done;
wire centroid_done;
output [7:0] centroid_x, centroid_y;
//centroid find_face(posx, posy, isWhite, finish, centroid_x, centroid_y, centroid_done, clk);
reg smooth_enable;
wire smoothed_output;
low_pass smooth_face(isWhite, smooth_enable, finish, clk, centroid_x, centroid_y, centroid_done, smoothed_output); // when this module finished, start processing
/*
Y = (R+2G+B)/4
U = R - G
V = B - G
*/
//wire [COLOR_DEPTH:0] Y_sum;
wire [COLOR_DEPTH-1:0] Y, U, V;
//assign Y_sum = image_in_R + {image_in_G[COLOR_DEPTH-1], (image_in_G << 1)}, + image_in_B; // left shift with keeping the MSB to perform *2
assign U = image_in_R < image_in_G ? 0 : image_in_R - image_in_G; // check for underflow
//assign isWhite = U > 26 && U < 74;
//assign V = image_in_B - image_in-G; // check for underflow
always @(posedge clk) begin
if(state == WAIT_FOR_IMAGE) begin
if(enable) begin
state <= RECIEVE_IMAGE;
posx <= 9'b0;
posy <= 9'b0;
end_of_image <= 1'b0;
smooth_enable <= 1'b1;
end
end else if (state == RECIEVE_IMAGE) begin
if(end_of_image) begin
$display("sending");
posx <= 9'b0;
posy <= 9'b0;
finish <= 1'b1;
end_of_image <= 1'b0;
isWhite <= 1'b0;
state <= WAIT_FOR_CENTROID;
smooth_enable <= 1'b0;
end else begin
if (U > 26 && U < 74) begin
image[(posy*WIDTH)+posx] <= 255;
isWhite <= 1'b1;
end else begin
image[(posy*WIDTH)+posx] <= 0;
isWhite <= 1'b0;
end
//image[(posy*WIDTH)+posx] <= U;
end
end else if (state == WAIT_FOR_CENTROID) begin
if (centroid_done) begin
$display("starting to output\n");
posx <= 9'b0;
posy <= 9'b0;
end_of_image <= 1'b0;
isWhite <= 1'b0;
state <= SEND_DATA;
done <= 1'b1;
end
end else if (state == SEND_DATA) begin
if(end_of_image) begin
//$display("reader finished sending");
//state <= WAIT_FOR_IMAGE;
finish <= 1'b0;
end else begin
//image_output <= image[(posy * WIDTH) + posx];
if(smoothed_output) begin
image_output <= 8'd255;
end else begin
image_output <= 8'd0;
end
end
end
end
always @(posedge clk) begin
// increment x and y position properly
if (state == RECIEVE_IMAGE || state == PROCESS || state == SEND_DATA) begin
if(posx == (WIDTH - 1)) begin
posx <= 9'b0;
if (posy == (DEPTH - 1)) begin
end_of_image <= 1'b1;
end else begin
posy <= posy + 1'b1;
end
end else begin
posx <= posx + 1'b1;
end
end
end
endmodule