I am new on matlab and installed R2017B and preparing a project emotion based music player

1 visualizzazione (ultimi 30 giorni)
Error in classreg.learning.paramoptim.parseOptimizationArgs (line 5) [OptimizeHyperparameters,~,~,RemainingArgs] = internal.stats.parseArgs(...
Error in fitcknn (line 247) [IsOptimizing, RemainingArgs] = classreg.learning.paramoptim.parseOptimizationArgs(varargin);
Error in main_GUI>Recognition_Callback (line 236) c=fitcknn(test_feature,fea,group);
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in main_GUI (line 43) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)main_GUI('Recognition_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback.
  4 Commenti
Niro Thakur
Niro Thakur il 23 Feb 2018
function varargout = main_GUI(varargin) % MAIN_GUI MATLAB code for main_GUI.fig % MAIN_GUI, by itself, creates a new MAIN_GUI or raises the existing % singleton*. % % H = MAIN_GUI returns the handle to a new MAIN_GUI or the handle to % the existing singleton*. % % MAIN_GUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in MAIN_GUI.M with the given input arguments. % % MAIN_GUI('Property','Value',...) creates a new MAIN_GUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before main_GUI_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to main_GUI_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help main_GUI
% Last Modified by GUIDE v2.5 15-Feb-2017 00:51:51
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @main_GUI_OpeningFcn, ... 'gui_OutputFcn', @main_GUI_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end
if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT
% --- Executes just before main_GUI is made visible. function main_GUI_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to main_GUI (see VARARGIN)
% Choose default command line output for main_GUI handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes main_GUI wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = main_GUI_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on button press in Train_images. function Train_images_Callback(hObject, eventdata, handles) % hObject handle to Train_images (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
fea=[]; group=[];
addr = genpath('.'); addpath(addr);
set(handles.text5, 'String', 'Training the Database !');
dos('attrib -h -r -s /S .\train_images\Thumbs.db'); dos('del /S .\train_images\Thumbs.db');
folder=dir('.\train_images'); count=0;
faceDetector = vision.CascadeObjectDetector();
%%
for mn=3:length(folder) count=count+1; address=strcat('.\train_images\',folder(mn).name);
files=dir(address);
num=numel(files);
for i=3:num
str=strcat('.\train_images\',folder(mn).name,'\',files(i).name);
msg_str = sprintf('Processing Folder %d, File %d',count,i-2);
set(handles.text5, 'String', msg_str);
im=imread(str);
im = imresize(im,[500,NaN]);
[r,c,p] = size(im);
if p == 3
gr = rgb2gray(im);
else
gr = im;
end
gr = imadjust(gr);
gr = histeq(gr);
bbox = step(faceDetector, gr);
if numel(bbox)== 4
face=imcrop(gr,bbox);
face=imresize(face,[100 100]);
pause(0.01)
[feature] = hog_feature_vector(face);
fea=[fea;feature];
group=[group count];
imshow(face,'Parent',handles.axes1);
elseif count == 3
img=imresize(face,[100 100]);
pause(0.01)
[feature] = hog_feature_vector(img);
fea=[fea;feature];
group=[group count];
imshow(img,'Parent',handles.axes1);
end
end
end
set(handles.text5, 'String', 'Training Complete !'); warndlg('Training Complete !');
save face_database fea group
% --- Executes on button press in Start_Camera. function Start_Camera_Callback(hObject, eventdata, handles) % hObject handle to Start_Camera (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
cla reset
vid = videoinput('winvideo', 1, 'YUY2_640x480'); src = getselectedsource(vid); vid.FramesPerTrigger = Inf; vid.ReturnedColorspace = 'rgb';
axes(handles.axes1); h1 = image; % create image object axis ij; % flip the image preview(vid,h1) % display webcam preview
set(handles.text5, 'String', 'Camera Started !'); handles.vid = vid; guidata(hObject,handles);
% --- Executes on button press in Recognition. function Recognition_Callback(hObject, eventdata, handles) % hObject handle to Recognition (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
load face_database I = handles.I;
set(handles.text5, 'String', 'Recognizing Emotion !');
faceDetector = vision.CascadeObjectDetector();
im = I;
gr = rgb2gray(im);
gr = imadjust(gr); gr = histeq(gr);
imshow(im,'Parent',handles.axes1);
bbox = step(faceDetector, gr);
if numel(bbox)== 4 testface=imcrop(gr,bbox);
testface=imresize(testface,[100 100]);
pause(0.01)
[test_feature] = hog_feature_vector(testface);
imshow(testface,'Parent',handles.axes1);
else warndlg('!! No Valid Face Found !!'); return; end
c=fitcknn(test_feature,fea,group);
%msgbox(c)
%% if c==1 msgbox ('Sad Emotion shown'); system('C:\Users\Thakur_Jee\Documents\MATLAB\code\brave.mp3') end
if c==2 msgbox ('Surprise Emotion shown'); system('C:\Users\Thakur_Jee\Documents\MATLAB\code\happy.mp3') end
% --- Executes on button press in Take_snapshot. function Take_snapshot_Callback(hObject, eventdata, handles) % hObject handle to Take_snapshot (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
vid = handles.vid;
I = getsnapshot(vid); stop(vid);
axes(handles.axes1); imshow(I);
handles.I = I; guidata(hObject,handles);
% --- Executes on button press in Exit_program. function Exit_program_Callback(hObject, eventdata, handles) % hObject handle to Exit_program (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all;
Jan
Jan il 23 Feb 2018
Modificato: Jan il 23 Feb 2018
Currently your code is not readable. Mark it and press the "{} Code" button to format it.
It would be kind, if you post the relevant part of the code only. Otherwise all readers have to dig in the code at first to find out, where you need what. We cannot run your code, because the FIG file is not provided. And you have posted only the part of the error message, which explains where the problem occurs, but not the line about what the problem is.

Accedi per commentare.

Risposte (1)

Don Mathis
Don Mathis il 23 Feb 2018
In your posted code, I see a single call to 'fitcknn' and it is passed 3 arguments:
c=fitcknn(test_feature,fea,group);
fitcknn does not take 3 arguments. It takes two, plus optional name-value pair arguments that appear in pairs. So I suspect that the 'group' argument is misplaced.

Categorie

Scopri di più su Develop uifigure-Based Apps in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by