OpenCV + Matlab ? ROS: Reading PNG

asked 2013-09-23 04:23:46 -0500

liborw gravatar image

updated 2013-09-23 09:34:48 -0500

I have a simple application that reads an image process it and prints some output to stdout. When I run it normally it works fine. We need to work with the output in Matlab so I have write simple Matlab wrapper that reads the stdout from the app and process it.

The problem is that when the app is called from Matlab I can't read PNG files.

I use OpenCV from ROS Hydro by the way.

$ cat dummy.cpp 
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>


int main(int argc, char *argv[])
{
    cv::Mat image;
    image = cv::imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);

    if (!image.data) {
        printf("FAIL!\n");
    } else {
        printf("OK\n");
    }

    return 0;
}

Example:

$ ./dummy 001_rgb.png 
OK

$ matlab 
>> [s,r] = system('./dummy 001_rgb.png') 
s =
     0
r =
FAIL!

As I can't answer my own questions (at least not now) here is the solution:

Matlab uses different version of the OpenCV library. So the LD_LIBRARY_PATH needs to be changed to target the ROS version of the OpenCV:

system('LD_LIBRARY_PATH=/opt/ros/hydro/lib ./dummy 001_rgb.png')
edit retag flag offensive close merge delete

Comments

Hmm I guess you will have to share your wrapper code and dummy source code if you want us to help you find out what goes wrong. Just telling that the wrapper cannot read PNG files can have thousands of reasons ...

StevenPuttemans gravatar imageStevenPuttemans ( 2013-09-23 04:50:55 -0500 )edit
liborw gravatar imageliborw ( 2013-09-23 05:09:04 -0500 )edit

Actually I do not think that using the system command will actually work like you desire. I think you need to create a propper matlab wrapper, like mentioned here.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-09-23 05:45:36 -0500 )edit

It works pretty well with other image types, pgm for example.

liborw gravatar imageliborw ( 2013-09-23 06:00:13 -0500 )edit

Hmm then my ideas are limited so far :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-09-23 06:01:29 -0500 )edit