Custom preview gui with buttons
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
So Im trying to reproduce this example:
https://de.mathworks.com/help/imaq/previewing-data.html#f11-76072
by using a figure window made with GUIDE.
At the moment, my code looks like this:
function varargout = aufnehmen_speichern(varargin)
% AUFNEHMEN_SPEICHERN MATLAB code for aufnehmen_speichern.fig
% AUFNEHMEN_SPEICHERN, by itself, creates a new AUFNEHMEN_SPEICHERN or raises the existing
% singleton*.
%
% H = AUFNEHMEN_SPEICHERN returns the handle to a new AUFNEHMEN_SPEICHERN or the handle to
% the existing singleton*.
%
% AUFNEHMEN_SPEICHERN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in AUFNEHMEN_SPEICHERN.M with the given input arguments.
%
% AUFNEHMEN_SPEICHERN('Property','Value',...) creates a new AUFNEHMEN_SPEICHERN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before aufnehmen_speichern_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to aufnehmen_speichern_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 aufnehmen_speichern
% Last Modified by GUIDE v2.5 25-Sep-2017 10:32:37
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @aufnehmen_speichern_OpeningFcn, ...
'gui_OutputFcn', @aufnehmen_speichern_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 aufnehmen_speichern is made visible.
function aufnehmen_speichern_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 aufnehmen_speichern (see VARARGIN)
% Choose default command line output for aufnehmen_speichern
handles.output = hObject;
imaqreset;
vid1 = videoinput('gige', 1,'Mono8');
vid2 = videoinput('gige', 2,'Mono8');
vidRes = vid1.VideoResolution;
imWidth = vidRes(1);
imHeight = vidRes(2);
nBands = vid1.NumberOfBands;
hImage1 = image(zeros(imHeight,imWidth,nBands),'Parent',handles.axes1);
src1 = getselectedsource(vid1);
src2 = getselectedsource(vid2);
set(vid1, 'LoggingMode', 'memory');
set(vid2, 'LoggingMode', 'memory');
src1.AcquisitionStartTriggerMode = 'On';
src2.AcquisitionStartTriggerMode = 'On';
triggerconfig(vid1, 'hardware', 'DeviceSpecific', 'DeviceSpecific');
triggerconfig(vid2, 'hardware', 'DeviceSpecific', 'DeviceSpecific');
src1.AcquisitionStartTriggerActivation = 'FallingEdge';
src2.AcquisitionStartTriggerActivation = 'FallingEdge';
src1.AcquisitionStartTriggerSource = 'Line1';
src2.AcquisitionStartTriggerSource = 'Line1';
src1.AcquisitionEndTriggerSource = 'Line1';
src2.AcquisitionEndTriggerSource = 'Line1';
src1.AcquisitionRecordTriggerSource = 'Line1';
src2.AcquisitionRecordTriggerSource = 'Line1';
src1.StreamBytesPerSecond = 60000000;
src2.StreamBytesPerSecond = 60000000;
src1.AcquisitionFrameRateAbs = 30.000300003;
src2.AcquisitionFrameRateAbs = 30.000300003;
src1.PacketSize = 1500;
src2.PacketSize = 1500;
vid1.FramesPerTrigger = Inf;
vid2.FramesPerTrigger = Inf;
start(vid1);
start(vid2);
preview(vid1, hImage1);
preview(vid2);
imaqmem(1000000000000);
%setappdata(hImage1,'UpdatePreviewWindowFcn',@mypreview_fcn);
%setappdata(hImage1,'HandleToTimestampLabel',handles.text1);
%setappdata(hImage1,'HandleToResolution',handles.text2);
%setappdata(hImage1,'HandleToStatus',handles.text3);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes aufnehmen_speichern wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = aufnehmen_speichern_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;
% --- Executes on button press in zurueck.
function return_Callback(hObject, eventdata, handles)
% hObject handle to zurueck (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;
main;
% --- Executes on button press in exit.
function exit_Callback(hObject, eventdata, handles)
% hObject handle to exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close;
% --- Executes on button press in get_data.
function get_data_Callback(hObject, eventdata, handles)
% hObject handle to get_data (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imaqmem(1000000000000);
diskLogger1 = VideoWriter('D:\Matlab Sciebo\Hummeln 2017\Kalibrierung\Test\links01.avi', 'Grayscale AVI');
diskLogger2 = VideoWriter('D:\Matlab Sciebo\Hummeln 2017\Kalibrierung\Test\rechts01.avi', 'Grayscale AVI');
diskLogger1.FrameRate = 35;
diskLogger2.FrameRate = 35;
open(diskLogger1);
open(diskLogger2);
data1 = getdata(vid1, vid1.FramesAvailable);
data2 = getdata(vid2, vid2.FramesAvailable);
numFrames1 = size(data1, 4);
numFrames2 = size(data2, 4);
for ii = 1:numFrames1
writeVideo(diskLogger1, data1(:,:,:,ii));
%Wenn die Aufnahmedauer länger als 10000 Frames geht, kann es zu Problemen kommen. Über die If- break kann die Dauer eingestellt werden.
%if (vid1==10000)
%break;
%end
end
for ii = 1:numFrames2
writeVideo(diskLogger2, data2(:,:,:,ii));
%if (vid2==4000)
%break;
%end
end
close(diskLogger1);
close(diskLogger2);
% --- Executes during object creation, after setting all properties.
function mypreview_fcn(hObject, eventdata, handles)
% hObject handle to text1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
tstmpstr = eventdata.Timestamp;
ts = getappdata(handles,'HandleToTimestampLabel');
ts.String = tstmpstr;
%rl = getappdata(handles,'HandleToResolution');
%rl.String = eventdata.Resolution;
%st = getappdata(handles,'HandleToStatus');
%st.String = eventdata.Status;
%handles.CData = eventdata.Data;
My problems that I currently have are, that whenever I press the get_data button, the get_data_Callback executes but throws the following error:
Warning: No video frames were written to this file. The filde may be invalid.
> In VideoWriter.VideoWriter>VideoWriter.close at 307
In VideoWriter.VideoWriter>VideoWriter.delete at 256
In gui_mainfcn at 220
In aufnehmen_speichern at 42
The other thing is that I don't understand how the strings on my buttons change from Resolution to 1292x734 for example. Do I have to use handles? But I did try using handles here:
%setappdata(hImage1,'HandleToTimestampLabel',handles.text1);
%setappdata(hImage1,'HandleToResolution',handles.text2);
%setappdata(hImage1,'HandleToStatus',handles.text3);
At least thats what the example on mathworks.com says.
By the way:
preview(vid1, hImage1);
preview(vid2);
are present, because my buttons won't work correctly as in the normal preview window of preview(vid2).
0 Commenti
Risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!