在 MATLAB 中使用了一段时间的一些基本图像处理之后,我觉得不得不问这个简单的问题有点尴尬......为什么以下代码的最后一条语句无法关闭指定的图像?在 MATLAB 中关闭指定图像的正确方法是什么?
clear; clc; close all;
%
%% Identify available webcams.
% The MATLAB Webcam Supoort Package must be installed first.
myWebcams = webcamlist % Identifies available webcams.
cam = webcam(myWebcams{1}) % Identifies the current webcam.
%
%% Acquire webcam images.
preview(cam) % A preview of the img.
img = snapshot(cam); img = rgb2gray(img); % A single webcam img.
imgh = imshow(img); % Display the img.
[imgHeight, imgWidth] = size(img)
close(imgh)
使用
close(imgh)
我收到以下错误:
>> close(imgh)
Error using close (line 116)
Invalid figure handle.
最佳答案
这里 imgh
不是图形句柄。它是图像对象的句柄,该图像对象位于坐标区对象内,坐标区对象位于图形内。要关闭图形,请使用
>> close(imgh.Parent.Parent);
或者,如果您有旧版本的 MATLAB,请使用
>> close(get(get(h, 'Parent'), 'Parent'));
或者,更简单地说,使用
>> close all
关于matlab - 如何关闭指定的 MATLAB 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31413173/