Der Name des default branch ist ab jetzt für neue Repositories main. The name of the default branch for new repositories is from now on main.

Commit fa625e91 authored by Daniel Müller's avatar Daniel Müller
Browse files

Merge branch 'fix-robot_face_interface' into 'master'

[fix] Make members of RobotFaceInterface class

See merge request !7
parents dd2e50d6 f831893e
......@@ -110,7 +110,6 @@ catkin_python_setup()
add_message_files(
FILES
DisplayImage.msg
DisplayImageFile.msg
)
generate_messages(
......
......@@ -36,7 +36,6 @@
// message callbacks
#include <homer_robot_face/DisplayImage.h> //for stream data
#include <homer_robot_face/DisplayImageFile.h> //for file from harddisk
/**
......@@ -58,7 +57,6 @@ public:
/** @brief callback for sensorMsgs::Images encapsulated in an ImageDisplay msg*/
void callbackImageDisplay(const homer_robot_face::DisplayImage::ConstPtr& image_msg);
/** @brief callback for images from harddisk*/
void callbackImageFileDisplay(const homer_robot_face::DisplayImageFile::ConstPtr& image_msg);
public slots:
/** @brief hide the current image and stop the reset timer*/
......@@ -92,7 +90,7 @@ private:
void rotateAndDrawImage(QPainter* painter, const QImage* toDraw);
/** @brief scale image respectively to max_image_width_ or max_image_height_ and add it to the
* image queue*/
void scaleAndAddImageToQueue(const QImage& image);
//void scaleAndAddImageToQueue(const QImage& image);
/** @brief convert a cv::Mat to a QImage. Supported encodings are CV_8UC4, CV_8UC3 and CV_8UC1*/
QImage cvMatToQImage(const cv::Mat& inMat);
/** @brief actual executive process of image data for painting in the window*/
......
......@@ -101,10 +101,8 @@ private:
ros::Subscriber image_stream_subscriber_;
ros::Subscriber image_stream_show_subscriber_;
ros::Subscriber face_image_stream_show_subscriber_;
ros::Subscriber face_image_display_show_subscriber_;
ros::Subscriber image_subscriber_;
ros::Subscriber image_show_subscriber_;
ros::Subscriber image_file_display_subscriber_;
image_transport::Subscriber image_sub_;
ros::Subscriber image_mat_subscriber;
......
......@@ -39,7 +39,6 @@
// messages to react to
#include <homer_robot_face/DisplayImage.h>
#include <homer_robot_face/DisplayImageFile.h>
#include <ros/callback_queue.h>
#include <ros/package.h>
#include <ros/ros.h>
......@@ -101,7 +100,6 @@ public:
void callbackTextForEmotion(const std_msgs::String::ConstPtr& msg);
void callbackResetAnimation(const std_msgs::String::ConstPtr& msg);
void callbackShowStream(const homer_robot_face::DisplayImage::ConstPtr& image_msg);
void callbackShowImage(const homer_robot_face::DisplayImageFile::ConstPtr& msg);
void callbackShowMatImage(const sensor_msgs::ImageConstPtr& msg);
public slots:
......
uint32 time # display time
string filename # path to the image file that should be displayed
......@@ -130,34 +130,6 @@ void ImageDisplay::rotateAndDrawImage(QPainter* painter, const QImage* toDraw)
painter->restore();
}
inline void ImageDisplay::scaleAndAddImageToQueue(const QImage& image)
{
// we don't want to overfill our queue
if (image_queue_.size() > MAX_QUEUE_SIZE)
{
return;
}
// scale image to the greater value of height or width to fit in widget
std::unique_ptr<QImage> image_ptr;
if (image.height() > image.width())
{
image_ptr = std::make_unique<QImage>(image.scaledToHeight(max_image_height_));
}
else
{
image_ptr = std::make_unique<QImage>(image.scaledToWidth(max_image_width_));
}
// forcing a deep copy
if (!image_ptr->isDetached())
{
image_ptr->detach();
}
image_queue_.push(std::move(image_ptr));
}
/// Convert function from
/// http://asmaloney.com/2013/11/code/converting-between-cvmat-and-qimage-or-qpixmap/
inline QImage ImageDisplay::cvMatToQImage(const cv::Mat& inMat)
......@@ -239,25 +211,11 @@ void ImageDisplay::processImageData(const homer_robot_face::DisplayImage::ConstP
void ImageDisplay::callbackImageDisplay(const homer_robot_face::DisplayImage::ConstPtr& image_msg)
{
// ROS_INFO_STREAM("Received ImageDisplay msg, draw image for " << image_msg->time << "
// seconds.");
ROS_INFO_STREAM("Received ImageDisplay msg, draw image for " << image_msg->time << "seconds.");
processImageData(image_msg);
emit newImageToShow(image_msg->time * 1000); // convert milliseconds to seconds
}
void ImageDisplay::callbackImageFileDisplay(
const homer_robot_face::DisplayImageFile::ConstPtr& image_msg)
{
ROS_INFO_STREAM("Received ImageFileDisplay msg, draw image '"
<< image_msg->filename << "' for " << image_msg->time << " seconds.");
// load a single image
QString image_file = (image_msg->filename).c_str();
QImage image_loaded(image_file);
scaleAndAddImageToQueue(image_loaded);
emit newImageToShow(image_msg->time * 1000); // convert milliseconds to seconds
}
#undef MAX_QUEUE_SIZE
......@@ -61,10 +61,6 @@ void QtRosNode::subscribeTopics()
face_image_stream_show_subscriber_
= node_handle_->subscribe<homer_robot_face::DisplayImage>("/robot_face/ImageDisplay", 10,
&TalkingHead::callbackShowStream, main_window_->getFaceWidget().get());
face_image_display_show_subscriber_
= node_handle_->subscribe<homer_robot_face::DisplayImageFile>(
"/robot_face/ImageFileDisplay", 10, &TalkingHead::callbackShowImage,
main_window_->getFaceWidget().get());
// text output subscribers
text_out_subscriber_
......@@ -94,9 +90,6 @@ void QtRosNode::subscribeTopics()
image_stream_subscriber_
= node_handle_->subscribe<homer_robot_face::DisplayImage>("/robot_face/ImageDisplay", 5,
&ImageDisplay::callbackImageDisplay, main_window_->getImageStream().get());
image_file_display_subscriber_ = node_handle_->subscribe<homer_robot_face::DisplayImageFile>(
"/robot_face/ImageFileDisplay", 10, &ImageDisplay::callbackImageFileDisplay,
main_window_->getImageStream().get());
}
void QtRosNode::quitNow()
......
......@@ -1126,12 +1126,6 @@ void TalkingHead::callbackShowStream(const homer_robot_face::DisplayImage::Const
emit timerChanged(image_msg->time * 1000);
}
void TalkingHead::callbackShowImage(const homer_robot_face::DisplayImageFile::ConstPtr& msg)
{
emit faceCleared();
emit timerChanged(msg->time * 1000);
}
void TalkingHead::callbackShowMatImage(const sensor_msgs::ImageConstPtr& msg)
{
emit faceCleared();
......
......@@ -5,8 +5,9 @@ import rospy
from std_msgs.msg import Header
from sensor_msgs.msg import Image
from homer_robot_face.msg import DisplayImageFile, DisplayImage
from homer_robot_face.msg import DisplayImage
import cv2
from cv_bridge import CvBridge, CvBridgeError
......@@ -14,7 +15,6 @@ class RobotFaceException(Exception):
pass
class RobotFaceInterface:
imageFilePublisher = rospy.Publisher("/robot_face/ImageFileDisplay", DisplayImageFile, queue_size=1)
imagePublisher = rospy.Publisher("/robot_face/ImageDisplay", DisplayImage, queue_size=1)
bridge = CvBridge()
......@@ -27,12 +27,8 @@ class RobotFaceInterface:
:returns: `None`
"""
imageFilePublisher.publish(
DisplayImageFile(
time = displayTime,
filename = path
)
)
cvImage = cv2.imread(path)
RobotFaceInterface.display_image_cv(cvImage)
@staticmethod
def display_image(image, displayTime=1):
......@@ -43,7 +39,7 @@ class RobotFaceInterface:
:returns: `None`
"""
imagePublisher.publish(
RobotFaceInterface.imagePublisher.publish(
DisplayImage(
time = displayTime,
Image = image
......@@ -54,14 +50,14 @@ class RobotFaceInterface:
def display_image_cv(cvImage, displayTime=1):
"""This method displays an image on Lisas face.\
:cvImage: Image as OpenCV Image (i.e. cv2.imread(path, cv2.IMREAD_COLOR))
:cvImage: Image as OpenCV Image (i.e. cv2.imread(path))
:displayTime: Duration in seconds that image should be displayed for
:returns: `None`
"""
image = bridge.cv2_to_imgmsg(cvImage, encoding="passthrough")
image = RobotFaceInterface.bridge.cv2_to_imgmsg(cvImage, encoding="passthrough")
imagePublisher.publish(
RobotFaceInterface.imagePublisher.publish(
DisplayImage(
time = displayTime,
Image = image
......
Markdown is supported
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