This is a tricky situation that comes up often with uEye (IDS Imaging) cameras when interfacing with MATLAB. Even though everything looks correctly shut down in the code, the underlying driver or hardware handle may remain active, which leads to the camera not being released properly. This can be frustrating, especially when trying to switch between MATLAB and the uEye application.
A few things to try that have worked in similar setups:
- Make sure that you are not just stopping and deleting the object, but also fully resetting the Image Acquisition Toolbox state.
- MATLAB sometimes keeps internal references to hardware drivers even after the video object is cleared.
- The “imaqreset” function is often the key step that's missing in many shutdown scripts.
Below is a general structure that tends to release the hardware properly when using MATLAB with uEye cameras:
clc; clear; close all;
info = imaqhwinfo;
if isempty(info.InstalledAdaptors)
error('No image acquisition adaptors installed.');
end
adaptor = 'ueye';
camInfo = imaqhwinfo(adaptor);
deviceID = camInfo.DeviceInfo(1).DeviceID;
vid = videoinput(adaptor, deviceID, camInfo.DeviceInfo(1).SupportedFormats{1});
src = getselectedsource(vid);
pause(1);
preview(vid);
pause(1);
img = getsnapshot(vid);
imshow(img);
pause(1);
closepreview(vid);
stop(vid);
flushdata(vid);
delete(vid);
clear vid;
imaqreset;
A few things worth noting:
- “flushdata” (vid) clears any internal frame buffers before deletion.
- “imaqreset” is critical as it resets all adaptors and releases any lingering device locks or handles, which is likely what the uEye application is detecting.
- Sometimes it helps to avoid “clear all” as it doesn't reset hardware connections like “imaqreset” does.
Also make sure MATLAB is not minimized or running a background figure or camera preview window when attempting the release, as these can sometimes keep the device context alive.
The following documentation links can be referred to for a better understanding:
- “videoinput” function: https://www.mathworks.com/help/imaq/videoinput.html
- “imaqreset” function: https://www.mathworks.com/help/imaq/imaqreset.html
- “flushdata” function: https://www.mathworks.com/help/imaq/imaqdevice.flushdata.html
- “delete” function: https://www.mathworks.com/help/matlab/ref/delete.html
There may be deeper OS-level device locks, but this usually resolves the common usage conflict.