我正在尝试让NAO人形机器人识别物体。我正在使用MatLab中的卷积神经网络(CNN)对通过机器人捕获的对象进行分类。我已经编写了两个独立的python脚本:一个是通过机器人拍摄照片并将其另存为.png文件,第二个是使机器人能够通过speechProxy (来自ALProxy库)说出对象的标题。第一个脚本运行良好,能够根据需要与MatLab进行通信。我使用以下命令运行python脚本,读取作为结果创建的.png,裁剪图像,然后对其进行分类:
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我的MatLab脚本的这一部分工作正常,因为我能够通过运行脚本并将对象放在机器人的视图中来对对象进行分类。我拥有的另一个脚本应该使机器人能够说出对象的标签,但我不太确定如何让python脚本从MatLab输出中读出标签。
下面的Python代码片段是我让Robot说出标签所需的内容。
speechProxy.say("This object is a " + sys.argv[1])现在的问题是从MatLab获取系统参数。我在MathWorks网站上搜索过,他们说传递系统参数应该如下所示
system('python','python_script_path',argument) %assuming argument is an object of certain datatype我已经用我各自的参数和python脚本/路径尝试了这种类型的语法,但得到了一个错误。如果您参考我展示MatLab脚本的第一段代码,传递参数的语法将如下所示:
system('python "speakObject.py path"', label);但这会导致错误。最终,我在获取MatLab脚本和第二个Python脚本进行通信时遇到了问题。如何将.png的标签分类作为系统参数传递给python,以便Robot可以说出对象的身份?
发布于 2018-08-02 05:40:02
您可能想尝试一下,比如
strCommand = sprintf('python speakObject.py %s', label);
system(strCommand);https://stackoverflow.com/questions/51640816
复制相似问题