Search code examples
pythonmatlabnao-robot

How to get MatLab object to go through sys.argv[1] in python?


I am trying to get the NAO Humanoid Robot to recognize objects. I am using a convolutional neural net (CNN) in MatLab to classify objects that are captured through the Robot. I have written two separate python scripts: One to take a picture through the Robot and also saving it as a .png file, The second to enable the Robot to speak the title of the object via speechProxy (From ALProxy library). The first script is working perfectly and is able to communicate with MatLab as desired. I used the following commands for running the python script, reading the .png that is created as a result, cropping the image, and then classifying it:

system('python "TakePhoto.py path"'); %running the TakePhoto python script
im = imread('object.png path'); %reading the .png file
im = imresize(im,[224 224]); %resizing the .png to the desired dimensions
label = classify(net,im); %classifying the object capture
image(im); %outputting the image in the given dimensions
title(char(label)); %showing the label at the top of the output

This part of my MatLab script is working properly as I am able to classify objects by just running the script and putting an object in the Robot's view. The other script that I have is supposed to enable the Robot to speak the label of the object but I am not exactly sure how to get the python script to speak the label from the MatLab output.

The snippet of my Python code below is what I need for the Robot to speak the label.

speechProxy.say("This object is a " + sys.argv[1])

The issue is now getting the system argument from MatLab. I have searched on the MathWorks website and they said that passing a system argument should be done as follows

system('python','python_script_path',argument) %assuming argument is an object of certain datatype

I have tried this type of syntax with my respective arguments and python scripts/path and I get an error. If you refer to my first snippet of code showing the MatLab script, the syntax for passing the argument would look as follows:

system('python "speakObject.py path"', label);

But this results in an error. Ultimately, I am having problems getting the MatLab script and the second Python script to communicate. How can I get the label classification of the .png to be passed as a system argument to python so that the Robot can say the identity of the object?


Solution

  • You might want to try something like

    strCommand = sprintf('python speakObject.py %s', label);
    system(strCommand);