靈兒
Lv 4
靈兒 asked in 電腦與網際網路程式設計 · 1 decade ago

MATLAB GUI程式除錯

以下是我要執行ㄉ程式,但他一直出現錯誤,

我不懂要改哪裡,所以請各位大大幫幫忙,謝謝!!

function varargout = eyeTrackingGUI(varargin)

% EYETRACKINGGUI M-file for eyeTrackingGUI.figgui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @eyeTrackingGUI_OpeningFcn, ...

'gui_OutputFcn', @eyeTrackingGUI_OutputFcn, ...

'gui_LayoutFcn', [] , ...

'gui_Callback', []);

if nargin && ischar(varargin{1})

gui_State.gui_Callback = str2func(varargin{1});

endif 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 eyeTrackingGUI is made visible.

function eyeTrackingGUI_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 eyeTrackingGUI (see VARARGIN)% Choose default command line output for eyeTrackingGUI

handles.output = hObject;set( handles.saveimage, 'Enable', 'off' );

handles.video = videoinput( 'winvideo', 1, 'RGB24_320x240' );

%{

set( handles.video, 'TimerPeriod', 0.05, ...

'TimerFcn',[ 'if( ~isempty( gco ) ),'...

'handles = guidata( gcf );'... % Update handles

'image( getsnapshot( handles.video ) );'... % Get picture using GETSNAPSHOT and put it into axes using IMAGE

'set( handles.videoOutput, ''ytick'', [], ''xtick'', [] ),'... % Remove tickmarks and labels that are inserted when using IMAGE

'else '...

'delete( imaqfind );'... % Clean up - delete any image acquisition objects

'end' ] );

triggerconfig( handles.video, 'Manual' );

%}

%triggerconfig( handles.video, 'Manual' );

set( handles.video, 'TriggerRepeat', Inf );

handles.video.FrameGrabInterval = 18;

% Update handles structure

guidata(hObject, handles);% UIWAIT makes eyeTrackingGUI wait for user response (see UIRESUME)

% uiwait(handles.figure1);

因為字數有限,所以我會以補充ㄉ方式貼上所有程式碼

Update:

function varargout = eyeTrackingGUI_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;

function readimage_Callback(hObject, eventdata, handles)

if strcmp( get( handles.video, 'Running' ), 'on' )

stop( handles.video ); % 停止CCD

Update 2:

set( handles.startwebcam, 'String', 'Start WebCam' );

end

[ fileName, filePath ] = uigetfile( '*.jpg', 'Select Image' );

if fileName ~= 0

im = imread( strcat( filePath, fileName ) );

figure, imshow( eyeTracking( im ) );

Update 3:

else

warndlg( 'Input image must be selected.',' Warning ' ) ;

end

function startwebcam_Callback(hObject, eventdata, handles)

% 啟動或關閉CCD

if strcmp( get( handles.startwebcam, 'String' ), 'Start WebCam' )

h = waitbar( 0, 'CCD...' );

Update 4:

for i = 1 : 100

waitbar( i / 100 );

pause( .01 );

end

close(h);

set( handles.startwebcam, 'String', 'Stop WebCam' );

Update 5:

start( handles.video );

while( 1 )

if strcmp( get( handles.startwebcam, 'String' ), 'Start WebCam' )

break;

end

data = getdata( handles.video, 1 );

imshow( eyeTracking( data ) );

end

Update 6:

function saveimage_Callback(hObject, eventdata, handles)

if strcmp( get( handles.video, 'Running' ), 'on' )

stop( handles.video ); % 停止CCD

Update 7:

set( handles.startwebcam, 'String', 'Start WebCam' );

end

[ fileName, filePath ] = uiputfile( '*.jpg', 'Save Image' ); % 設定存檔檔名

if fileName ~= 0

Update 8:

h = waitbar( 0, 'Save Image...' );

for i = 1 : 20

waitbar( i / 20 );

pause( 0.01 );

end

close( h );

I = getframe( handles.videoOutput ); % 取得資料

imwrite( I.cdata,strcat( filePath, fileName ) ); %存檔

Update 9:

else

warndlg( 'Input image must be selected.', ' Warning ' );

end

function exitGUI_Callback(hObject, eventdata, handles)

stop( handles.video ) % 停止CCD

close all; % 離開程式

Update 10:

function figure1_CloseRequestFcn(hObject, eventdata, handles)

stop( handles.video ) % 停止CCD

% Hint: delete(hObject) closes the figure

delete(hObject);

以上程式結束

Update 11:

以下是我執行出現ㄉ錯誤

??? Error using ==> videoinput.videoinput at 233

There are no devices installed for the specified ADAPTORNAME. See IMAQHWINFO.

Error in ==> eyeTrackingGUI>eyeTrackingGUI_OpeningFcn at 59

handles.video = videoinput( 'winvideo', 1, 'RGB24_320x240' );

Update 12:

Error in ==> gui_mainfcn at 210

feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});

Error in ==> eyeTrackingGUI at 42

gui_mainfcn(gui_State, varargin{:});

Update 13:

不好意思,因為有字數ㄉ限制,所以有點凌亂

大大可以將改好後可以執行ㄉ程式寄到我ㄉ信箱

再次拜託幫幫忙 感恩!!

Update 14:

TO:Ryan

你好,

我是用MATLAB 2007版ㄉ,在輸入imaqhwinfo指令後,我產生ㄉ是

ans =

InstalledAdaptors: {'coreco' ‘demo’ 'winvideo'}

MATLABVersion: '7.4 (R2007a)'

ToolboxName: 'Image Acquisition Toolbox'

ToolboxVersion: '2.1 (R2007a)'

Update 15:

但是我現在ㄉ煩惱是

我執行後會出現這種錯誤

Error in ==> gui_mainfcn at 210

feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});

Error in ==> eyeTrackingGUI at 42

gui_mainfcn(gui_State, varargin{:});

我不知道要改哪裡才能讓錯誤不在出現

1 Answer

Rating
  • Ryan
    Lv 5
    1 decade ago
    Favorite Answer

    以下是我執行出現ㄉ錯誤

    ??? Error using ==> videoinput.videoinput at 233

    There are no devices installed for the specified ADAPTORNAME. See IMAQHWINFO.

    你的錯誤訊息很明顯是MATLAB沒有偵測到對應的影像擷取裝置,

    所以請你先在MATLAB環境(command window)輸入下列指令

    >> imaqhwinfo

    ans =

    InstalledAdaptors: {'coreco' 'matrox' 'winvideo'}

    MATLABVersion: '7.9 (R2009b)'

    ToolboxName: 'Image Acquisition Toolbox'

    ToolboxVersion: '3.4 (R2009b)'

    然後進一步查詢是否該裝置有連接硬體

    >> imaqhwinfo('winvideo')

    ans =

    AdaptorDllName: [1x67 char]

    AdaptorDllVersion: '3.4 (R2009b)'

    AdaptorName: 'winvideo'

    DeviceIDs: {1x0 cell}

    DeviceInfo: [1x0 struct]

    如果回傳1x0 struct表示空矩陣,沒有偵測到任何影像裝置;

    反之,如果有安裝一個webcamera,應該會抓到1x1 struct

    你先試試看吧!

    2010-08-08 21:55:40 補充:

    重點不在於GUI,在你的影像裝置使否正確抓到,

    請看我貼的步驟,去確認你是否有攝影機。

    ps.如果回傳1x0 struct表示空矩陣,沒有偵測到任何影像裝置

Still have questions? Get your answers by asking now.