Converting sensor_msgs/Image unit8[] data to sumable type for computing average brightness
!/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.