Cannot import Image message for rosjava [closed]

asked 2014-12-13 13:24:56 -0500

Robocop87 gravatar image

Hi everyone,

I have gotten rosjava to work with String messages, and I am now trying to make it work with Image messages. Unfortunately, when I try to import Image messages, I get the following error when I build:

package org.ros.message.sensor_msgs does not exist import org.ros.message.sensor_msgs.Image;

Here is my Java code:

import java.awt.image.BufferedImage;
import java.awt.image.ComponentSampleModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.Raster;
import java.awt.image.SampleModel;

import org.ros.message.MessageListener;
import org.ros.message.sensor_msgs.Image;


public class ImageListener implements MessageListener<Image> {
    long time;

    public void onNewMessage(Image img) {
        time = System.currentTimeMillis();
        String cameraName = img.header.frame_id;

        BufferedImage buffImg = messageToBufferedImage(img);
        VideoController.getInstance().receiveNewImage(cameraName, buffImg);    

    public static BufferedImage messageToBufferedImage(Image imgMsg){
        int width = (int) imgMsg.width;
        int height = (int) imgMsg.height;       
        DataBuffer buffer = new DataBufferByte(, width*height);
        SampleModel sampleModel = new ComponentSampleModel(DataBuffer.TYPE_BYTE, width, height, 3, width*3, new int[]{2,1,0});
        Raster raster = Raster.createRaster(sampleModel, buffer, null);
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
        return image;

and my gradle files look like this:

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'

buildscript {
    def rosMavenPath = "$System.env.ROS_MAVEN_PATH".split(':').collect { 'file://' + it }
    def rosMavenRepository = "$System.env.ROS_MAVEN_REPOSITORY"
    repositories {
        rosMavenPath.each { p ->
            maven {
                url p
        maven {
            url rosMavenRepository
    dependencies {
        classpath group: 'org.ros.rosjava_bootstrap', name: 'gradle_plugins', version: '[0.1,0.2)'

apply plugin: 'catkin'
apply plugin: 'eclipse'

allprojects {
    group 'com.github.rosjava.hsmrs_gui'
    group 'org.ros.rosjava_core'
    version = project.catkin.pkg.version

subprojects {
    apply plugin: 'ros-java'
defaultTasks 'tasks'


apply plugin: 'application'
mainClassName = 'org.ros.RosRun'

dependencies {
  compile 'org.ros.rosjava_core:rosjava:[0.1,)'

apply plugin:'java'


  compile 'com.miglayout:miglayout-swing:4.2'

Any idea whats going wrong? Your help is appreciated!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Robocop87
close date 2014-12-15 04:24:37.146499


For the record, you should add org.ros.rosjava_messages:sensor_msgs to your compile dependencies

jubeira gravatar image jubeira  ( 2017-04-11 13:56:24 -0500 )edit