2013-09-16 110 views
1

Capture按鈕確實捕獲圖像並將其保存在一個文件夾中。每當我按下Capture按鈕它只會繼續捕捉和保存圖像。我想要做的是每當我按下Capture按鈕時,它會自動更新image1.jpg文本框MATLAB圖文件麻煩

爲了把事情說清楚:

每一擊到捕獲按鈕,則編輯文本框更新它的 名字image1.jpg,1再打來捕捉,文本框更新 image2.jpg等等....請幫我:(

enter image description here

拍攝按鈕的代碼是

vid = videoinput('winvideo', 2); 
set(vid, 'ReturnedColorSpace', 'RGB'); 
img = getsnapshot(vid); 
imshow(img); 

%this is where the image will be saved 
counter = 1; 
baseDir = 'C:\Users\Sony Vaio\Documents\Task\Appendix\images\'; 
baseName = 'image'; 
newName = [baseDir baseName num2str(counter) '.jpg']; 
while exist(newName,'file') 
counter = counter + 1; 
newName = [baseDir baseName num2str(counter) '.jpg']; 
end  
imwrite(img, newName); 

的過程中出現的文本框按鈕的代碼

name=get(handles.name,'String'); 
A=imread(strcat('images/',name)); 
org=A; 
axes(handles.axes1); 
[h,w,f]=size(A); 
%original image is shown 
imshow(A); 
+0

你試過設置文本框的'String'屬性嗎? 'set(hTextBox,'String',newName);' – chappjc

+0

@chappjc對不起,忘了說文本框只是用作Process按鈕的顯示。該文本框沒有屬性。 – lloydknight

+0

要將文件名放在編輯文本框中,您仍然需要使用'String'屬性。問題是如何將文件名從完整文件路徑中刪除?爲此,請使用'fileparts'。 – chappjc

回答

1

我不知道你貼出來供大家拍攝按鈕的推回調整個代碼,但我沒有看到你在任何地方設置編輯框的String屬性。

set(hEditBox,'String',newName); 

如果您在handles設定欄,不要忘記guidata(hObject,handles)

+0

好吧生病吧試試:) – lloydknight

+0

它的工作,但名稱是圖像的整個路徑。整個目錄。 – lloydknight

+0

'newName = [baseDir baseName num2str(counter)'.jpg'];'這個名字得到整個目錄。如果我使用'baseDir',則名稱不會移動到**圖像** – lloydknight