메타데이터 분석 및 보드 제어 메인 로직 구현 파일 더 자세히 ...
#include <iostream>
#include <unordered_map>
#include <string>
#include <regex>
#include <cmath>
#include <mutex>
#include <cstdio>
#include <fstream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <deque>
#include <limits>
#include <thread>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <SQLiteCpp/SQLiteCpp.h>
#include "board_control.h"
#include "../config_manager.hpp"
클래스 | |
struct | Point |
2차원 좌표를 나타내는 구조체 더 자세히 ... | |
struct | Line |
선(시작점, 끝점, 모드, 이름) 정보를 담는 구조체 더 자세히 ... | |
struct | ObjectState |
객체 이동 경로를 저장하는 구조체 더 자세히 ... | |
함수 | |
std::string | get_uart_port_for_board (int board_id) |
보드 ID로 포트 경로를 조회합니다. | |
void | analyze_risk_and_alert (SQLite::Database &db, int human_id, const string &rule_name, const string &utc_time_str) |
위험 분석 및 경고 처리 | |
float | compute_cosine_similarity (const Point &a, const Point &b) |
두 벡터의 코사인 유사도 계산 | |
void | capture_screen_and_save (SQLite::Database &db, const string &utc_time_str) |
화면을 캡처하여 DB에 저장 | |
void | control_board (int board_id, uint8_t cmd) |
보드에 명령 전송 | |
void | control_board_async (int board_id, const string &utc_time_str) |
비동기 보드 제어 (스레드) | |
void | create_detections_table (SQLite::Database &db) |
Detections 테이블을 생성합니다. | |
void | insert_data (SQLite::Database &db, const vector< unsigned char > &image_data, const string ×tamp) |
DB에 이미지 데이터를 삽입합니다. | |
bool | calculate_intersection (const Point &a1, const Point &a2, const Point &b1, const Point &b2, Point &intersection) |
두 직선의 교차점을 계산합니다. | |
void | load_dots_and_center (SQLite::Database &db) |
DB에서 Dots(보조선) 좌표를 로드하고 dot_center를 계산합니다. | |
void | load_rule_lines (SQLite::Database &db) |
DB에서 Rule Lines(가상선) 정보를 로드합니다. | |
bool | contains_frame_block (const string &block) |
블럭 내에 VideoAnalytics 프레임이 포함되어 있는지 확인합니다. | |
bool | is_linecrossing_event (const string &event_block, string &object_id, string &rule_name) |
라인크로싱 이벤트 블럭인지 확인하고 ObjectId와 RuleName을 추출합니다. | |
bool | is_human (const string &block, const string &object_id) |
ObjectId로 객체 타입이 Human인지 확인합니다. | |
void | update_vehicle_positions (const string &frame_block, const deque< string > &frame_cache) |
프레임에서 차량 위치를 업데이트하고 사라진 차량을 정리합니다. | |
void | metadata_thread (SQLite::Database &db) |
ffmpeg 메타데이터 스트림을 처리하는 루프 함수입니다. | |
int | main () |
프로그램 메인 함수 (메타데이터 모니터링 및 분석) | |
변수 | |
std::vector< std::pair< int, std::string > > | board_info |
보드 ID와 포트 경로 매핑 테이블 | |
recursive_mutex | data_mutex |
데이터 보호용 재귀 뮤텍스 | |
vector< tuple< int, Point, int, Point > > | base_line_pairs |
DB에서 로드된 기준선 쌍 (id1, p1, id2, p2) | |
Point | dot_center = {0, 0} |
기준선 교차점(중앙점) | |
unordered_map< string, Line > | rule_lines |
라인 이름 → Line 구조체 매핑 | |
unordered_map< int, ObjectState > | vehicle_trajectory_history |
차량 ID → 이동 이력 매핑 | |
메타데이터 분석 및 보드 제어 메인 로직 구현 파일
void analyze_risk_and_alert | ( | SQLite::Database & | db, |
int | human_id, | ||
const string & | rule_name, | ||
const string & | utc_time_str | ||
) |
위험 분석 및 경고 처리
위험 분석 및 경고 로직을 수행합니다.
db | SQLite 데이터베이스 객체 |
human_id | 이벤트 발생 인간의 ID |
rule_name | 이벤트 발생 라인 이름 |
utc_time_str | 이벤트 발생 시간(UTC) |
bool calculate_intersection | ( | const Point & | a1, |
const Point & | a2, | ||
const Point & | b1, | ||
const Point & | b2, | ||
Point & | intersection | ||
) |
두 직선의 교차점을 계산합니다.
a1 | 첫 번째 직선의 시작점 |
a2 | 첫 번째 직선의 끝점 |
b1 | 두 번째 직선의 시작점 |
b2 | 두 번째 직선의 끝점 |
intersection | 교차점 좌표(출력) |
void capture_screen_and_save | ( | SQLite::Database & | db, |
const string & | utc_time_str | ||
) |
화면을 캡처하여 DB에 저장
화면을 캡처하고 DB에 저장합니다.
db | SQLite 데이터베이스 객체 |
utc_time_str | UTC 시간 문자열 |
두 벡터의 코사인 유사도 계산
두 벡터의 코사인 유사도를 계산합니다.
a | 벡터 a |
b | 벡터 b |
bool contains_frame_block | ( | const string & | block | ) |
블럭 내에 VideoAnalytics 프레임이 포함되어 있는지 확인합니다.
block | XML 블럭 문자열 |
void control_board | ( | int | board_id, |
uint8_t | cmd | ||
) |
보드에 명령 전송
보드에 명령을 전송하고 결과를 출력합니다.
board_id | 보드 ID |
cmd | 명령 코드 |
void control_board_async | ( | int | board_id, |
const string & | utc_time_str | ||
) |
비동기 보드 제어 (스레드)
비동기(스레드)로 보드 제어 및 화면 캡처를 수행합니다.
board_id | 보드 ID |
utc_time_str | UTC 시간 문자열 |
void create_detections_table | ( | SQLite::Database & | db | ) |
Detections 테이블을 생성합니다.
db | SQLite 데이터베이스 객체 |
std::string get_uart_port_for_board | ( | int | board_id | ) |
보드 ID로 포트 경로를 조회합니다.
board_id | 보드 ID |
void insert_data | ( | SQLite::Database & | db, |
const vector< unsigned char > & | image_data, | ||
const string & | timestamp | ||
) |
DB에 이미지 데이터를 삽입합니다.
db | SQLite 데이터베이스 객체 |
image_data | 이미지 데이터 벡터 |
timestamp | 타임스탬프 문자열 |
bool is_human | ( | const string & | block, |
const string & | object_id | ||
) |
ObjectId로 객체 타입이 Human인지 확인합니다.
block | XML 블럭 문자열 |
object_id | 확인할 ObjectId |
bool is_linecrossing_event | ( | const string & | event_block, |
string & | object_id, | ||
string & | rule_name | ||
) |
라인크로싱 이벤트 블럭인지 확인하고 ObjectId와 RuleName을 추출합니다.
event_block | 이벤트 XML 블럭 |
object_id | 추출된 ObjectId (출력) |
rule_name | 추출된 RuleName (출력) |
void load_dots_and_center | ( | SQLite::Database & | db | ) |
DB에서 Dots(보조선) 좌표를 로드하고 dot_center를 계산합니다.
db | SQLite 데이터베이스 객체 |
void load_rule_lines | ( | SQLite::Database & | db | ) |
DB에서 Rule Lines(가상선) 정보를 로드합니다.
db | SQLite 데이터베이스 객체 |
int main | ( | ) |
프로그램 메인 함수 (메타데이터 모니터링 및 분석)
void metadata_thread | ( | SQLite::Database & | db | ) |
ffmpeg 메타데이터 스트림을 처리하는 루프 함수입니다.
db | SQLite 데이터베이스 객체 |
void update_vehicle_positions | ( | const string & | frame_block, |
const deque< string > & | frame_cache | ||
) |
프레임에서 차량 위치를 업데이트하고 사라진 차량을 정리합니다.
frame_block | 프레임 XML 블럭 |
frame_cache | 최근 프레임 캐시 |
std::vector<std::pair<int, std::string> > board_info |
보드 ID와 포트 경로 매핑 테이블