OpenCV + Matlab ? ROS: Reading PNG [closed]

asked Sep 23 '13

liborw gravatar image

updated Sep 23 '13

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')
Preview: (hide)

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-06 08:23:11.751839

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 (Sep 23 '13)edit
liborw gravatar imageliborw (Sep 23 '13)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 (Sep 23 '13)edit

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

liborw gravatar imageliborw (Sep 23 '13)edit

Hmm then my ideas are limited so far :)

StevenPuttemans gravatar imageStevenPuttemans (Sep 23 '13)edit