#pragma once #include #include #include #include #include #include namespace py = pybind11; struct Event { Event(int x, int y, double t, int polarity) : x_(x), y_(y), t_(t), polarity_(polarity) {} bool operator<(Event& other) { return t_ < other.t_; } int x_, y_; double t_; int polarity_; }; /* * The EventSimulator takes as input a sequence of stamped images, * assumed to be sampled at a "sufficiently high" framerate, * and simulates the principle of operation of an idea event camera * with a constant contrast threshold C. * Pixel-wise intensity values are linearly interpolated in time. * * The pixel-wise voltages are reset with the values from the first image * which is passed to the simulator. */ class EventSimulator { public: EventSimulator(float contrast_threshold_pos, float contrast_threshold_neg, float refractory_period, float log_eps, bool use_log_img); Eigen::MatrixXd generateFromFolder(std::string image_folder, std::string timestamps_file_path); Eigen::MatrixXd generateFromVideo(std::string video_path, std::string timestamps_file_path); Eigen::MatrixXd generateFromStampedImageSequence(std::vector image_paths, std::vector timestamps); Eigen::MatrixXd generateEventFromCVImage(py::array_t input_array, double time); void initialise(py::array_t input_array, double time); void setParameters(float contrast_threshold_pos, float contrast_threshold_neg, float refractory_period, float log_eps, bool use_log_img) { contrast_threshold_pos_ = contrast_threshold_pos; contrast_threshold_neg_ = contrast_threshold_neg; refractory_period_ = refractory_period; log_eps_ = log_eps; use_log_img_ = use_log_img; } cv::Mat pyArrayToCvMat(py::array_t input_array) { // Accessing the NumPy array data py::buffer_info buf_info = input_array.request(); float* ptr = static_cast(buf_info.ptr); // Assuming a 3-channel image, you may need to adjust channels and sizes accordingly return cv::Mat(buf_info.shape[0], buf_info.shape[1], CV_32F, ptr).clone(); } private: void init(const cv::Mat &img, double time); Eigen::MatrixXd vec_to_eigen_matrix(std::vector& events_vec) { Eigen::MatrixXd events(events_vec.size(), 4); for (int i=0; i& events); void read_directory_from_path(const std::string& name, std::vector& v) { boost::filesystem::path p(name); boost::filesystem::directory_iterator start(p); boost::filesystem::directory_iterator end; auto path_leaf_string = [](const boost::filesystem::directory_entry& entry) -> std::string {return entry.path().string();}; std::transform(start, end, std::back_inserter(v), path_leaf_string); std::sort(v.begin(), v.end()); } float contrast_threshold_pos_; float contrast_threshold_neg_; float refractory_period_; float log_eps_; bool use_log_img_; bool is_initialized_; double current_time_; cv::Mat ref_values_; cv::Mat last_img_; cv::Mat last_event_timestamp_; int image_height_; int image_width_; };