1. Title
실시간 이미지 처리를 통해 움직이는 사물을 추적할 수 있는 모듈을 설계한다.
2. Category
"Video Processing"
3. Key Concepts
Object Tracking
4. 개념
카메라를 통해 실시간으로 물체를 추적하는 원리는 다음과 같은 과정을 거친다.
1. 객체 검출 (Object Detection)
먼저 영상 내에서 추적하고자 하는 객체를 검출해야 한다. 대표적인 방법으로는 Haar Cascade, HOG (Histogram of Oriented Gradients), YOLO (You Only Look Once), SSD (Single Shot Multibox Detector) 등이 있으며 검출된 객체는 보통 바운딩 박스(좌표)로 표시됩니다.
2. 객체 추적 (Object Tracking)
객체를 검출한 후에는 프레임 간에 비교를 통해 그 객체의 위치를 추적해야 한다.
3. 트래킹 알고리즘의 평가
Threshold 값에 따라 해당 객체가 움직인 것인지 판별한다.
Video Course Project - Motion Detector
1. Title실시간 이미지 처리를 통해 모션을 감지할 수 있는 모듈을 설계한다.2. Category"Video Processing" 3. Key ConceptsMotion Detect, Sobel Filter 4. 개념카메라를 통해 실시간으로 움직임을 검출하는 원리는
salmon1113.tistory.com
객체 검출 알고리즘은 위의 모션 디텍팅에서 사용된 알고리즘을 활용한다.
5. BLOCK DIAGRAM / FSM
6.Code Review
always_ff @(posedge pclk, posedge reset) begin
if (reset) begin
sum_x <= 20'b0;
sum_y <= 20'b0;
pixel_count <= 17'b0;
end else begin
if (frame_done) begin
sum_x <= 20'b0;
sum_y <= 20'b0;
pixel_count <= 17'b0;
end else if (diff_detected) begin
if (x_pixel < 320 && y_pixel < 240) begin
sum_x <= sum_x + x_pixel;
sum_y <= sum_y + y_pixel;
pixel_count <= pixel_count + 1;
end
end
end
end
객체의 중심을 계산하는 알고리즘이다. 만약 화면 상에서 움직임이 감지되면, 감지된 부분의 좌표값을 지속적으로 저장한다. (sum_x, sum_y)
always_ff @(posedge frame_done, posedge reset) begin
if (reset) begin
curr_center_x <= 10'd0;
curr_center_y <= 10'd0;
end else begin
if (pixel_count > 17'd150) begin
curr_center_x <= sum_x / (pixel_count);
curr_center_y <= sum_y / (pixel_count);
end else begin
curr_center_x <= curr_center_x;
curr_center_y <= curr_center_y;
end
end
end
always_ff @(posedge clk, posedge reset) begin
if (reset) begin
center_x <= 10'd0;
center_y <= 10'd0;
end else begin
center_x <= curr_center_x;
center_y <= curr_center_y;
end
end
frame이 끝나는 시점에서, 만약에 일정 수준 이상의 움직임이 감지되었다 하면 그때부터 감지된 객체의 중심을 계산한다.
always_comb begin
next_state = state;
motion_valid = 0;
case (state)
IDLE: begin
motion_valid = 0;
if(pixel_count > 17'd150) begin
next_state = TRACKING;
end
end
TRACKING: begin
motion_valid = 1;
if(half_sec_tick) begin
next_state = IDLE;
end
end
endcase
end
일정 수준 이상의 움직임이 감지되었다 하면 FSM에 따라서 0.5초 동안 TRACKING 상태가 되어 위에서 계산된 좌표값을 기준으로 아래 알고리즘을 통해 네모 박스를 그리게 된다.
logic [9:0] box_left, box_right, box_top, box_bottom;
logic box_h_border, box_v_border;
assign box_left = (center_x > (box_width/2)) ? (center_x - (box_width/2)) : 10'd0;
assign box_right = (center_x + (box_width/2) < 10'd320) ? (center_x + (box_width/2)) : 10'd319;
assign box_top = (center_y > (box_height/2)) ? (center_y - (box_height/2)) : 10'd0;
assign box_bottom = (center_y + (box_height/2) < 10'd240) ? (center_y + (box_height/2)) : 10'd239;
assign box_h_border = ((y_pixel == box_top || y_pixel == box_bottom) &&
(x_pixel >= box_left && x_pixel <= box_right));
assign box_v_border = ((x_pixel == box_left || x_pixel == box_right) &&
(y_pixel >= box_top && y_pixel <= box_bottom));
assign box_active = display_enable && motion_valid && (box_h_border || box_v_border);
always_ff @(posedge clk, posedge reset) begin
if (reset) begin
r_out <= 4'b0;
g_out <= 4'b0;
b_out <= 4'b0;
end else if (display_enable) begin
if (left_top_enable) begin
if (box_active) begin
r_out <= 4'h0;
g_out <= 4'hf;
b_out <= 4'h0;
end else begin
if (motion_detected) begin
if (x_pixel < LINE_THICKNESS) begin
r_out <= 4'hf;
g_out <= 4'h0;
b_out <= 4'h0;
end else begin
r_out <= left_top_image;
g_out <= left_top_image;
b_out <= left_top_image;
end
end else begin
r_out <= left_top_image;
b_out <= left_top_image;
g_out <= left_top_image;
end
end
end
end
end
7.동작 영상
'PROJECTS > 영상 처리' 카테고리의 다른 글
Video Course Project - Motion Detector (0) | 2025.03.28 |
---|---|
Video Course Project - Sobel Filter (0) | 2025.03.23 |