簡體   English   中英

使用IP網絡攝像頭的Matlab運動檢測可提供奇怪的顏色

[英]Matlab motion detection using IP Webcam giving weird colors

此代碼使用Android手機和應用程序“ IP Webcam”(URL由應用程序提供)以及手機和筆記本電腦通過手機的熱點進行連接。 我的視頻顏色有點問題。 它們只是黃色/白色和黑色的陰影。 有人可以幫我獲得合適的視頻嗎? 還是至少有一個比這更好的? 代碼: 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);

'YUY2_640x480'表示視頻以YUV格式而不是RGB格式'YUY2_640x480' 有兩種解決方法。 如果鍵入imaqtool ,則應該看到MATLAB可見的所有相機格式的列表。 如果您看到類似RGB_640x480 ,那應該會給您RGB視頻。 如果不是,請嘗試使用ycbcr2rgb函數將當前獲取的幀轉換為RGB。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM