how do i add or draw the rectangles around movable object in real time video.enclosure:code

13 views (last 30 days)
vidDevice = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480', ... 'ROI', [1 1 640 480], ... 'ReturnedColorSpace', 'rgb', ... 'DeviceProperties.Brightness', 90, ... 'DeviceProperties.Sharpness', 90);
optical = vision.OpticalFlow( ... 'OutputValue', 'Horizontal and vertical components in complex form');
maxWidth = imaqhwinfo(vidDevice,'MaxWidth'); maxHeight = imaqhwinfo(vidDevice,'MaxHeight'); shapes = vision.ShapeInserter; shapes.Shape = 'lines'; shapes.BorderColor = 'white'; r = 1:5:maxHeight; c = 1:5:maxWidth; [Y, X] = meshgrid(c,r);
hVideoIn = vision.VideoPlayer; hVideoIn.Name = 'Original Video'; hVideoOut = vision.VideoPlayer; hVideoOut.Name = 'Motion Detected Video';
nFrames = 0; while (nFrames<2000) % Process for the first 100 frames. % Acquire single frame from imaging device. rgbData = step(vidDevice);
% Compute the optical flow for that particular frame.
optFlow = step(optical,rgb2gray(rgbData));
% Downsample optical flow field.
optFlow_DS = optFlow(r, c);
H = imag(optFlow_DS)*50;
V = real(optFlow_DS)*50;
% Draw lines on top of image
lines = [Y(:)'; X(:)'; Y(:)'+V(:)'; X(:)'+H(:)'];
rgb_Out = step(shapes, rgbData, lines');
% Send image data to video player
% Display original video.
step(hVideoIn, rgbData);
% Display video along with motion vectors.
step(hVideoOut, rgb_Out);
% Increment frame count
nFrames = nFrames + 1;
end
release(vidDevice);
release(hVideoIn);
release(hVideoOut);
displayEndOfDemoMessage(mfilename) clc

Answers (1)

Dima Lisin
Dima Lisin on 10 Nov 2014
You can use the insertShape function to draw a rectangle into the image.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!