Live video to frames, detect people

3 vues (au cours des 30 derniers jours)
Han
Han le 1 Mar 2018
Commenté : Image Analyst le 2 Mar 2018
Hi all
I'm trying to write a program to detect people who are wearing white things .. whatever it's.
I faced difficult to convert live video to frames so I compare it with background !
Code:
function ForMe_OpeningFcn(hObject, eventdata, handles, varargin)
vid = videoinput('winvideo',1);
handles.video = vid;
set(handles.video,'TimerPeriod', 0.05, ...
'TimerFcn',['if(~isempty(gco)),'...
'handles=guidata(gcf);'...
'image(getsnapshot(handles.video));'...
'set(handles.axes1,''ytick'',[],''xtick'',[]),'...
'else '...
'end']);
set(vid,'FramesPerTrigger',1);
%vid.FrameGrabInterval = 2;
set(vid,'TriggerRepeat',Inf);
triggerconfig(vid, 'Manual');
handles.output = hObject;
guidata(hObject, handles);
uiwait
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
vid = handles.video;
start(vid);
trigger(vid);
BackgroundImage = getsnapshot(vid);
I1 = rgb2gray(BackgroundImage);
figure;
subplot(2,2,1);
imshow(I1);
title('background');
pause(2);
while 1
frames = getdata(vid);
I2 = rgb2gray(frames);
subplot(2,2,2);
imshow(I2);
title('frames');
pause(2);
Objects = I1 ~= I2;
BlobAnalysis = vision.BlobAnalysis('MinimumBlobArea',20000,'MaximumBlobArea',40000);
[area,centroid,BoundingBox] = step(BlobAnalysis,Objects);
[row , col ] = size (BoundingBox);
for i=1 : row
x = BoundingBox(i,1);
y =BoundingBox(i,2);
w=BoundingBox(i,3);
h=BoundingBox(i,4);
TestImage = frames(y :(y+h),x:(x+w), :);
r = TestImage(:,:,1);
g = TestImage(:,:,2);
b = TestImage(:,:,3);
subplot(2,2,3);
title('Histogram');
histogram2(r,g,'DisplayStyle','tile','ShowEmptyBins','on', ...
'XBinLimits',[0 255],'YBinLimits',[0 255]);
histogram(r,'BinMethod','integers','FaceColor','r','EdgeAlpha',0,'FaceAlpha',1)
hold on
histogram(g,'BinMethod','integers','FaceColor','g','EdgeAlpha',0,'FaceAlpha',0.7)
histogram(b,'BinMethod','integers','FaceColor','b','EdgeAlpha',0,'FaceAlpha',0.7)
xlabel('RGB value')
ylabel('Frequency')
title('Color Histogram')
xlim([0 257])
thresholding = 2097150;
rth=graythresh(TestImage(:,:,1))*255
gth=graythresh(TestImage(:,:,2))*255
bth=graythresh(TestImage(:,:,3))*255
if ( rth*gth*bth >= thresholding )
% Ishape = insertShape(object,'rectangle',BoundingBox,'Color', 'green','Linewidth',6);
msgbox('Alarm it is white !');
load gong.mat;
while ( rth*gth*bth >= thresholding)%endless loop
sound(y);
lastTime = clock;
while etime(clock, lastTime) < 5
pause(0.03);
end
break;
end
else
msgbox('ok');
end
clear TestImage;
end
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
vid = handles.video;
stop (vid);
guidata(hObject, handles)
Errors:
Error event occurred at 00:17:26 for video input object: MJPG_1280x720-winvideo-1.
GETDATA timed out before FRAMES were available.
Error using imaqdevice/getdata (line 148)
GETDATA timed out before FRAMES were available.
Error in ForMe>pushbutton1_Callback (line 87)
frames = getdata(vid);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in ForMe (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ForMe('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error using uiwait (line 81)
Error while evaluating UIControl Callback
Struct contents reference from a non-struct array object.
Error in ForMe>ForMe_OutputFcn (line 71)
varargout{1} = handles.output;
Error in gui_mainfcn (line 264)
feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
Error in ForMe (line 42)
gui_mainfcn(gui_State, varargin{:});
Thank you ..

Réponses (1)

Image Analyst
Image Analyst le 1 Mar 2018
It looks like your camera is not sending video, perhaps because you set your trigger to manual. I don't have any experience with manual triggering. I don't use it, I just let the camera run all the time and call getsnapshot() to grab a frame from the live video.
  2 commentaires
Han
Han le 1 Mar 2018
Thank you for your answer ..
I delete this satement
triggerconfig(vid, 'Manual');
and I get this error:
Error event occurred at 00:52:05 for video input object: MJPG_1280x720-winvideo-1.
Unable to allocate memory for an incoming image frame due to insufficient free physical memory.
Error in ForMe>pushbutton1_Callback (line 91)
pause(1);
Image Analyst
Image Analyst le 2 Mar 2018
I don't know. I can't tell just by looking at one of your GUI functions. Plus, I don't have the same type of camera you do. Call tech support.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by