python - 如何让 MatLab 对象在 python 中通过 sys.argv[1]?
问题描述
我正在尝试让 NAO Humanoid Robot 识别物体。我在 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 代码片段是机器人说出标签所需要的。
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,以便机器人可以说出对象的身份?
解决方案
您可能想尝试类似的东西
strCommand = sprintf('python speakObject.py %s', label);
system(strCommand);
推荐阅读
- bash - file_path 将空格计为文件名的结尾
- jquery - 如何在jQuery中将事件分配给变量
- bootstrap-select - 带有引导选择的 FormValidation.io
- bash - 如何从 bash 脚本中的 Docker 容器中运行的脚本获取 USB 设备信息?
- javascript - 预检请求未通过访问控制检查:它没有 HTTP ok 状态
- python - 合并两个不同大小的数据框
- math - 精益是否将自己暴露为 C/C++ 或 python 库?
- tailwind-css - 顺风 + Javascript
- xpath - 如何单击 td 为空的输入?
- r - 如果在变量中找到向量,则从向量中分配名称