how to implement optical flow algorithm on ip camera feed

21 Ansichten (letzte 30 Tage)
bashaar ilyas
bashaar ilyas am 28 Apr. 2015
Bearbeitet: Walter Roberson am 27 Feb. 2017
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 Kommentar
Nguyen Van Duong
Nguyen Van Duong am 27 Feb. 2017
Bearbeitet: Nguyen Van Duong am 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);

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu MATLAB Support Package for IP Cameras finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by