Error using imaq.VideoDevice

Hello, I made such a code for my project, but
Error using imaq.internal.VideoDeviceInternalNo device is available at the specified DEVICEID. See IMAQHWINFO('winvideo').Error in imaq.VideoDevice
My camera: a4 tech pk-636k
I'm getting an error like this, if you can help I'd appreciate it.
%% Detecting Motions Using Gaussian Mixture MOdel
%
%
%
%https://ch.mathworks.com/help/vision/examples/detecting-cars-using-gaussian-mixture-models.html
%
%%
clear all; close all;
clc;
%%
FRAME_WIDTH = 1280;
FRAME_HEIGHT = 720;
vidDevice = imaq.VideoDevice('winvideo', 2, strcat('MJPG_',num2str(FRAME_WIDTH),'x',num2str(FRAME_HEIGHT)), ... % Acquire input video stream
'ROI', [1 1 FRAME_WIDTH FRAME_HEIGHT], ...
'ReturnedColorSpace', 'rgb');
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ...
'NumTrainingFrames', 50);
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', false, 'CentroidOutputPort', false, ...
'MinimumBlobArea', 3500);
se = strel('square', 5); % morphological filter for noise removal
%% Train Foreground Detector
disp('Training');
for i = 1:150
disp(strcat('step#',num2str(i)));
frame = step(vidDevice); % read the next video frame
foreground = step(foregroundDetector, frame);
end
disp('Training Complete');
%%
for i=1:400
rgbFrame = step(vidDevice);
rgbFrame=flip(rgbFrame,2);
grayFrame = rgb2gray(rgbFrame);
grayFrame = imgaussfilt(grayFrame,4);
% Detect the foreground in the current video frame
foreground = step(foregroundDetector, rgbFrame);
% Use morphological opening to remove noise in the foreground
filteredForeground = imopen(foreground, se);
% Detect the connected components with the specified minimum area, and
% compute their bounding boxes
bbox = step(blobAnalysis, filteredForeground);
% Draw bounding boxes around the detected cars
result = insertShape(rgbFrame, 'Rectangle', bbox, 'Color', 'green','LineWidth', 5);
% Display the number of cars found in the video frame
numCars = size(bbox, 1);
result = insertText(result, [10 10], numCars, 'BoxOpacity', 1, ...
'FontSize', 14);
figure(5),imshow(result);
% step(videoPlayer, result); % display the results
end
%%
release(vidDevice)

回答 (3 件)

Image Analyst
Image Analyst 2021 年 12 月 29 日

1 投票

What does this show fpr you?
>> imaqhwinfo
ans =
struct with fields:
InstalledAdaptors: {'gentl' 'lumeneraimaq' 'winvideo'}
MATLABVersion: '9.11 (R2021b)'
ToolboxName: 'Image Acquisition Toolbox'
ToolboxVersion: '6.5 (R2021b)'

9 件のコメント

trk
trk 2021 年 12 月 31 日
Sir, I'm sorry, I don't know much about matlab, I didn't know exactly where to cut this code.
Image Analyst
Image Analyst 2021 年 12 月 31 日
Type that into the command window.
trk
trk 2022 年 1 月 1 日
Sir is giving eror again.
Image Analyst
Image Analyst 2022 年 1 月 1 日
You're not supposed to paste in the answer for my system. You're supposed to just call imaqhwinfo
imaqhwinfo
Type that into the command line.
trk
trk 2022 年 1 月 3 日
Walter Roberson
Walter Roberson 2022 年 1 月 3 日
編集済み: Image Analyst 2022 年 1 月 3 日
vidDevice = imaq.VideoDevice('winvideo', 2, strcat('MJPG_',num2str(FRAME_WIDTH),'x',num2str(FRAME_HEIGHT)), ... % Acquire input video stream
'ROI', [1 1 FRAME_WIDTH FRAME_HEIGHT], ...
'ReturnedColorSpace', 'rgb');
You are asking for the second device (#2) but you only have one winvideo device. Try
videoRes = sprintf('MJPG_%dx%d', FRAME_WIDTH, FRAME_HEIGHT)
% Acquire input video stream. Instantiate vidDevice object.
vidDevice = imaq.VideoDevice('winvideo', 1, ...
videoRes, ...
'ROI', [1, 1, FRAME_WIDTH, FRAME_HEIGHT], ...
'ReturnedColorSpace', 'rgb');
Image Analyst
Image Analyst 2022 年 1 月 3 日
See if the attached program runs for you. It is more robust than what you've done and tried to automatically find the video source. Works for winvideo and my Logitech web cam.
trk
trk 2022 年 1 月 3 日
Sir, it is giving an error again. I have one more question for you. There would be an article for Motion Detection that I can read, a resource I can use, for example, if you could give me advice on how it works, I would be very happy because this is my final project, but there is always a problem, I need to research thoroughly and for my presentation.
Image Analyst
Image Analyst 2022 年 1 月 3 日
I don't see a line number there. Tell the debugger to run but stop on any error and tell me what line number it is throwing the error on.

サインインしてコメントする。

yanqi liu
yanqi liu 2021 年 12 月 30 日

0 投票

yes,sir,may be use
vidDevice = imaq.VideoDevice('winvideo', 1, strcat('MJPG_',num2str(FRAME_WIDTH),'x',num2str(FRAME_HEIGHT)), ... % Acquire input video stream
'ROI', [1 1 FRAME_WIDTH FRAME_HEIGHT], ...
'ReturnedColorSpace', 'rgb');
Pham
Pham 2023 年 2 月 8 日

0 投票

Hello, I made such a code for my project, but
Error using imaq.internal.VideoDeviceInternal
Invalid VIDEOFORMAT 'YUY2_640x480' specified. VIDEOFORMAT must be specified as a string. The available
formats on this device are {RGB24_640x480}.
Error in imaq.VideoDevice

1 件のコメント

Walter Roberson
Walter Roberson 2023 年 2 月 8 日
What is your call to imaq.VideoDevice ?
What hardware (brand and model) of camera are you using?

サインインしてコメントする。

質問済み:

trk
2021 年 12 月 29 日

コメント済み:

2023 年 2 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by