Ask Your Question

liborw's profile - activity

2013-09-23 06:00:13 -0600 commented question OpenCV + Matlab ? ROS: Reading PNG

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

2013-09-23 05:09:04 -0600 commented question OpenCV + Matlab ? ROS: Reading PNG
2013-09-23 05:08:27 -0600 received badge  Editor (source)
2013-09-23 04:23:46 -0600 asked a question 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')
2012-10-10 07:02:15 -0600 asked a question Save 11bit PGM

I'have 11 bit image and want to save it to PGM. However, the saved image's header is "P5 640 480 65535". Is there a way how to change header of the saved PGM from OpenCV?