how to implement optical flow algorithm on ip camera feed

조회 수: 19 (최근 30일)
bashaar ilyas
bashaar ilyas 2015년 4월 28일
편집: Walter Roberson 2017년 2월 27일
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
Nguyen Van Duong
Nguyen Van Duong 2017년 2월 27일
편집: Nguyen Van Duong 2017년 2월 27일
% 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);

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for IP Cameras에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by