0

This line from demo.m works fine in MatLab when I run demo.m directly:

save('C:\PATH_TO_MY_FOLDER\boxes.mat', 'boxes');

So when I check the folder, I do indeed find that a file called boxes.mat has been created, which holds a 2D array.

However, when I run demo.m from python (in the code below), Matlab seems to open but boxes.mat doesn't seem to get saved.

import win32com.client
h = win32com.client.Dispatch('matlab.application')
h.Execute ("C:\\PATH_TO_MY_FOLDER\\demo.m")

Am I maybe not successfully running demo.m in the first place? I added the line

fprintf('hello'); 

in demo.m before the line that saves the boxes.mat file, but didn't get that output either. How can I find out for sure that the demo.m is even getting executed from Python? I do see a Matlab button show up in the taskbar for a moment.

The code of demo.m is slightly edited and taken from here:

% This demo shows how to use the software described in our IJCV paper: 
%   Selective Search for Object Recognition,
%   J.R.R. Uijlings, K.E.A. van de Sande, T. Gevers, A.W.M. Smeulders, IJCV 2013
%%
addpath('Dependencies');

fprintf('Demo of how to run the code for:\n');
fprintf('   J. Uijlings, K. van de Sande, T. Gevers, A. Smeulders\n');
fprintf('   Segmentation as Selective Search for Object Recognition\n');
fprintf('   IJCV 2013\n\n');

% Compile anisotropic gaussian filter
if(~exist('anigauss'))
    fprintf('Compiling the anisotropic gauss filtering of:\n');
    fprintf('   J. Geusebroek, A. Smeulders, and J. van de Weijer\n');
    fprintf('   Fast anisotropic gauss filtering\n');
    fprintf('   IEEE Transactions on Image Processing, 2003\n');
    fprintf('Source code/Project page:\n');
    fprintf('   http://staff.science.uva.nl/~mark/downloads.html#anigauss\n\n');
    mex Dependencies/anigaussm/anigauss_mex.c Dependencies/anigaussm/anigauss.c -output anigauss
end

if(~exist('mexCountWordsIndex'))
    mex Dependencies/mexCountWordsIndex.cpp
end

% Compile the code of Felzenszwalb and Huttenlocher, IJCV 2004.
if(~exist('mexFelzenSegmentIndex'))
    fprintf('Compiling the segmentation algorithm of:\n');
    fprintf('   P. Felzenszwalb and D. Huttenlocher\n');
    fprintf('   Efficient Graph-Based Image Segmentation\n');
    fprintf('   International Journal of Computer Vision, 2004\n');
    fprintf('Source code/Project page:\n');
    fprintf('   http://www.cs.brown.edu/~pff/segment/\n');
    fprintf('Note: A small Matlab wrapper was made.\n');
%     fprintf('   
    mex Dependencies/FelzenSegment/mexFelzenSegmentIndex.cpp -output mexFelzenSegmentIndex;
end

%%
% Parameters. Note that this controls the number of hierarchical
% segmentations which are combined.
colorTypes = {'Hsv', 'Lab', 'RGI', 'H', 'Intensity'};
colorType = colorTypes{1}; % Single color space for demo

% Here you specify which similarity functions to use in merging
simFunctionHandles = {@SSSimColourTextureSizeFillOrig, @SSSimTextureSizeFill, @SSSimBoxFillOrig, @SSSimSize};
simFunctionHandles = simFunctionHandles(1:2); % Two different merging strategies

% Thresholds for the Felzenszwalb and Huttenlocher segmentation algorithm.
% Note that by default, we set minSize = k, and sigma = 0.8.
k = 200; % controls size of segments of initial segmentation. 
minSize = k;
sigma = 0.8;

% As an example, use a single image
images = {'000016.jpg'};
%images = {'C:\Users\Public\Pictures\Sample Pictures\Desert.jpg'};
im = imread(images{1});

% Perform Selective Search
[boxes blobIndIm blobBoxes hierarchy] = Image2HierarchicalGrouping(im, sigma, k, minSize, colorType, simFunctionHandles);
boxes = BoxRemoveDuplicates(boxes);

save('C:\work_asaaki\code\SelectiveSearchCodeIJCV\boxes.mat', 'boxes');
4
  • sprintf('hello'); creates a char array hello but does not print anything. Use disp or fprintf! Are you able to run the demo.m via Matlab? Commented May 21, 2014 at 20:36
  • What is the command line output of matlab? Check the return arguments of h.Execute if you don't see any. Commented May 21, 2014 at 20:40
  • Ooops I actually did use sprintf, I edited my question to correct it. Yes I'm able to run demo.m directly via Matlab, as I said in my question it successfully creates boxes.mat. The command line output of matlab is hello. How can I check the return arguments of h.Execute? I tried printing but it gives an error: ??? Error: Unexpected MATLAB operator. Commented May 21, 2014 at 20:57
  • "??? Error: Unexpected MATLAB operator." is the error message created by matlab, that is exactly what I was looking for. Commented May 21, 2014 at 22:18

1 Answer 1

1

You are asking Matlab to run the command 'C:\PATH_TO_MY_FOLDER\demo.m', this is not a valid matlab command, if you enter it to your matlab console you will get the same error message.

What you probably want is:

h.Execute ("cd('C:\\PATH_TO_MY_FOLDER');")
h.Execute ("demo;")

This is what you would do in matlab, change directory and then run it. You could also create a single line using run, but due to relative path in your scripts this will probably not work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.