フィルターのクリア

why do i reaceive this masage Undefined function 'insertShape' for input arguments of type 'int32'.

1 回表示 (過去 30 日間)
vidDevice = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480', ...
'ROI', [1 1 640 480], ...
'ReturnedColorSpace', 'rgb', ...
'DeviceProperties.Brightness', 90, ...
'DeviceProperties.Sharpness', 90);
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ...
'NumTrainingFrames', 50);
for i = 1:150
frame = step(vidDevice); % read the next video frame
foreground = step(foregroundDetector, frame);
end
figure; imshow(frame); title('Video Frame');
figure; imshow(foreground); title('Foreground');
se = strel('square', 3);
filteredForeground = imopen(foreground, se);
figure; 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')
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 1 月 5 日
int32 is not a supported datatype for insertShape
Use im2double to convert the frames to double.
DGM
DGM 2023 年 9 月 12 日
編集済み: DGM 2023 年 9 月 12 日
There are two problems here. The first is rather direct. You're calling insertshape(), not insertShape(). If you had been using the right capitalization, the error you would get if either the image or the color tuple were int32 would be different:
Error using insertShape
Expected Color to be one of these types:
uint8, uint16, int16, double, single
Instead its type was int32.
So you need to use the correct capitalizaiton, but the inputs you're providing aren't supported anyway. You'll need to convert them to a standard image class.
Trying to use im2double() won't work for the same reason. It also only supports the same standard image classes (uint8, uint16, int16, double, single, and logical). Anything else will cause an error.
% an int32 input array equivalent to (1:4)/5
A = int32([-1288490189 -429496730 429496729 1288490188])
A = 1×4
-1288490189 -429496730 429496729 1288490188
% you could do it the hard way
B = (double(A) + 2147483648)/4294967295
B = 1×4
0.2000 0.4000 0.6000 0.8000
% before anybody mentions it, no, this is wrong
C = mat2gray(A)
C = 1×4
0 0.3333 0.6667 1.0000
% but this works
D = mat2gray(A,[-2147483648 2147483647])
D = 1×4
0.2000 0.4000 0.6000 0.8000
% but using im2double() will fail with an error
F = im2double(A)
Error using im2double
Expected input number 1, Image, to be one of these types:

double, logical, uint8, uint16, int16, single

Instead its type was int32.

Error in im2double (line 36)
validateattributes(img,{'double','logical','uint8','uint16','int16','single'},{}, ...
Note that all of these options presume a fixed input class and output class. You would have to rewrite everything if either changed. If you were using MIMT, this would all be simple, provided that the input array is correctly-scaled for its class.
% things are simple in MIMT
G = imcast(A,'double') % or pick any output class you want
% works for:
% 'uint8','uint16','uint32','int8','int16','int32','double','single','logical'
... but 32-bit integer support is only in the more recent versions, so that wouldn't have been an option in 2018.

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

採用された回答

Stalin Samuel
Stalin Samuel 2014 年 11 月 3 日
change the data type suitable for your function
  3 件のコメント
yogesh nandurkar
yogesh nandurkar 2014 年 11 月 5 日
i have change the data type bbox to single but still error has been occured Undefined function 'insertShape' for input arguments of type 'single'. plz reply ....
Walter Roberson
Walter Roberson 2018 年 1 月 5 日
insertShape requires the computer vision toolbox.

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

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by