项目结构大变
This commit is contained in:
@@ -6,21 +6,22 @@
|
||||
class BallisticPredictor {
|
||||
public:
|
||||
BallisticPredictor(float bullet_speed = 16.0f);
|
||||
|
||||
~BallisticPredictor(); // Added destructor to properly manage memory
|
||||
|
||||
// Predict ballistic point considering target movement and flight time
|
||||
cv::Point2f* predict_ballistic_point(const cv::Point2f* predicted_center,
|
||||
const cv::Point2f& img_center,
|
||||
cv::Point2f* predict_ballistic_point(const cv::Point2f* predicted_center,
|
||||
const cv::Point2f& img_center,
|
||||
const cv::Point2f& target_speed);
|
||||
|
||||
|
||||
// Get last ballistic point
|
||||
const cv::Point2f* get_last_ballistic_point() const { return last_ballistic_point; }
|
||||
|
||||
|
||||
private:
|
||||
float bullet_speed; // Bullet speed (m/s)
|
||||
float armor_half_width; // Armor half width (converted to meters)
|
||||
float armor_half_height; // Armor half height (converted to meters)
|
||||
cv::Point2f* last_ballistic_point; // Last ballistic prediction
|
||||
|
||||
|
||||
// Calculate distance to target
|
||||
float calculate_distance(const cv::Point2f& armor_center, const cv::Point2f& img_center, float focal_length = 800.0f);
|
||||
};
|
||||
|
||||
@@ -8,16 +8,12 @@ class ImagePreprocessor {
|
||||
public:
|
||||
ImagePreprocessor();
|
||||
~ImagePreprocessor();
|
||||
|
||||
// Get mask based on target color
|
||||
cv::Mat get_mask(const cv::Mat& frame, const std::string& target_color);
|
||||
|
||||
// Get frame with only the target color
|
||||
cv::Mat get_color_only_frame(const cv::Mat& frame, const std::string& target_color);
|
||||
|
||||
// Combined function to return both mask and color-only frame
|
||||
void process_frame(const cv::Mat& frame, const std::string& target_color,
|
||||
cv::Mat& mask, cv::Mat& color_only_frame);
|
||||
|
||||
// Apply morphological operations to a mask
|
||||
void apply_morphology(const cv::Mat& input_mask, cv::Mat& output_mask);
|
||||
|
||||
// Apply Gaussian blur to reduce noise
|
||||
void apply_gaussian_blur(const cv::Mat& input, cv::Mat& output, int kernel_size = 6);
|
||||
};
|
||||
|
||||
#endif // IMAGEPREPROCESSOR_H
|
||||
@@ -6,12 +6,16 @@
|
||||
class KalmanFilter {
|
||||
public:
|
||||
KalmanFilter();
|
||||
|
||||
|
||||
void update(const cv::Point2f& measurement);
|
||||
cv::Point2f predict();
|
||||
|
||||
|
||||
// Method to update the process noise based on target movement characteristics
|
||||
void updateProcessNoise(const cv::Point2f& current_measurement);
|
||||
|
||||
cv::Point2f get_last_measurement() const { return last_measurement; }
|
||||
cv::Point2f get_last_prediction() const { return last_prediction; }
|
||||
cv::Point2f get_current_velocity() const; // New method to get current velocity
|
||||
bool is_initialized() const { return initialized; }
|
||||
|
||||
private:
|
||||
@@ -19,8 +23,16 @@ private:
|
||||
bool initialized;
|
||||
cv::Point2f last_measurement;
|
||||
cv::Point2f last_prediction;
|
||||
|
||||
cv::Point2f prev_measurement;
|
||||
bool has_prev_measurement;
|
||||
|
||||
// Store previous states for velocity and acceleration estimation
|
||||
cv::Point2f prev_velocity;
|
||||
double time_elapsed; // Time in seconds between measurements
|
||||
bool has_prev_velocity;
|
||||
|
||||
void init_params();
|
||||
cv::Point2f estimate_velocity(const cv::Point2f& current, const cv::Point2f& previous);
|
||||
};
|
||||
|
||||
#endif // KALMANFILTER_H
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
// MindVision SDK 头文件 - 可能需要根据实际SDK文件调整
|
||||
extern "C" {
|
||||
@@ -17,12 +18,14 @@ public:
|
||||
int width;
|
||||
int height;
|
||||
int fps;
|
||||
unsigned char* g_pRgbBuffer; // 处理后数据缓存区
|
||||
|
||||
MindVisionCamera(int cam_id = 0, const std::string& target_color = "red");
|
||||
~MindVisionCamera();
|
||||
|
||||
void set_cam_params();
|
||||
bool set_cam_params();
|
||||
bool read_frame(cv::Mat& frame);
|
||||
bool read_frame_with_color_filter(cv::Mat& frame, cv::Mat& mask, const std::string& target_color);
|
||||
void release();
|
||||
bool switch_color(const std::string& target_color);
|
||||
|
||||
|
||||
@@ -3,17 +3,11 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
// Placeholder for TTL communication class
|
||||
// In a real implementation, you would use a C++ serial library like:
|
||||
// - serial (https://github.com/wjwwood/serial)
|
||||
// - Boost.Asio
|
||||
// - or a system-specific approach
|
||||
|
||||
class TTLCommunicator {
|
||||
public:
|
||||
TTLCommunicator(int baudrate = 115200);
|
||||
TTLCommunicator(const std::string& port_name = "/dev/ttyUSB0", int baudrate = 115200);
|
||||
~TTLCommunicator();
|
||||
|
||||
|
||||
bool connect();
|
||||
void close();
|
||||
bool send_data(const std::string& data);
|
||||
@@ -23,8 +17,9 @@ private:
|
||||
std::string port_name;
|
||||
int baudrate;
|
||||
bool connected;
|
||||
|
||||
// These would be implemented with actual serial communication code
|
||||
|
||||
int serial_fd;
|
||||
|
||||
bool open_serial_port();
|
||||
void close_serial_port();
|
||||
};
|
||||
|
||||
@@ -28,9 +28,9 @@ const float HORIZONTAL_ANGLE_THRESHOLD_RAD = HORIZONTAL_ANGLE_THRESHOLD * CV_PI
|
||||
const float NEARBY_LIGHT_BAR_THRESHOLD = 500.0f; // Light bar merging distance threshold (pixels)
|
||||
const float LIGHT_BAR_IOU_THRESHOLD = 0.05f; // Light bar merging IOU threshold
|
||||
const float ARMOR_DISTANCE_RATIO_MIN = 0.6f; // Armor light bar distance ratio range
|
||||
const float ARMOR_DISTANCE_RATIO_MAX = 3.0f;
|
||||
const float ARMOR_DISTANCE_RATIO_MAX = 4.0f;
|
||||
const float ARMOR_LENGTH_DIFF_RATIO = 0.5f; // Armor light bar length difference ratio
|
||||
const float ARMOR_ANGLE_DIFF_THRESHOLD = 20.0f * CV_PI / 180.0f; // Armor light bar angle difference threshold (radians)
|
||||
const float ARMOR_ANGLE_DIFF_THRESHOLD = 15.0f * CV_PI / 180.0f; // Armor light bar angle difference threshold (radians)
|
||||
|
||||
// Kalman filter parameters
|
||||
const float KF_PROCESS_NOISE = 0.02f; // Process noise covariance
|
||||
|
||||
Reference in New Issue
Block a user