Getting Errors in HSV App Design I created. Getting class, type errors when trying to move the data/ matrices that i need for image object detection using HSV.
이전 댓글 표시
Or any references to thresholding a live video feed to filter out a particular object.
Errors I received * Struct contents reference from a non-struct array object.
Error in HSVColorAPP/StartTrackingSwitchValueChanged (line 165) app.EditField.Value = app.threshh.Value;
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 352) Error while evaluating Switch PrivateValueChangedFcn.
Error using matlab.ui.control.internal.model.AbstractNumericComponent/set.Value (line 110) 'Value' must be a double scalar.
Error in HSVColorAPP/StartTrackingSwitchValueChanged (line 165) app.EditField.Value = app.threshh;
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 352) Error while evaluating Switch PrivateValueChangedFcn. rror setting property 'EditField' of class 'HSVColorAPP': Invalid data type. Value must be matlab.ui.control.NumericEditField or be convertible to matlab.ui.control.NumericEditField.
Error in HSVColorAPP/StartTrackingSwitchValueChanged (line 165) app.EditField = app.threshh;
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 352) Error while evaluating Switch PrivateValueChangedFcn.
Code I have put together
classdef HSVColorAPP < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
HueMaxSliderLabel matlab.ui.control.Label
HueMaxSlider matlab.ui.control.Slider
SaturationMinSliderLabel matlab.ui.control.Label
SaturationMinSlider matlab.ui.control.Slider
ValueMinSliderLabel matlab.ui.control.Label
ValueMinSlider matlab.ui.control.Slider
img_org matlab.ui.control.UIAxes
img_hsview matlab.ui.control.UIAxes
img_track matlab.ui.control.UIAxes
StartCameraSwitchLabel matlab.ui.control.Label
StartCameraSwitch matlab.ui.control.Switch
HueMinSliderLabel matlab.ui.control.Label
HueMinSlider matlab.ui.control.Slider
SaturationMaxSliderLabel matlab.ui.control.Label
SaturationMaxSlider matlab.ui.control.Slider
ValueMaxSliderLabel matlab.ui.control.Label
ValueMaxSlider matlab.ui.control.Slider
StartTrackingSwitch_2Label matlab.ui.control.Label
StartTrackingSwitch matlab.ui.control.Switch
HSVSwitchLabel matlab.ui.control.Label
HSVSwitch matlab.ui.control.Switch
EditFieldLabel matlab.ui.control.Label
EditField matlab.ui.control.NumericEditField
end
properties (Access = public)
hmax;
hmin;
smin;
smax;
vmin;
vmax;
img_h;
img_s;
img_v;
img_o;
img_hsv;
row;
column;
threshh;
img_add;
end
properties (Access = private)
% Description
end
methods (Access = private)
% function [img_o,rows,columns,img_hsv1,img_h,img_s,img_v] = camsetup(app) % % % end % % % function [threshh,threshs,threshv]= thresholds(~,img_h,img_s,img_v,hmin,hmax,smin,smax,vmin,vmax); % % % Place the values within the thresholds % threshh = app.img_h >= app.hmin & app.img_h<= app.hmax; % threshs = app.img_s >= app.smin & app.img_s<= app.smax; % threshv = app.img_v >= app.vmin & app.img_v<= app.vmax; % % end % % % % function results = trackedimage(app,threshh,threshs,threshv) % %Add Images together % img_add = threshh+ threshs + threshv; % imshow(img_add,'Parent',app.img_track); % % end % end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
% Callback function: HueMaxSlider, ValueMinSlider
function HueMaxSliderValueChanging(app, event)
changingValue = event.Value;
app.hmax = changingValue;
end
% Value changing function: ValueMinSlider
function ValueMinSliderValueChanging(app, event)
changingValue = event.Value;
app.vmin = changingValue;
end
% Value changing function: ValueMaxSlider
function ValueMaxSliderValueChanging(app, event)
changingValue = event.Value;
app.vmax = changingValue;
end
% Value changing function: HueMinSlider
function HueMinSliderValueChanging(app, event)
changingValue = event.Value;
app.hmin = changingValue;
end
% Value changing function: SaturationMinSlider
function SaturationMinSliderValueChanging(app, event)
changingValue = event.Value;
app.smin = changingValue;
end
% Value changed function: StartCameraSwitch
function StartCameraSwitchValueChanged(app, event)
camvalue = app.StartCameraSwitch.Value;
switch camvalue
case 'On'
disp(camvalue);
%Establish Video Object
vid1 = ipcam('http://192.168.1.109:80/videostream.cgi[?user=admin&pwd= '']');
%Snapshot of the Vid
app.img_o = snapshot(vid1);
imshow(app.img_o,'Parent',app.img_org);
%Size the Frame
[app.row, app.column, ~] = size(app.img_o);
%Convert to HSV
app.img_hsv = rgb2hsv(app.img_o);
imshow(app.img_hsv,'Parent',app.img_hsview);
case 'Off'
disp(camvalue);
end
end
% Value changed function: StartTrackingSwitch
function StartTrackingSwitchValueChanged(app, event)
switchvalue = app.StartTrackingSwitch.Value;
switch switchvalue
case ('On')
disp(switchvalue);
% Place the values within the thresholds
app.threshh = app.hmax - app.hmin;
% app.threshs = app.smax.Value- app.smin.Value;
% app.threshv = app.vmax.Value- app.vmin.Value;
app.EditField = app.threshh;
% threshs = [app.smin,Value , app.smax.Value];
% threshv = [app.vmin.Value , app.vmax.Value];
%Add Images together
app.img_add = app.threshh;
imshow(app.img_add,'Parent',app.img_track);
% imshow(app.img_o,'Parent',app.img_org);
case ('Off')
disp(switchvalue);
end
end
% Value changing function: SaturationMaxSlider
function SaturationMaxSliderValueChanging(app, event)
changingValue = event.Value;
app.smax = changingValue;
end
% Value changed function: HSVSwitch
function HSVSwitchValueChanged(app, event)
hsvvalue = app.HSVSwitch.Value;
disp(hsvvalue);
switch hsvvalue
case 'On'
disp(hsvvalue);
%Image to Gray
img_gry = rgb2gray(app.img_hsv);
% disp(img_gry);
%Getting the HSV
app.img_h = app.img_hsv(:,:,1) - img_gry ;
app.img_s = app.img_hsv(:,:,2) - img_gry;
% app.img_v = app.img_hsv(:,:,3) - img_gry;
% app.UiTable = app.img_h.Value;
case 'Off'
disp(hsvvalue);
end
end
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 1119 586];
app.UIFigure.Name = 'UI Figure';
% Create HueMaxSliderLabel
app.HueMaxSliderLabel = uilabel(app.UIFigure);
app.HueMaxSliderLabel.HorizontalAlignment = 'right';
app.HueMaxSliderLabel.Position = [875 453 54 15];
app.HueMaxSliderLabel.Text = 'Hue Max';
% Create HueMaxSlider
app.HueMaxSlider = uislider(app.UIFigure);
app.HueMaxSlider.Limits = [0 255];
app.HueMaxSlider.ValueChangingFcn = createCallbackFcn(app, @HueMaxSliderValueChanging, true);
app.HueMaxSlider.Position = [950 459 150 3];
app.HueMaxSlider.Value = 255;
% Create SaturationMinSliderLabel
app.SaturationMinSliderLabel = uilabel(app.UIFigure);
app.SaturationMinSliderLabel.HorizontalAlignment = 'right';
app.SaturationMinSliderLabel.Position = [845 411 84 15];
app.SaturationMinSliderLabel.Text = 'Saturation Min';
% Create SaturationMinSlider
app.SaturationMinSlider = uislider(app.UIFigure);
app.SaturationMinSlider.Limits = [0 255];
app.SaturationMinSlider.ValueChangingFcn = createCallbackFcn(app, @SaturationMinSliderValueChanging, true);
app.SaturationMinSlider.Position = [950 417 150 3];
% Create ValueMinSliderLabel
app.ValueMinSliderLabel = uilabel(app.UIFigure);
app.ValueMinSliderLabel.HorizontalAlignment = 'right';
app.ValueMinSliderLabel.Position = [869 293 60 15];
app.ValueMinSliderLabel.Text = 'Value Min';
% Create ValueMinSlider
app.ValueMinSlider = uislider(app.UIFigure);
app.ValueMinSlider.Limits = [0 255];
app.ValueMinSlider.ValueChangedFcn = createCallbackFcn(app, @HueMaxSliderValueChanging, true);
app.ValueMinSlider.ValueChangingFcn = createCallbackFcn(app, @ValueMinSliderValueChanging, true);
app.ValueMinSlider.Position = [950 299 150 3];
% Create img_org
app.img_org = uiaxes(app.UIFigure);
title(app.img_org, 'Original Image')
xlabel(app.img_org, 'X')
ylabel(app.img_org, 'Y')
app.img_org.Box = 'on';
app.img_org.XGrid = 'on';
app.img_org.YGrid = 'on';
app.img_org.Position = [13 278 300 301];
% Create img_hsview
app.img_hsview = uiaxes(app.UIFigure);
title(app.img_hsview, 'HSV')
xlabel(app.img_hsview, 'X')
ylabel(app.img_hsview, 'Y')
app.img_hsview.Box = 'on';
app.img_hsview.XGrid = 'on';
app.img_hsview.YGrid = 'on';
app.img_hsview.Position = [445 278 342 301];
% Create img_track
app.img_track = uiaxes(app.UIFigure);
title(app.img_track, 'Tracked Image')
xlabel(app.img_track, 'X')
ylabel(app.img_track, 'Y')
app.img_track.DataAspectRatio = [1 1 1];
app.img_track.PlotBoxAspectRatio = [1 1 1];
app.img_track.XLim = [0 1];
app.img_track.YLim = [0 1];
app.img_track.ZLim = [0 1];
app.img_track.CLim = [0 1];
app.img_track.GridColor = [0.15 0.15 0.15];
app.img_track.MinorGridColor = [0.1 0.1 0.1];
app.img_track.XColor = [0.15 0.15 0.15];
app.img_track.XTick = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
app.img_track.YColor = [0.15 0.15 0.15];
app.img_track.YTick = [0 0.2 0.4 0.6 0.8 1];
app.img_track.ZColor = [0.15 0.15 0.15];
app.img_track.ZTick = [0 0.5 1];
app.img_track.CameraPosition = [0.5 0.5 9.16025403784439];
app.img_track.CameraTarget = [0.5 0.5 0.5];
app.img_track.CameraUpVector = [0 1 0];
app.img_track.Position = [49 -2 506 281];
% Create StartCameraSwitchLabel
app.StartCameraSwitchLabel = uilabel(app.UIFigure);
app.StartCameraSwitchLabel.HorizontalAlignment = 'center';
app.StartCameraSwitchLabel.Position = [830 517 77 15];
app.StartCameraSwitchLabel.Text = 'Start Camera';
% Create StartCameraSwitch
app.StartCameraSwitch = uiswitch(app.UIFigure, 'slider');
app.StartCameraSwitch.ValueChangedFcn = createCallbackFcn(app, @StartCameraSwitchValueChanged, true);
app.StartCameraSwitch.Position = [845 547 45 20];
% Create HueMinSliderLabel
app.HueMinSliderLabel = uilabel(app.UIFigure);
app.HueMinSliderLabel.HorizontalAlignment = 'right';
app.HueMinSliderLabel.Position = [878 491 51 15];
app.HueMinSliderLabel.Text = 'Hue Min';
% Create HueMinSlider
app.HueMinSlider = uislider(app.UIFigure);
app.HueMinSlider.Limits = [0 255];
app.HueMinSlider.ValueChangingFcn = createCallbackFcn(app, @HueMinSliderValueChanging, true);
app.HueMinSlider.Position = [950 497 150 3];
% Create SaturationMaxSliderLabel
app.SaturationMaxSliderLabel = uilabel(app.UIFigure);
app.SaturationMaxSliderLabel.HorizontalAlignment = 'right';
app.SaturationMaxSliderLabel.Position = [842 347 87 15];
app.SaturationMaxSliderLabel.Text = 'Saturation Max';
% Create SaturationMaxSlider
app.SaturationMaxSlider = uislider(app.UIFigure);
app.SaturationMaxSlider.Limits = [0 255];
app.SaturationMaxSlider.ValueChangingFcn = createCallbackFcn(app, @SaturationMaxSliderValueChanging, true);
app.SaturationMaxSlider.Position = [950 353 150 3];
app.SaturationMaxSlider.Value = 255;
% Create ValueMaxSliderLabel
app.ValueMaxSliderLabel = uilabel(app.UIFigure);
app.ValueMaxSliderLabel.HorizontalAlignment = 'right';
app.ValueMaxSliderLabel.Position = [868 243 63 15];
app.ValueMaxSliderLabel.Text = 'Value Max';
% Create ValueMaxSlider
app.ValueMaxSlider = uislider(app.UIFigure);
app.ValueMaxSlider.Limits = [0 255];
app.ValueMaxSlider.ValueChangingFcn = createCallbackFcn(app, @ValueMaxSliderValueChanging, true);
app.ValueMaxSlider.Position = [952 249 150 3];
app.ValueMaxSlider.Value = 255;
% Create StartTrackingSwitch_2Label
app.StartTrackingSwitch_2Label = uilabel(app.UIFigure);
app.StartTrackingSwitch_2Label.HorizontalAlignment = 'center';
app.StartTrackingSwitch_2Label.Position = [931 517 80 15];
app.StartTrackingSwitch_2Label.Text = 'Start Tracking';
% Create StartTrackingSwitch
app.StartTrackingSwitch = uiswitch(app.UIFigure, 'slider');
app.StartTrackingSwitch.ValueChangedFcn = createCallbackFcn(app, @StartTrackingSwitchValueChanged, true);
app.StartTrackingSwitch.Position = [948 547 45 20];
% Create HSVSwitchLabel
app.HSVSwitchLabel = uilabel(app.UIFigure);
app.HSVSwitchLabel.HorizontalAlignment = 'center';
app.HSVSwitchLabel.Position = [1052 517 30 15];
app.HSVSwitchLabel.Text = 'HSV';
% Create HSVSwitch
app.HSVSwitch = uiswitch(app.UIFigure, 'slider');
app.HSVSwitch.ValueChangedFcn = createCallbackFcn(app, @HSVSwitchValueChanged, true);
app.HSVSwitch.Position = [1044 547 45 20];
% Create EditFieldLabel
app.EditFieldLabel = uilabel(app.UIFigure);
app.EditFieldLabel.HorizontalAlignment = 'right';
app.EditFieldLabel.Position = [642 182 56 15];
app.EditFieldLabel.Text = 'Edit Field';
% Create EditField
app.EditField = uieditfield(app.UIFigure, 'numeric');
app.EditField.Position = [713 178 100 22];
end
end
methods (Access = public)
% Construct app
function app = HSVColorAPP
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!