function main()
clear all;clc;
path='.\image_files\'; %___________image files path
path_posmap='.\pos_maps\';%_________stores positions of agents
NumOfImages = length(dir(path)) - 2;
w = dir(path);
img_names={}; %________stores names of all images
for i=3:NumOfImages+2,
img_names{i-2} = w(i).name;
end
for i=1:numel(img_names),
imname = [ path img_names{i}];
im0 = imread(imname);
imageHandle =imshow(im0);%_____________displays the image
xlabel(num2str(i));
set(imageHandle,'ButtonDownFcn',@ImageClickCallback);
end
end
function coordinates=ImageClickCallback (objectHandle , eventData)
axesHandle = get(objectHandle,'Parent');
coordinates = get(axesHandle,'CurrentPoint');
coordinates = coordinates(1,1:2);
message = sprintf('x: %.1f , y: %.1f',coordinates (1) ,coordinates (2));
disp(coordinates); %___ add these coordinates for each image
close(gcf);
end
我想要向用戶顯示一系列圖像。對於來自用戶的每個圖像請求輸入,以鼠標的形式點擊圖像。將每次點擊的座標存儲在矩陣中。因此,最後有一個尺寸爲num_images x 2
的矩陣。用戶輸入後續圖像以存儲座標
但是在上面
a。我無法獲得從函數ImageClickCallback
返回的座標b。無法在用戶點擊時關閉圖像並顯示新圖像。
嘗試'close(get(axesHandle,'Parent'));'以關閉圖像。是否顯示正確的座標? – Wauzl
@Wauzl是的,他們顯示,但我也想存儲他們。最後的手段是創建一個全局變量並添加。在哪裏添加'close(get(axesHandle,'Parent'));'。 –