Error using videoinput - Width and height values for ROIPosition must be greater than 0.

10 views (last 30 days)
Hello everyone,
I'm trying to write a code in App Designer for the Lab. A part of it should just read in the input of a camera (Basler puA 1600-60uc) and display a live preview on a specified axes. Now my problem is that the code only works in 50% of cases. I never used App Designer and I don't know how to debug a code that sometimes works and starts the preview... and sometimes the program just closes itself and an error message is displayed. I'd be thankful if anyone could help me correct the code, so it just starts the camera reliably.
The Startup Fcn contains code to clear all.
The code I use to start the camera (from a previous search):
vHeight = 1200;
vWidth = 1600;
% Image acquisition
app.camObj = videoinput('gentl', 1,'BayerRG8');
% Create blank image
app.hImage = image(app.UIPreview,zeros(vHeight,vWidth,3));
pause(2);
% Aspect ratio
app.UIPreview.XLim = [0,vWidth];
app.UIPreview.YLim = [0,vHeight];
app.UIPreview.XTick = [];
app.UIPreview.YTick = [];
pbaspect(app.UIPreview,[vWidth,vHeight,1]);
% Preview the image
preview(app.camObj,app.hImage);
'gentl' and 'BayerRG8' per se is correct, I checked.
The error message I am getting:
Thank you in advance.
  3 Comments
Walter Roberson
Walter Roberson on 25 Aug 2022
app.camObj = videoinput('gentl', 1,'BayerRG8');
What happens if the camera is already in use or disconnected?
Jessica Winkler
Jessica Winkler on 27 Aug 2022
It just closes the app and shows "Error using videoinput: There are no devices installed for the specified
ADAPTORNAME. See IMAQHWINFO."

Sign in to comment.

Answers (1)

Swaraj
Swaraj on 17 Jan 2024
Hi Jessica,
The error message indicates that "ROIPosition" is not set for the videoinput object. You can try the below code and check if it works fine for the cases where this error is getting thrown.
app.camObj = videoinput('gentl', 1,'BayerRG8');
app.camObj.ROIPosition = [10,10,500,500];
You can find more information in the below documentation.
Hope it helps!!

Community Treasure Hunt

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

Start Hunting!