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

Converting sensor_msgs/Image unit8[] data to sumable type for computing average brightness

asked 2019-09-02 16:38:16 -0500

Marseiliais gravatar image

updated 2019-09-02 16:43:53 -0500

!/usr/bin/env python

from sensor_msgs.msg import Image
import rospy

average =0.0
def ImageCallback(image):
    global average 
    suma=0.0
    average=0.0
    #print(type(image.data[200]),"--------",image.data[200])
    for i in range(len(image.data)):
        print(type(image.data[i]),"--------",image.data[i])
    #average = suma/len(image.data)






if __name__=='__main__':
    while not rospy.is_shutdown():
        try:
            rospy.init_node('wezel',anonymous=True)
            image_subscriber = rospy.Subscriber('/camera/rgb/image_raw',Image,ImageCallback)
            print ("Average brightness is {}".format(average))
            rospy.spin()
        except:
            pass

Above code gives me as na output 'randomly': (type 'str', '--------', 'p') (type 'str', '--------', '8') (type 'str', '--------', '\xb2')

Am i using data from sensor_msg.msg/Image properly? How to convert this array to numbers, to compute average brightness f.e.?

When im using comand

rostopic echo /camera/rgb/image_raw

im getting numbers as an output.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-09-04 06:54:19 -0500

Choco93 gravatar image

I would recommend you take a look at here, use cv_bridge to read image as rgb, then you can play around with pixel values.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-09-02 16:38:16 -0500

Seen: 560 times

Last updated: Sep 04 '19