使用IP网络摄像头的Matlab运动检测给出了奇怪的颜色

时间:2015-04-27 08:48:51

标签: android matlab video-processing matlab-cvst motion-detection

此代码使用Android手机和应用程序“IP网络摄像头”(网址由应用程序提供),手机和笔记本电脑通过手机的热点连接。我对视频颜色有一些问题。它们只有黄色/白色和黑色。有人可以帮我找一个合适的视频吗?或者至少比这更好?代码:http://pastebin.com/RPBCVrzu 我把它贴在这里也是为了方便:

% vidDevice = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480', ...
% 'ROI', [1 1 640 480], ...
% 'ReturnedColorSpace', 'rgb');
url = 'http://192.168.43.1:8080/shot.jpg';
ss  = imread(url);
optical = vision.OpticalFlow('OutputValue', 'Horizontal and vertical components in complex form');
% maxWidth = imaqhwinfo(vidDevice,'MaxWidth');
% maxHeight = imaqhwinfo(vidDevice,'MaxHeight');
maxWidth=size(ss,2);
maxHeight=size(ss,1);
shapes = vision.ShapeInserter;
shapes.Shape = 'Lines';
shapes.BorderColor = 'Custom';
shapes.CustomBorderColor = [255 0 0];
r = 1:5:maxHeight;
c = 1:5:maxWidth;
[Y, X] = meshgrid(c,r);
 hVideoIn = vision.VideoPlayer;
 hVideoIn.Name = 'Original Video';
hVideoIn.Position = [30 100 640 480];
hVideoOut = vision.VideoPlayer;
hVideoOut.Name = 'Motion Detected Video';
hVideoOut.Position = [700 100 640 480];
nFrames = 0;
while (nFrames < Inf)
%rgbData = step(vidDevice);
rgbData=single(imread(url));
optFlow = step(optical,rgb2gray(rgbData));
optFlow_DS = optFlow(r, c);
H = imag(optFlow_DS)*50;
V = real(optFlow_DS)*50;
lines = [Y(:)'; X(:)'; Y(:)'+V(:)'; X(:)'+H(:)'];
rgb_Out = step(shapes, rgbData, lines');
step(hVideoIn, rgbData);
step(hVideoOut, rgb_Out);
nFrames = nFrames + 1;
end
release(hVideoOut);
release(hVideoIn);
release(vidDevice);

1 个答案:

答案 0 :(得分:0)

'YUY2_640x480'表示视频是以YUV格式而不是RGB格式。有两种方法可以解决这个问题。如果您键入imaqtool,您应该会看到MATLAB可见的所有相机格式的列表。如果您看到类似RGB_640x480的内容,那么应该会为您提供RGB视频。如果没有,请尝试使用ycbcr2rgb函数将当前获取的帧转换为RGB。