8 #include <iCub/ctrl/math.h> 9 #include <opencv2/core/core.hpp> 10 #include <opencv2/core/cuda.hpp> 11 #include <opencv2/core/eigen.hpp> 12 #include <opencv2/imgproc/imgproc.hpp> 13 #include <opencv2/cudaimgproc.hpp> 14 #include <opencv2/cudawarping.hpp> 15 #include <yarp/eigen/Eigen.h> 16 #include <yarp/math/Math.h> 17 #include <yarp/os/Time.h> 21 using namespace Eigen;
27 using yarp::sig::Vector;
28 using yarp::sig::ImageOf;
29 using yarp::sig::PixelRgb;
33 const int img_width,
const int img_height,
34 const int num_particles,
35 const double resample_ratio) :
37 img_width_(img_width),
38 img_height_(img_height),
39 num_particles_(num_particles),
40 resample_ratio_(resample_ratio)
46 cuda_hog_->setDescriptorFormat(cuda::HOG::DESCR_FORMAT_ROW_BY_ROW);
73 prediction_->getExogenousModel().setProperty(
"ICFW_INIT");
94 ImageOf<PixelRgb>* tmp_imgin = YARP_NULLPTR;
96 if (tmp_imgin != YARP_NULLPTR)
107 measurement = cvarrToMat(
img_in_.getIplImage());
108 cuda_img.upload(measurement);
110 cuda::cvtColor(cuda_img, cuda_img_alpha, COLOR_BGR2BGRA, 4);
111 cuda_hog_->compute(cuda_img_alpha, descriptors_cam_cuda);
112 descriptors_cam_cuda.download(descriptors_cam_left);
115 if (getFilteringStep() != 0)
120 correction_->getVisualObservationModel().setProperty(
"VP_PARAMS");
131 std::cout <<
"Step: " << getFilteringStep() << std::endl;
132 std::cout <<
"Neff: " << resampling_->neff(
cor_weight_) << std::endl;
135 std::cout <<
"Resampling!" << std::endl;
142 res_particle, res_weight,
198 estimates_out.resize(7);
199 toEigen(estimates_out) = out_particle.cast<
double>();
211 return this->yarp().attachAsServer(source);
217 std::cout <<
"Opening RPC command port." << std::endl;
220 std::cerr <<
"Cannot open the RPC command port." << std::endl;
225 std::cerr <<
"Cannot attach the RPC command port." << std::endl;
228 std::cout <<
"RPC command port opened and attached. Ready to recieve commands!" << std::endl;
260 return skip(what_step, status);
267 return correction_->getVisualObservationModel().setProperty(
"VP_ANALOGS_ON");
269 return correction_->getVisualObservationModel().setProperty(
"VP_ANALOGS_OFF");
275 std::vector<std::string> info;
277 info.push_back(
"<| Information about Visual SIR Particle Filter |>");
278 info.push_back(
"<| The Particle Filter is " + std::string(isRunning() ?
"not " :
"") +
"running |>");
279 info.push_back(
"<| Filtering step: " + std::to_string(getFilteringStep()) +
" |>");
280 info.push_back(
"<| Using " +
cam_sel_ +
" camera images |>");
281 info.push_back(
"<| Using " + std::to_string(
num_particles_) +
" particles |>");
285 info.insert(info.end(), est_ext_info.begin(), est_ext_info.end());
293 if (method ==
"mean")
299 else if (method ==
"smean")
305 else if (method ==
"wmean")
311 else if (method ==
"emean")
317 else if (method ==
"mode")
323 else if (method ==
"smode")
329 else if (method ==
"wmode")
335 else if (method ==
"emode")
Eigen::MatrixXf pred_particle_
bool skip_step(const std::string &what_step, const bool status) override
Enable/Disable skipping the filtering step specified in what_step.
bool reset_filter() override
Reset the visual SIR particle filter.
Eigen::VectorXf pred_weight_
bool run_filter() override
Initialize and run the visual SIR particle filter.
cv::Ptr< cv::cuda::HOG > cuda_hog_
void getResult() override
yarp::os::ConstString cam_sel_
bool use_analogs(const bool status) override
Use/Don't use the analog values from the right hand to correct the finger poses.
void filteringStep() override
std::vector< std::string > get_info() override
Get information about recursive Bayesian filter, like it's status, the available methods, and the current one in use, to extract the state estimate from the particle set.
yarp::os::Port port_rpc_command_
bool quit() override
Gently close the application, deallocating resources.
VisualSIS(const yarp::os::ConstString &cam_sel, const int img_width, const int img_height, const int num_particles, const double resample_ratio)
yarp::sig::ImageOf< yarp::sig::PixelRgb > img_in_
bool attach(yarp::os::Port &source)
bfl::EstimatesExtraction estimate_extraction_
Eigen::VectorXf cor_weight_
Eigen::MatrixXf cor_particle_
bool set_estimates_extraction_method(const std::string &method) override
Change the current method to extract the state estimates from the particle set.
yarp::os::BufferedPort< yarp::sig::Vector > port_estimates_out_
bool set_mobile_average_window(const int16_t window) override
Change the window size of mobile averages for estimates extraction.
unsigned int descriptor_length_
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > port_image_in_
void initialization() override
bool stop_filter() override
Stop and reset the SIR particle filter.