1、前记:
和https://www.mathworks.com/help/matlabmobile/ug/classify-images-from-ios-camera-using-deep-learning.html记录利用手机端MATLAB进行传感器数据获取
包括数据显示,调用手机端相机拍照并利用训练好的模型进行识别。
2、步骤
(1)手机安装MATLAB Mobile app后,启动MATLAB移动应用程序,使用MathWorks帐户登录。
MATLAB Mobile自动将设备连接到MathWorks云(可能需要下载MATLAB drive)
(2)桌面MATLAB端安装MATLAB drive和安卓或IOS的硬件支持包。
(3)满足(1)和(2)之后进行测试:
在启动的MATLAB移动应用程序中,选择传感器进行设置---实时流式传输至MATLAB--采样率默认也可---更多里面打开访问传感器和摄像头。【传感器右上角有个?,点击可查如下】
保证移动端连接到云的传感器服务器【一般打开app之后会显示正在连接到mathworks cloud】。然后按下代码进行按小节运行。
%% use the mobiledev command to create an object
% that represents your mobile device.
clc
clear
m = mobiledev;
%% open camera
cam = camera(m,'back');
%% load deep learning net
nnet = googlenet;
%% call camnet and get the result of camera acquisition
label = camnet(cam,nnet);
%% Prepare for Data Acquisition from Multiple Sensors
m.AngularVelocitySensorEnabled = 1;%打开mobile端传感器类型
m.OrientationSensorEnabled = 1;
%% start sending data
m.Logging = 1; %mobile端开始数据获取---> m.Logging = 0;停止数据获取
%% plot data or use orientation data to change the view of figure
[X,Y,Z] = peaks;
surf(X,Y,Z)
xlabel('X')
ylabel('Y')
zlabel('Z')
while true
r=m.Orientation*180/pi
view([r(1,1) r(1,2) r(1,3)])
% plot3(r(1,1),r(1,2),r(1,3),'*')
drawnow;
end
其中的camnet函数为:
function value = camnet(cam,nnet)
img = snapshot(cam,'manual');
pic = imresize(img,[224,224]);
value = classify(nnet,pic);
figure('Name','识别结果','NumberTitle','off')
image(pic)
title(char(value))
end
若出现缺少googlenet,则在附加功能中进行下载即可。
3、结果
(1)手动拍图之后在MATLAB中通过预先训练好的模型识别到的结果。
(2)实时Orientation数据改变view视角。