Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV + Matlab ? ROS: Reading PNG

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.

OpenCV + Matlab ? ROS: Reading PNG

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!

OpenCV + Matlab ? ROS: Reading PNG

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')

OpenCV + Matlab ? ROS: Reading PNG

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')