How to fix STEP not enough input arguments?

7 Ansichten (letzte 30 Tage)
Diom Larin
Diom Larin am 3 Nov. 2015
Bearbeitet: Daemonic am 17 Jan. 2018
I have been trying codes in the internet that will be used for our project, and some codes are working perfectly if used individually but the essence of our project is to combine all of these image processing techniques.
here is the code where the function STEP is not working.
% Add the callback function directory to the MATLAB® path.
utilpath = fullfile(matlabroot, 'toolbox', 'imaq', 'imaqdemos', 'helper');
addpath(utilpath);
% Access an image acquisition device.
vidobj = videoinput('winvideo');
% Convert the input images to grayscale.
vidobj.ReturnedColorSpace = 'grayscale';
% Retrieve the video resolution.
vidRes = vidobj.VideoResolution;
% Create a figure and an image object.
f = figure('Visible', 'off');
% The Video Resolution property returns values as width by height, but
% MATLAB images are height by width, so flip the values.
imageRes = fliplr(vidRes);
subplot(1,2,1);
hImage = imshow(zeros(imageRes));
% Set the axis of the displayed image to maintain the aspect ratio of the
% incoming frame.
axis image;
setappdata(hImage,'UpdatePreviewWindowFcn',@update_livehistogram_display);
% Here are the contents of update_livehistogram_display.m which contains
% the callback function.
dbtype('update_livehistogram_display.m');
% The PREVIEW function starts the camera and display. The image on which to
% display the video feed is also specified.
preview(vidobj, hImage);
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ...
'NumTrainingFrames', 50);
for i = 1:150
frame = step(vidobj); % read the next video frame
foreground = step(foregroundDetector, frame);
end
%After the training, the detector begins to output more reliable segmentation results.
%The two figures below show one of the video frames and the foreground mask computed by the detector.
subplot(2,2,1); imshow(frame); title('Video Frame');
subplot(2,2,2); imshow(foreground); title('Foreground');
%The foreground segmentation process is not perfect and often includes undesirable noise.
%The example uses morphological opening to remove the noise and to fill gaps in the detected objects.
se = strel('square', 3);
filteredForeground = imopen(foreground, se);
subplot(2,2,3); imshow(filteredForeground); title('Clean Foreground');
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', false, 'CentroidOutputPort', false, ...
'MinimumBlobArea', 150);
bbox = step(blobAnalysis, filteredForeground);
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
numCars = size(bbox, 1);
result = insertText(result, [10 10], numCars, 'BoxOpacity', 1, ...
'FontSize', 14);
figure; imshow(result); title('Detected Cars');
videoPlayer = vision.VideoPlayer('Name', 'Detected Cars');
videoPlayer.Position(3:4) = [650,400]; % window size: [width, height]
se = strel('square', 3); % morphological filter for noise removal
while ~isDone(vidobj)
frame = step(vidobj); % read the next video frame
% Detect the foreground in the current video frame
foreground = step(foregroundDetector, frame);
% 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(frame, 'Rectangle', bbox, 'Color', 'green');
% Display the number of cars found in the video frame
numCars = size(bbox, 1);
result = insertText(result, [10 10], numCars, 'BoxOpacity', 1, ...
'FontSize', 14);
step(videoPlayer, result); % display the results
end
release(vidobj); % close the video file
% View the histogram for 30 seconds.
pause(30);
% Stop the preview image and delete the figure.
stoppreview(vidobj);
delete(f);
delete(vidobj)
clear vidobj
so far if i seperate the optical flow and blob detection to the histogram extension technique the code works perfectly, but if they are combined the step function seems to miss an input argument.
but this is not the case if we use a prerecorded video.
is there a way to use STEP function while using a live acquisition video??
this is the error :
Error using step (line 84)
Not enough input arguments.
Error in Histogram_and_OpticalBLOB (line 42)
frame = step(vidobj); % read the next video frame
any suggestion is appreciated thanks in advance :)

Antworten (1)

Daemonic
Daemonic am 17 Jan. 2018
Bearbeitet: Daemonic am 17 Jan. 2018
I was running into the same problem. Instead of using videoinput to define your video object, Try:
vidobj = imaq.VideoDevice('winvideo', 1);
A full example can be found in the documentation: https://www.mathworks.com/help/imaq/imaq.videodevice.html

Community Treasure Hunt

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

Start Hunting!

Translated by