2 Commits

Author SHA1 Message Date
lyf
1e21138668 格式修正 2025-12-04 22:48:31 +08:00
lyf
8728fd88e5 坐标变化 2025-12-04 20:26:55 +08:00

View File

@@ -30,8 +30,14 @@ void output_control_data(const cv::Point2f* ballistic_point,
std::ostringstream send_str; std::ostringstream send_str;
// Calculate offset (based on actual image center) // Calculate offset (based on actual image center)
int ballistic_offset_x = static_cast<int>(ballistic_point->x - img_center.x); int ballistic_offset_x = -static_cast<int>(ballistic_point->x - img_center.x);
int ballistic_offset_y = static_cast<int>(img_center.y - ballistic_point->y); if ( abs(ballistic_offset_x) > 320){
ballistic_offset_x = ( ballistic_offset_x / abs( ballistic_offset_x ) ) * 320 ;
}
int ballistic_offset_y = -static_cast<int>(img_center.y - ballistic_point->y);
if ( abs(ballistic_offset_y) > 180 ) {
ballistic_offset_y = ( ballistic_offset_x / abs( ballistic_offset_x ) ) * 180 ;
}
// Color simplification mapping // Color simplification mapping
std::string simplified_color = target_color; std::string simplified_color = target_color;
@@ -39,7 +45,7 @@ void output_control_data(const cv::Point2f* ballistic_point,
else if (target_color == "blue") simplified_color = "b"; else if (target_color == "blue") simplified_color = "b";
// Construct send string // Construct send string
send_str << "s " << simplified_color << " " << std::to_string(ballistic_offset_x) << " " << std::to_string(ballistic_offset_y) << "\n"; send_str << "#s " << simplified_color << " " << std::to_string(ballistic_offset_x) << " " << std::to_string(ballistic_offset_y) << "*\n";
// Send data // Send data
if (ttl_communicator != nullptr) { if (ttl_communicator != nullptr) {
@@ -72,15 +78,7 @@ int main(int /*argc*/, char* /*argv*/[]) {
if (Numbe == 0) { if (Numbe == 0) {
// 执行 shell 命令(注意安全风险!) // 执行 shell 命令(注意安全风险!)
int result = std::system("soude chmod 777 /dev/tty*"); std::system("sudo chmod 777 /dev/tty*");
// 可选:检查命令是否成功执行
if (result == -1) {
std::cerr << "Failed to execute system command.\n";
} else {
std::cout << "Permissions updated (if any tty devices exist).\n";
}
Numbe++; Numbe++;
} }