how to implement optical flow algorithm on ip camera feed

3 views (last 30 days)
I have imported ip camera feed successfully in matlab by using below mentioned code.. but i m unable to implement optical flow algorithm for motion detection on it .. the optical flow algorithm is written to take video feed from webcam of my laptop.. i dont know how to change it so that it can take video feed from my ip camera... kindly help me out.
code used for importing ip cam feed :
url=('http://192.168.0.103:81/snapshot.jpg?user=admin&password=admin');
hVideoIn = vision.VideoPlayer('Name', 'Final Video');
while(1)
ss=imread(url);
step(hVideoIn,ss)
end
optical flow algorithm:
vidDevice = imaq.VideoDevice('winvideo', 1, 'MJPG_320x240')
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';
% Set up for stream
nFrames = 0;
while (nFrames<1000) % 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
  1 Comment
Nguyen Van Duong
Nguyen Van Duong on 27 Feb 2017
Edited: Nguyen Van Duong on 27 Feb 2017
% code
%Please download IP Camera Support from MATLAB
% code
cam = ipcam('http://192.168.2.1/?action=stream');
optical = vision.OpticalFlow( ...
'OutputValue', 'Horizontal and vertical components in complex form');
maxWidth = 640; %From your camera specs
maxHeight = 480; %From your camera specs
.
.
.
...
while (nFrames<100) % Process for the first 100 frames.
% Acquire single frame from imaging device.
rgbData = snapshot(cam);
rgbData = im2double(rgbData);

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB Support Package for IP Cameras 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!