Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adds rostopic support to vision_gui #135

Open
wants to merge 1 commit into
base: indigo-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vision_stack/vision_gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ FIND_PACKAGE(Qt4 REQUIRED)
find_package( OpenCV REQUIRED )
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(-DQT_NO_KEYWORDS)
include_directories(include/${PROJECT_NAME}/ ${CMAKE_CURRENT_BINARY_DIR})
include_directories(include/${PROJECT_NAME}/ ${CMAKE_CURRENT_BINARY_DIR} task_bouy/include/ task_marker/include/)

##############################################################################
# Ros Initialisation
Expand Down
13 changes: 13 additions & 0 deletions vision_stack/vision_gui/include/ImageNew/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#include <cstring>
#include <sstream>
#include <QtCore>
#include <ros/ros.h>
#include <ros/network.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>

class MyLabel : public QLabel
{

Expand Down Expand Up @@ -59,6 +64,8 @@ public Q_SLOTS:
void on_startCamera_clicked();
void on_pauseCamera_clicked();
void on_closeCamera_clicked();
void on_submitRosTopic_clicked();

// slider callbacks
void on_HValue_slider_valueChanged(int value);
void on_SValue_slider_valueChanged(int value);
Expand All @@ -67,6 +74,7 @@ public Q_SLOTS:
void on_SThreshValue_slider_valueChanged(int value);
void on_VThreshValue_slider_valueChanged(int value);
void on_colorImage_mouseDoubleClickEvent(QMouseEvent * ev);
void imageCallBack(const sensor_msgs::ImageConstPtr &_msg);

/******** Filters ****************/

Expand Down Expand Up @@ -119,12 +127,17 @@ public Q_SLOTS:
Ui::MainWindow *ui;
bool camera_opend,video_being_processed;
cv::Scalar start,end;
// ros::NodeHandle n;
// image_transport::ImageTransport it(n);
// image_transport::Subscriber sub;
// const sensor_msgs::ImageConstPtr &msg;
std::string fileName;
QTimer *timer;
cv::Mat colorImage,displayImage,thImage,binaryImage,camImage;
cv::VideoCapture cam;
cv::Size image_size;
MyLabel *colorLabel;
// sensor_msgs::ImageConstPtr msg;
cv::Vec3b vec;
bool getNextFrame(cv::Mat &img);
void displayImages();
Expand Down
4 changes: 4 additions & 0 deletions vision_stack/vision_gui/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
<url>http://ros.org/wiki/ImageNew</url>
<depend package="roscpp"/>
<depend package="cv_bridge"/>
<depend package="image_transport"/>
<depend package="blob"/>
<depend package="resources"/>
<depend package="actionlib"/>
<depend package="actionmsg"/>
<depend package="kraken_msgs"/>

</package>

Expand Down
48 changes: 47 additions & 1 deletion vision_stack/vision_gui/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
#include <fstream>
#include <stdio.h>
#include <stdlib.h>

#include <blob/blob.h>
#include <blob/BlobResult.h>
#include <blob/BlobContour.h>
#include <blob/BlobLibraryConfiguration.h>
#include <blob/BlobOperators.h>
#include <blob/ComponentLabeling.h>
#include <blob/BlobProperties.h>
#include <ros/ros.h>
#include <ros/network.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>

QString fn_video;

Expand Down Expand Up @@ -76,6 +79,7 @@ MyWindow::MyWindow(QWidget *parent) :
filter_arg2 = B_LESS;
filter_arg4 = B_INCLUDE;
filter_arg5_area = 500;

}

void MyWindow::setThresh()
Expand Down Expand Up @@ -502,6 +506,48 @@ void MyWindow::on_closeCamera_clicked()
ui->closeCamera->setEnabled(false);
}

void MyWindow::on_submitRosTopic_clicked()
{
QString topic = ui->textRosTopic->text();
try
{
int argc = 0;
ros::init(argc,NULL,"vision_gui_rostopic");
ros::NodeHandle n;
std::cout <<"Correct ROS Topic input given."<< std::endl;
image_transport::ImageTransport it(n);
image_transport::Subscriber sub;
while(ros::ok())
{
sub = it.subscribe(topic.toUtf8().constData(), 1, &MyWindow::imageCallBack, this);
std::cout <<"ROS Loop"<< std::endl;
}
ros::shutdown();
}
catch (ros::InvalidNameException& e)
{
std::cout <<"Incorrect ROS Topic input given : "<<topic.toUtf8().constData()<< std::endl;
ros::shutdown();
}
}

void MyWindow::imageCallBack(const sensor_msgs::ImageConstPtr &_msg)
{
try
{
cv_bridge::CvImagePtr imagePtr = cv_bridge::toCvCopy(_msg, "bgr8");
std::cout <<"ROS Topic Subscription Callback." << std::endl;
camImage = imagePtr->image;
source_from_log = true;
video_being_processed = true;
setThresh();
}
catch (cv_bridge::Exception& e)
{
std::cout <<"ROS Topic input given : Could not convert from" << _msg->encoding.c_str() << std::endl;
}
}

void MyWindow::on_HValue_slider_valueChanged(int value)
{
std::ostringstream str;
Expand Down
13 changes: 13 additions & 0 deletions vision_stack/vision_gui/src/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#include <cstring>
#include <sstream>
#include <QtCore>
#include <ros/ros.h>
#include <ros/network.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>

class MyLabel : public QLabel
{

Expand Down Expand Up @@ -59,6 +64,8 @@ public Q_SLOTS:
void on_startCamera_clicked();
void on_pauseCamera_clicked();
void on_closeCamera_clicked();
void on_submitRosTopic_clicked();

// slider callbacks
void on_HValue_slider_valueChanged(int value);
void on_SValue_slider_valueChanged(int value);
Expand All @@ -67,6 +74,7 @@ public Q_SLOTS:
void on_SThreshValue_slider_valueChanged(int value);
void on_VThreshValue_slider_valueChanged(int value);
void on_colorImage_mouseDoubleClickEvent(QMouseEvent * ev);
void imageCallBack(const sensor_msgs::ImageConstPtr &msg);

/******** Filters ****************/

Expand Down Expand Up @@ -119,13 +127,18 @@ public Q_SLOTS:
Ui::MainWindow *ui;
bool camera_opend,video_being_processed;
cv::Scalar start,end;
// ros::NodeHandle n;
// image_transport::ImageTransport it(n);
// image_transport::Subscriber sub;
// const sensor_msgs::ImageConstPtr &msg;
std::string fileName;
QTimer *timer;
cv::Mat colorImage,displayImage,thImage,binaryImage,camImage;
cv::VideoCapture cam;
cv::Size image_size;
MyLabel *colorLabel;
cv::Vec3b vec;
// sensor_msgs::ImageConstPtr msg;
bool getNextFrame(cv::Mat &img);
void displayImages();
void setThresh();
Expand Down
19 changes: 19 additions & 0 deletions vision_stack/vision_gui/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<string>Open Video</string>
</property>
</item>
<item>
<property name="text">
<string>Open Bag</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
Expand Down Expand Up @@ -108,6 +113,20 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLineEdit" name="textRosTopic">
<property name="text">
<string>/kraken/front_camera/buoy_image</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="submitRosTopic">
<property name="text">
<string>Submit ROS topic</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down