Real time display of a video and its marker
    1 次查看(过去 30 天)
  
       显示 更早的评论
    
Hello, I made a matlab programm to track the center of 2 circles. Now, I would like to make a GUI to show the video runing AND the distance beetewen the two markers. I succed to display the distance of the 2 markers, but the probleme now is that in the while line 202 (at the end), I am unable to know what I have to write after "set(handles.Video,...." to display my video on the axes taged Video (cf attachment). I don't know if I have to write it in or after the "while" or if the syntax to run the video is usable with the syntax I want.
I past all the code, but the problem is in the while (at the end)
function varargout = HARMO_GUI(varargin)
% HARMO_GUI MATLAB code for HARMO_GUI.fig
%      HARMO_GUI, by itself, creates a new HARMO_GUI or raises the existing
%      singleton*.
%
%      H = HARMO_GUI returns the handle to a new HARMO_GUI or the handle to
%      the existing singleton*.
%
%      HARMO_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in HARMO_GUI.M with the given input arguments.
%
%      HARMO_GUI('Property','Value',...) creates a new HARMO_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before HARMO_GUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to HARMO_GUI_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help HARMO_GUI
% Last Modified by GUIDE v2.5 18-Aug-2017 13:50:36
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @HARMO_GUI_OpeningFcn, ...
                   'gui_OutputFcn',  @HARMO_GUI_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before HARMO_GUI is made visible.
function HARMO_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to HARMO_GUI (see VARARGIN)
% Choose default command line output for HARMO_GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes HARMO_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = HARMO_GUI_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
set(handles.dist,'String',num2str([0 0]));
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Choix de l'image
[FileName PathName]=uigetfile('*.*');
TotalPath = [PathName FileName]
% Screenshot première image de la vidéo
obj = VideoReader(TotalPath);
this_frame = readFrame(obj);
thisfig = figure();
thisax = axes('Parent', thisfig);
image(this_frame, 'Parent', thisax);
this_frame=this_frame(:,:,3);
imagesc(this_frame);
uiwait(msgbox(('Selectionnez le fond de la première tâche'),'Information','modal'));
%determination de la couleur moyenne des tâches
Fond=double(imcrop(gca));    %Selectionne le fond de la première tâche
Fond1=mean(mean(Fond(:,:)));    % Calcule la moyene du fond
uiwait(msgbox(('Selectionnez le fond de la deuxième tâche'),'Information','modal'));
Fond=double(imcrop(gca));    %Selectionne le fond de la deuxième tâche
Fond2=mean(mean(Fond(:,:)));    % Calcule la moyene du fond
%Ouverture de l'image 
imagesc(this_frame)
uiwait(msgbox(('Selectionnez à main levée le premier cercle (selectionez assez large autour)'),'Information','modal'));
% Selection de la première cible
handROI = imfreehand(gca);
uiwait(msgbox(('Selectionnez à main levée le deuxième cercle (selectionez assez large autour)'),'Information','modal'));
% Selection de la deuxième cible
handROI2 = imfreehand(gca); 
% Création des masques
FW = createMask(handROI);
FW2 = createMask(handROI2);
% Détermination des matrices
Tache1=zeros(length(this_frame(:,1)),length(this_frame(1,:)),length(this_frame(1,1)));
Tache2=zeros(length(this_frame(:,1)),length(this_frame(1,:)),length(this_frame(1,1)));
for i=1:length(this_frame(:,1))   
    for j=1:length(this_frame(1,:))
          % Remplissage des matrices Nir
          Tache1(i,j)=uint8(FW(i,j))*this_frame(i,j);  
          Tache2(i,j)=uint8(FW2(i,j))*this_frame(i,j);
  end
end
for i=1:length(this_frame(:,1))
    for j=1:length(this_frame(1,:))
          %Détermination de la zone avec la tache
          if (Tache1(i,j)<Fond1+30) && (Tache1(i,j)>Fond1-30)
              Tache1(i,j)=1;
          else Tache1(i,j)=0;
          end
          %Détermination de la zone avec la tache 2
          if (Tache2(i,j)<Fond2+30) && (Tache2(i,j)>Fond2-30)
              Tache2(i,j)=1;
          else Tache2(i,j)=0;
          end
    end
  end
save('usersettings3.mat','this_frame','Tache1','Tache2','TotalPath');
close figure 1
clc
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
load('usersettings3.mat');
compteur1=0;
compteur2=0;
barycentre1=[0 0];
barycentre2=[0 0];
for i=1:length(this_frame(:,1))
  for j=1:length(this_frame(1,:))
          %Détermination du barycentre de la tâche 1
          if Tache1(i,j)==1
              compteur1=compteur1+1;
              barycentre1(1)=barycentre1(1)+i;
              barycentre1(2)=barycentre1(2)+j;
          end
          %Détermination du barycentre de la tâche 2
          if Tache2(i,j)==1
              compteur2=compteur2+1;
              barycentre2(1)=barycentre2(1)+i;
              barycentre2(2)=barycentre2(2)+j;
          end
      end
  end
  barycentre1=barycentre1/compteur1;
  barycentre2=barycentre2/compteur2;
% Création des points à tracker
videoFileReader = vision.VideoFileReader(TotalPath);
videoPlayer = vision.VideoPlayer;
frame = step(videoFileReader);
pointTracker = vision.PointTracker;
pointTracker2 = vision.PointTracker;
initialize(pointTracker,[barycentre1(2) barycentre1(1)],frame);
%initialize(pointTracker2,[barycentre2(2) barycentre2(1)],frame);
point(2,:) = [barycentre2(2) barycentre2(1)]; % la référence est immobile
while ~isDone(videoFileReader) 
    frame = step(videoFileReader);
    point(1,:) = step(pointTracker,frame);
    %      point(2,:) = step(pointTracker2,frame); permet de tracker la ref
    out = insertMarker(frame,point,'x');
      % Calcule du barycentre
    point(3,:)=[abs((point(2,2) - point(1,2))) abs((point(2,1) - point(1,1)))];
      step(videoPlayer,out);
      set(handles.dist,'String',num2str(point(3,:)))
  end
0 个评论
采纳的回答
  Image Analyst
      
      
 2017-8-18
        Try putting a "drawnow" just before the end of your loop.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!