一、项目简介

本系统基于MATLAB平台,利用卷积神经网络(CNN)与GUI界面,实现石头、剪刀、布三类手势图像的识别。训练模块采用自定义CNN(含4个卷积层、池化层及全连接层,输出3类),按8:2划分训练集与测试集;GUI模块支持PNG图像选取、灰度/二值化预处理、单张实时识别及测试集各类别准确率评估,交互直观。

二、部分源码

function pushbutton1_Callback(hObject, eventdata, handles) % 选取图像

% hObject handle to pushbutton1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

global I

[fn,pn,~]=uigetfile('*.png','请选择所要识别的图像');

I = imread([pn fn]);

axes(handles.axes1);

imshow(I);

title('原始图像');

% --- Executes on button press in pushbutton2.

function pushbutton2_Callback(hObject, eventdata, handles) % 进行识别

% hObject handle to pushbutton2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

global I

load("CNNnet.mat");

y_pred = classify(CNNnet,I);

% disp(y_pred);

set(handles.edit1,'string',y_pred);

function edit1_Callback(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text

% str2double(get(hObject,'String')) returns contents of edit1 as a double

% --- Executes during object creation, after setting all properties.

function edit1_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

% --- Executes on button press in pushbutton3.

function pushbutton3_Callback(hObject, eventdata, handles) % 显示整个测试集的结果

% hObject handle to pushbutton3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

%% 加载数据

allImages = imageDatastore('dbx', ...

'IncludeSubfolders' ,true, ...

'LabelSource' , 'foldernames' );% 图像加载为图像数据存储

% imageDatastore函数会根据文件夹名称自动标记图像

% 划分训练集(80%)和测试集(20%)

[imgsTrain,imgsTest] = splitEachLabel(allImages,0.8,'randomized');

load("CNNnet.mat");

y_pred = classify(CNNnet,imgsTest); % 使用训练好的网络测试

accuracy = mean(y_pred == imgsTest.Labels);% 计算准确率

%% 计算每类的准确率

y1 = categorical("paper"); y2 = categorical("rock"); y3 = categorical("scissors");

paper = 0; rock = 0; scissors = 0;

for i = 1:length(y_pred)

if (y_pred(i) == y1) && (imgsTest.Labels(i) == y1)

paper = paper + 1;

elseif (y_pred(i) == y2) && (imgsTest.Labels(i) == y2)

rock = rock + 1;

elseif (y_pred(i) == y3) && (imgsTest.Labels(i) == y3)

scissors = scissors + 1;

end

end

paper_acc = paper/sum(imgsTest.Labels == y1);

rock_acc = rock/sum(imgsTest.Labels == y2);

scissors_acc = scissors/sum(imgsTest.Labels == y3);

set(handles.text2,'string',['总体准确率: ',num2str(100*accuracy),'%'],'FontSize',12);

set(handles.text1,'string',['布: ', num2str(100*paper_acc),'%'],'FontSize',12);

set(handles.text3,'string',['石头: ', num2str(100*rock_acc),'%'],'FontSize',12);

set(handles.text4,'string',['剪刀: ', num2str(100*scissors_acc),'%'],'FontSize',12);

三、运行结果

四、总结

测试集总体准确率达99.46%,各类别准确率分别为布98.18%、石头100%、剪刀100%,验证了CNN在手势分类任务中的优异性能。系统界面友好,兼具教学与实用价值。不足在于网络结构较浅、支持PNG格式。后续可通过迁移学习、数据增强及多格式支持进一步提升泛化能力。

五、代码获取

接matlab程序定制和论文设计,方向如下:

图像处理|语音识别|图像识别|目标检测|深度学习|神经网络|强化学习|机器学习|通信系统|信号处理|时频分析|小波降噪|路径规划|优化算法|智能算法|数据处理|数学建模|文献复现|算法复现|模型复现等

程序包运行成功,零基础的可以远程帮你运行,赠送安装包

作为初学者,遇见不会的问题是非常正常的事情,具体代码仿真可通过主页 私信博主。

Logo

脑启社区是一个专注类脑智能领域的开发者社区。欢迎加入社区,共建类脑智能生态。社区为开发者提供了丰富的开源类脑工具软件、类脑算法模型及数据集、类脑知识库、类脑技术培训课程以及类脑应用案例等资源。

更多推荐