Matlab GUI не показывает данные графика - PullRequest
2 голосов
/ 15 июня 2019

Я работаю с моим файлом Matlab GUI для воспроизведения видео и построения среднего значения из цветового канала (RGB). Он имеет 2 оси, первую для видеоплеера и вторую ось для среднего графика, но вторая ось не показывает никаких данных, она просто обновляет координаты x и y, но ничего не показывает.

Я пытался изменить дескрипторы, изменяет следующий параметр графика в инспекторе свойств, но он не работает

function main_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;
video = vision.VideoFileReader();
handles.video = video;
frameCount = 0;
handles.frameCount = frameCount;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.

function varargout = main_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
handles.output = hObject;
varargout{1} = handles.output;
% --- Executes on button press in Browse.

function Browse_Callback(hObject, eventdata, handles)
% hObject    handle to Browse (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[ video_file_name,video_file_path ] = uigetfile({'*.avi'},'Pick a video file');      %;*.png;*.yuv;*.bmp;*.tif'},'Pick a file');
if(video_file_path == 0)
    return;
end
input_video_file = [video_file_path,video_file_name];
fullpath = strcat(video_file_path,video_file_name);
set(handles.edit1,'String',fullpath);
video = vision.VideoFileReader(input_video_file);
vidFrame = step(video);
axes(handles.axes1);set(handles.StartButton,'String','Start');
frameCount = 1;
imshow(vidFrame);
drawnow;
axis(handles.axes1,'off');
   for nChannel = 1:3
       colorChannel = vidFrame(:,:,nChannel);
       rawColorSignal(nChannel,frameCount) =  mean(mean(colorChannel));
   end

%plot(frameCount,rawColorSignal(1, :),frameCount,rawColorSignal(2, :),frameCount,rawColorSignal(3, :), handles.axes2);
axes(handles.axes2)
plot(frameCount,rawColorSignal(1, :));
grid on
drawnow;
axes(handles.axes1)
% Display Frame Number
%Update handles
handles.video = video;
guidata(hObject,handles);

% --- Executes on button press in StartButton.
function StartButton_Callback(hObject, eventdata, handles)
% hObject    handle to StartButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if strcmp(get(handles.StartButton,'String'),'Pause')
    set(handles.StartButton,'String','Start');
else
    set(handles.StartButton,'String','Pause');
end
video = handles.video;
if  isDone(video)
    reset(video)
    frameCount = 0;
    handles.frameCount = frameCount;
end
frameCount = handles.frameCount;
 while ~isDone(video) && strcmp(get(handles.StartButton,'String'),'Pause')
     vidFrame   = step(video);
     imshow(vidFrame,'Parent',handles.axes1); %plot frame is specific axis
     drawnow;
    frameCount = frameCount + 1;
    for nChannel = 1:3
       colorChannel = vidFrame(:,:,nChannel);
       rawColorSignal(nChannel,frameCount) =  mean(mean(colorChannel));
    end

    plot(frameCount,rawColorSignal(1, :),'Parent',handles.axes2);
    grid on
    drawnow;
 end

%plot(frameCount,rawColorSignal(1, :),'r',frameCount,rawColorSignal(2, :),'g',frameCount,rawColorSignal(3, :),'b','Parent', handles.axes2);
%drawnow;
 set(handles.StartButton,'String','Start');
% --- Executes on button press in PauseButton.
function PauseButton_Callback(hObject, eventdata, handles)
% hObject    handle to PauseButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%axes(handles.axes2)
%surf(membrane(3))

Я ожидал, что линейный график будет виден и обновляется вдоль осей.

1 Ответ

0 голосов
/ 15 июня 2019

Я думаю, что нашел проблему:

Заменить: plot(frameCount,rawColorSignal(1, :));
С: plot(1:frameCount,rawColorSignal(1, :));

Заменить: plot(frameCount,rawColorSignal(1, :),'Parent',handles.axes2);
С: plot(1:frameCount,rawColorSignal(1, :),'Parent',handles.axes2);


plot(frameCount, ... использует скаляр frameCount в качестве координат X.
Вы хотите, чтобы координаты X на вашем графике были вектором, который изменяется от 1 до frameCount.

Если вы получаете ошибку, попробуйте:
plot(1:length(rawColorSignal(1, :)), rawColorSignal(1, :), 'Parent', handles.axes2);

Not plotting


Я создал следующееПример кода для демонстрации проблемы:

Следующий пример не отображает:

frameCount = 0;
rawColorSignal = [];

for i = 1:10
    frameCount = frameCount + 1;
    rawColorSignal(frameCount) =  i;
end

plot(frameCount, rawColorSignal);
grid on
drawnow;

При замене plot(frameCount, rawColorSignal); на plot(1:frameCount, rawColorSignal); он делает:

frameCount = 0;
rawColorSignal = [];

for i = 1:10
    frameCount = frameCount + 1;
    rawColorSignal(frameCount) =  i;
end

plot(1:frameCount, rawColorSignal);
grid on
drawnow;

Plotting

...