Width and height values for ROIPosition must be greater than 0. error even when explicitly defining them.

I am using the image aquisition toolbox to connect to a camera using the gentl communications. I used the imaqhwinfo command to get the needed information and run:
vid = videoinput("gentl", 4, "Mono8",'ROIPosition',[0 0 320 320]);
After this I show the preview window, but this is the first line in the script and it fails here.
Initially this worked fine, but when I restarted matlab and tried again I get the error:
"Width and height values for ROIPosition must be greater than 0."
Initially I didn't specify the ROIPosition and it worked fine, but now even with it specified as shown I get this error.
It starts working again if I launch the imageAcquisitionExplorer. I don't even have to connect to the camera, just launching the explorer and detecting the camera is enough. Then I can close the explorer and after this the above command works in my code with or without the ROIPosition specified. I would rather not have to launch imageAcquisitionExplorer every time I want my script to work. Is there some other way to preemptively correct this problem?

4 Comments

"After this I show the preview window" <== for some reason you forgot to show that line of code. Please give it.
Hello, here is the full code:
% Create a video input object and get information about video
vid = videoinput("gentl", 4, "Mono8",'ROIPosition',[0 0 320 320]);
vidRes = vid.VideoResolution;
nBands = vid.NumberOfBands;
% create figure
figure('Toolbar','none',...
'Menubar', 'none',...
'NumberTitle','Off',...
'Name','My Preview Window');
%create image object to display video in
hImage = image( zeros(vidRes(2), vidRes(1), nBands) );
% Display the video data
preview(vid, hImage);
" I used the imaqhwinfo command to get the needed information..."
@Image Analyst was asking for you to show the results of that command...
That is not what they asked... But I am obviously greatful for the any help! I run this in the command window to get the info for this one camera for testing, will do this more programmatically in the future. Here is the output of imaqhwinfo:
>> info = imaqhwinfo
info =
struct with fields:
InstalledAdaptors: {'gentl' 'gige'}
MATLABVersion: '23.2 (R2023b)'
ToolboxName: 'Image Acquisition Toolbox'
ToolboxVersion: '23.2 (R2023b)'
Here is the output of imaqhwinfo('gentl'):
info = imaqhwinfo('gentl')
info =
struct with fields:
AdaptorDllName: 'C:\ProgramData\MATLAB\SupportPackages\R2023b\toolbox\imaq\supportpackages\gentl\adaptor\win64\mwgentlimaq.dll'
AdaptorDllVersion: '23.2 (R2023b)'
AdaptorName: 'gentl'
DeviceIDs: {[1] [2] [3] [4]}
DeviceInfo: [1×4 struct]
The first 3 are "Simulated" and the 4th seems to be the actual camera.
Here is what I get for the GigE adapter:
info =
struct with fields:
AdaptorDllName: 'C:\ProgramData\MATLAB\SupportPackages\R2023b\toolbox\imaq\supportpackages\gige\adaptor\win64\mwgigeimaq.dll'
AdaptorDllVersion: '23.2 (R2023b)'
AdaptorName: 'gige'
DeviceIDs: {[1]}
DeviceInfo: [1×1 struct]
I have been mainly using gentl as early on I had issues with dropped frames on gige. Let me know if there is any other info I should provide.

Sign in to comment.

Answers (1)

I'm using a Teledyne camera with gentl. What happens if you call this attached InitializeVideoCamera function? It's meant to be called from an AppDesigner program so if you don't have that, just comment out the referenced to "app".

Products

Release

R2023b

Asked:

on 12 Mar 2026

Edited:

on 17 Mar 2026

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!