how to implement optical flow algorithm on ip camera feed
3 ビュー (過去 30 日間)
古いコメントを表示
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
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 Center および File 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!