Commit c7a6595a authored by Fernando Herrero's avatar Fernando Herrero
Browse files

Load filter adds 2 points with bound values, so new points can be added. Show color sample in list

parent e0d3baa3
......@@ -31,7 +31,7 @@
// [publisher subscriber headers]
#include <iri_blob_detector/blob_array.h>
#include <camera_info_manager/camera_info_manager.h>
#include <image_transport/image_transport.h>
//#include <image_transport/image_transport.h>
// Uncomment to use the openCV <-> ROS bridge
//#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/Image.h>
......@@ -69,9 +69,7 @@ class ColorCalibrationAlgNode : public algorithm_base::IriBaseAlgorithm<ColorCal
void blobs_mutex_exit(void);
std::vector<TBlob> blobs;
//image_transport::CameraSubscriber segmented_image_subscriber_;
ros::Subscriber segmented_img_subscriber_;
//void segmented_image_callback(const sensor_msgs::Image::ConstPtr& msg,const sensor_msgs::CameraInfoConstPtr& info);
void segmented_image_callback(const sensor_msgs::Image::ConstPtr& msg);
pthread_mutex_t segmented_image_mutex_;
void segmented_image_mutex_enter(void);
......@@ -79,9 +77,7 @@ class ColorCalibrationAlgNode : public algorithm_base::IriBaseAlgorithm<ColorCal
sensor_msgs::Image segmented_image;
bool segmented_image_received;
//image_transport::CameraSubscriber original_image_subscriber_;
ros::Subscriber original_img_subscriber_;
//void original_image_callback(const sensor_msgs::Image::ConstPtr& msg,const sensor_msgs::CameraInfoConstPtr& info);
void original_image_callback(const sensor_msgs::Image::ConstPtr& msg);
pthread_mutex_t original_image_mutex_;
void original_image_mutex_enter(void);
......@@ -91,7 +87,6 @@ class ColorCalibrationAlgNode : public algorithm_base::IriBaseAlgorithm<ColorCal
// Uncomment to use the openCV <-> ROS bridge
//cv_bridge::CvImagePtr cv_image_;
image_transport::ImageTransport it;
// [service attributes]
......@@ -138,6 +133,7 @@ class ColorCalibrationAlgNode : public algorithm_base::IriBaseAlgorithm<ColorCal
void save_params(const std::string &filename);
void get_color_id(std::string &color_id);
void set_color_id(const std::string &color_id);
/**
* \brief Destructor
*
......
......@@ -3,8 +3,7 @@
#include <fstream>
ColorCalibrationAlgNode::ColorCalibrationAlgNode(MainGui *gui) :
algorithm_base::IriBaseAlgorithm<ColorCalibrationAlgorithm>(),
it(this->public_node_handle_)
algorithm_base::IriBaseAlgorithm<ColorCalibrationAlgorithm>()
{
//init class attributes if necessary
this->loop_rate_ = 10;//in [Hz]
......@@ -17,11 +16,9 @@ ColorCalibrationAlgNode::ColorCalibrationAlgNode(MainGui *gui) :
this->blobs_subscriber_ = this->public_node_handle_.subscribe("blobs", 1, &ColorCalibrationAlgNode::blobs_callback, this);
pthread_mutex_init(&this->blobs_mutex_,NULL);
//this->segmented_image_subscriber_ = this->it.subscribeCamera("segmented_image/image_raw", 1, &ColorCalibrationAlgNode::segmented_image_callback, this);
this->segmented_img_subscriber_ = this->public_node_handle_.subscribe("segmented_image/image_raw", 1, &ColorCalibrationAlgNode::segmented_image_callback, this);
pthread_mutex_init(&this->segmented_image_mutex_,NULL);
//this->original_image_subscriber_ = this->it.subscribeCamera("original_image/image_raw", 1, &ColorCalibrationAlgNode::original_image_callback, this);
this->original_img_subscriber_ = this->public_node_handle_.subscribe("original_image/image_raw", 1, &ColorCalibrationAlgNode::original_image_callback, this);
pthread_mutex_init(&this->original_image_mutex_,NULL);
this->original_image_received=false;
......
......@@ -144,6 +144,8 @@ void MainGui::on_image_mousePressed(QPoint &point)
// get the color of the pixel
this->node->get_rgb_pixel(point.y(),point.x(),R,G,B);
this->node->get_hsv_pixel(point.y(),point.x(),H,S,V);
// add the point to the
this->ui->pixel_list->insertRow(this->ui->pixel_list->rowCount());
item_text.setNum(R);
......@@ -152,6 +154,11 @@ void MainGui::on_image_mousePressed(QPoint &point)
this->ui->pixel_list->setItem(this->ui->pixel_list->rowCount()-1,1,new QTableWidgetItem(item_text));
item_text.setNum(B);
this->ui->pixel_list->setItem(this->ui->pixel_list->rowCount()-1,2,new QTableWidgetItem(item_text));
this->ui->pixel_list->setItem(this->ui->pixel_list->rowCount()-1,3,new QTableWidgetItem());
QColor c = QColor(R,G,B);
this->ui->pixel_list->item(this->ui->pixel_list->rowCount()-1, 3)->setBackground(c);
this->ui->pixel_list->scrollToBottom();
// update the filter coefficients
this->node->add_pixel_filter(H,S,V);
......@@ -205,6 +212,70 @@ void MainGui::on_load_params_pressed(void)
this->node->load_params(yaml_file.toUtf8().constData());
this->ui->pixel_list->clearContents();
this->ui->pixel_list->setRowCount(0);
unsigned int h_center,h_window,s_center,s_window,v_center,v_window;
this->node->get_hsv_filter(h_center,h_window,s_center,s_window,v_center,v_window);
unsigned int H,S,V;
unsigned char R,G,B;
QString item_text;
QColor c;
H = h_center-h_window/2;
S = s_center-s_window/2;
V = v_center-v_window/2;
c.setHsv(H,S,V);
R = c.red();
G = c.green();
B = c.blue();
//this->node->hsv_to_rgb(R,G,B, H,S,V);
this->ui->pixel_list->insertRow(this->ui->pixel_list->rowCount());
item_text.setNum(R);
this->ui->pixel_list->setItem(this->ui->pixel_list->rowCount()-1,0,new QTableWidgetItem(item_text));
item_text.setNum(G);
this->ui->pixel_list->setItem(this->ui->pixel_list->rowCount()-1,1,new QTableWidgetItem(item_text));
item_text.setNum(B);
this->ui->pixel_list->setItem(this->ui->pixel_list->rowCount()-1,2,new QTableWidgetItem(item_text));
this->ui->pixel_list->setItem(this->ui->pixel_list->rowCount()-1,3,new QTableWidgetItem());
c = QColor(R,G,B);
this->ui->pixel_list->item(this->ui->pixel_list->rowCount()-1, 3)->setBackground(c);
this->ui->pixel_list->scrollToBottom();
this->node->add_pixel_filter(H,S,V);
H = h_center+h_window/2;
S = s_center+s_window/2;
V = v_center+v_window/2;
c.setHsv(H,S,V);
R = c.red();
G = c.green();
B = c.blue();
//this->node->hsv_to_rgb(R,G,B, H,S,V);
this->ui->pixel_list->insertRow(this->ui->pixel_list->rowCount());
item_text.setNum(R);
this->ui->pixel_list->setItem(this->ui->pixel_list->rowCount()-1,0,new QTableWidgetItem(item_text));
item_text.setNum(G);
this->ui->pixel_list->setItem(this->ui->pixel_list->rowCount()-1,1,new QTableWidgetItem(item_text));
item_text.setNum(B);
this->ui->pixel_list->setItem(this->ui->pixel_list->rowCount()-1,2,new QTableWidgetItem(item_text));
this->ui->pixel_list->setItem(this->ui->pixel_list->rowCount()-1,3,new QTableWidgetItem());
c = QColor(R,G,B);
this->ui->pixel_list->item(this->ui->pixel_list->rowCount()-1, 3)->setBackground(c);
this->ui->pixel_list->scrollToBottom();
this->node->add_pixel_filter(H,S,V);
this->show_filter_params();
this->node->update_filter();
}
......
......@@ -318,14 +318,26 @@
<bool>true</bool>
</property>
<property name="columnCount">
<number>3</number>
<number>4</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>70</number>
</attribute>
<attribute name="horizontalHeaderHighlightSections">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>57</number>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderHighlightSections">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>Red</string>
......@@ -341,6 +353,11 @@
<string>Blue</string>
</property>
</column>
<column>
<property name="text">
<string>Sample</string>
</property>
</column>
</widget>
<widget class="QLineEdit" name="color_id_value">
<property name="geometry">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment