ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

working with cmvision/Blobs

asked 2014-08-12 09:36:19 -0600

ghanimmukhtar gravatar image

updated 2014-08-12 18:04:27 -0600

hi, I am trying to work with cmvision/Blobs topic "message" and when I use in my code cmvision/Blobs.x it gives me an error, can anyone please show me how to access the elements of Blobs (x,y in particular)?


Here is the code:

#include "ros/ros.h"
#include <geometry_msgs/Twist.h>
#include "cmvision/Blobs.h"
#include <turtlesim/Pose.h>

using namespace std;

ros::Publisher pub_msg;
geometry_msgs::Twist cmd_msg;
cmvision::Blobs lastobjectpose;
turtlesim::Pose lastFollowerPose;

void fblobCallback(cmvision::Blobs object_pose)

void fposeCallback(turtlesim::Pose follower_pose)

int main (int argc, char** argv)
    //ROS Initialization
    ros::init(argc, argv, "follower_leader");
    ROS_INFO("Node follower_leader Connected to roscore");
    ros::NodeHandle n ("~");
    ros::Subscriber pose_sub_object = n.subscribe<cmvision::Blobs>("/blobs",1,fblobCallback);
    ros::Subscriber pose_sub_follower = n.subscribe<turtlesim::Pose>("follower_pose",1,fposeCallback);

    pub_msg = n.advertise<geometry_msgs::Twist>("follower_velocity",1);
    ros::Rate rate(10);
    ROS_INFO("SPINNING @ 10Hz");

    while (ros::ok()){
        double d = 0;
    d = sqrt(   pow(lastobjectpose.x-lastFollowerPose.x,2)
            + pow(lastobjectpose.y-lastFollowerPose.y,2) ) ;
    double dtheta = 0.0 ;
    if( d>0.01 ) {
        dtheta =   atan2(lastobjectpose.y-lastFollowerPose.y,
        - lastFollowerPose.theta ;

        cmd_msg.linear.x = 0.2*d;
        cmd_msg.angular.z = 4*dtheta;}else{cmd_msg.linear.x = 0;
        cmd_msg.angular.z = 0;}

    ROS_INFO("ROS-Node Terminated\n");

And here is the error i receive when i do "catkin_make":

Base path: /home/ghanim/catkin_ws
Source space: /home/ghanim/catkin_ws/src
Build space: /home/ghanim/catkin_ws/build
Devel space: /home/ghanim/catkin_ws/devel
Install space: /home/ghanim/catkin_ws/install
#### Running command: "make cmake_check_build_system" in "/home/ghanim/catkin_ws/build"
#### Running command: "make -j2 -l2" in "/home/ghanim/catkin_ws/build"
[  0%] [  0%] Built target std_msgs_generate_messages_py
Built target std_msgs_generate_messages_cpp
[  0%] Built target std_msgs_generate_messages_lisp
[ 18%] Built target colorgui
[ 25%] Building CXX object color_follower/CMakeFiles/color_follower_node.dir/src/color_follower_node.cpp.o
[ 31%] Built target follower_leader_node
[ 43%] Built target cmvision_generate_messages_cpp
[ 62%] Built target cmvision_generate_messages_py
[ 75%] Built target cmvision_generate_messages_lisp
[ 75%] Built target cmvision_gencpp
[ 75%] Built target cmvision_generate_messages
[100%] Built target cmvision
/home/ghanim/catkin_ws/src/color_follower/src/color_follower_node.cpp: In function ‘int main(int, char**)’:
/home/ghanim/catkin_ws/src/color_follower/src/color_follower_node.cpp:60:33: error: ‘cmvision::Blobs’ has no member named ‘x’
/home/ghanim/catkin_ws/src/color_follower/src/color_follower_node.cpp:61:39: error: ‘cmvision::Blobs’ has no member named ‘y’
/home/ghanim/catkin_ws/src/color_follower/src/color_follower_node.cpp:64:36: error: ‘cmvision::Blobs’ has no member named ‘y’
/home/ghanim/catkin_ws/src/color_follower/src/color_follower_node.cpp:65:39: error: ‘cmvision::Blobs’ has no member named ‘x’
make[2]: *** [color_follower/CMakeFiles/color_follower_node.dir/src/color_follower_node.cpp.o] Error 1
make[1]: *** [color_follower/CMakeFiles/color_follower_node.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed
edit retag flag offensive close merge delete



Please update your question with the error message you're getting, and the code that produces it.

Dan Lazewatsky gravatar image Dan Lazewatsky  ( 2014-08-12 10:53:30 -0600 )edit

When adding code, please don't create an answer. I moved the code to your original question, and deleted the answer you created.

jarvisschultz gravatar image jarvisschultz  ( 2014-08-12 18:05:39 -0600 )edit

okay and thanks

ghanimmukhtar gravatar image ghanimmukhtar  ( 2014-08-13 03:45:29 -0600 )edit

2 Answers

Sort by » oldest newest most voted

answered 2014-08-12 16:21:31 -0600

ahubers gravatar image

Here is the cmvision/Blobs message structure:

std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
uint32 image_width
uint32 image_height
uint32 blob_count
cmvision/Blob[] blobs
  string name
  uint32 red
  uint32 green
  uint32 blue
  uint32 area
  uint32 x
  uint32 y
  uint32 left
  uint32 right
  uint32 top
  uint32 bottom

When you access your cmvision::Blobs struct like so pow(lastobjectpose.x-lastFollowerPose.x,2), you are implying that the Blobs message type has some x member. However, the x and y that you are looking for are in actuality in lastobjectpose.blobs[some_index].x and so it goes for y. Hence it might make sense for you to instead loop through lastobjectpose.blobs, using lastobjectpose.blob_count as your bound, i.e,

for (i = 0; i < lastobjectpose.blob_count; i++) {
  //Do your stuff.
edit flag offensive delete link more


Thanks very much it is compiling now, i have another question though how can I access the image_width and height ?

ghanimmukhtar gravatar image ghanimmukhtar  ( 2014-08-13 03:46:45 -0600 )edit

I'm not much of a C++ person, but I believe you can think of a message in your code as you do a struct. Since image_width and image_height are direct members of this message, you can write lastobjectpose.image_width and lastobjectpose.image_height, respectively.

ahubers gravatar image ahubers  ( 2014-08-13 11:32:56 -0600 )edit

thanks very much actually i have done this way and yeah it is working :)

ghanimmukhtar gravatar image ghanimmukhtar  ( 2014-08-13 15:13:12 -0600 )edit

answered 2014-08-13 05:58:32 -0600

Mobile_robot gravatar image

Hello, I used this code to have the access to the CMVISION's Blobs, I remind you that Blobs is a type of the message that includes another message called Blob, And also in my code I just used the FIRST Blob (which is the bigger one in size) , so you can modify as you want.

This is your callback function.

if (msg1->blob_count > 0){
    // If you want to access to ALL Blobs
    //for (int i = 0; i < msg1->blob_count; i++){

    //This is for the case that you want to catch a Blob with some size limitation.
    //if(msg1->blobs[i].right - msg1->blobs[i].left > 7 || msg1->blobs[i].top - msg1->blobs[i].bottom > 7   )
        X = msg1->blobs[0].x ;
        Y = msg1->blobs[0].y ;


edit flag offensive delete link more


yeah i basically used the same, thanks

ghanimmukhtar gravatar image ghanimmukhtar  ( 2014-08-13 15:22:13 -0600 )edit

Question Tools

1 follower


Asked: 2014-08-12 09:36:19 -0600

Seen: 937 times

Last updated: Aug 13 '14