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
2018년 1월 5일
int32 is not a supported datatype for insertShape
Use im2double to convert the frames to double.
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])
% you could do it the hard way
B = (double(A) + 2147483648)/4294967295
% before anybody mentions it, no, this is wrong
C = mat2gray(A)
% but this works
D = mat2gray(A,[-2147483648 2147483647])
% but using im2double() will fail with an error
F = im2double(A)
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.
채택된 답변
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!