Skip to content

How can I view the sensor_msgs.Image data as an image? #62

Answered by aler9
Maverobot asked this question in Q&A
Discussion options

You must be logged in to vote

Here's a working example, that works with the rgba encoding (if it's different, you need to convert it)

package main

import (
	"image"
	"bytes"
	"image/jpeg"
	"io/ioutil"
	"time"

	"github.com/aler9/goroslib"
	"github.com/aler9/goroslib/pkg/msgs/sensor_msgs"
)

func main() {
	// create a node and connect to the master
	n, err := goroslib.NewNode(goroslib.NodeConf{
		Name:          "goroslib_sub",
		MasterAddress: "127.0.0.1:11311",
	})
	if err != nil {
		panic(err)
	}
	defer n.Close()

	onMessage := func(msg *sensor_msgs.Image) {
		if msg.Encoding != "rgba" {
			panic("not rgba")
		}

		r := image.Rectangle{image.Point{0, 0}, image.Point{int(msg.Width), int(msg.Height)}}
		i := &image.RGBA

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Maverobot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants