Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 5 Gen 2018
int32 is not a supported datatype for insertShape
Use im2double to convert the frames to double.
DGM
DGM il 12 Set 2023
Modificato: DGM il 12 Set 2023
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.

Accedi per commentare.

Risposta accettata

Stalin Samuel
Stalin Samuel il 3 Nov 2014
change the data type suitable for your function
  3 Commenti
yogesh nandurkar
yogesh nandurkar il 5 Nov 2014
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 ....

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by