GUI with Video Mosaicking
Show older comments
I am currently working on a Video Mosaicking project that will in cooperate up to 10 cameras together for a end user to see around their vehicle. Currently I am designing a GUI with an older version of the code we plan to use. However I keep running into a few problems.
As part of my GUI I would like to be able to pause the program mid process and then resume right where I left off. However when I program the *pause * command into a button and try to use it. The program either acts as if it is not responding and then doesn't work or takes a good while to pause the program.
Then when I choose to resume the program with the GUI with a pause off command the program doesn't resume crashes.
The current configuration I am using only has 2 web cameras over USB, MATLAB 2012, MatLab Image Acquisition Toolbox, and the code below.
The computer hardware that I am running these commands/program off of is a HP laptop with i5-2520M CPU @ 2.50GHz 2.50GHz and 6 GB of RAM.
If you need the figure file feel free to email me.
function varargout = GUI_interface(varargin)
% GUI_INTERFACE MATLAB code for GUI_interface.fig
% GUI_INTERFACE, by itself, creates a new GUI_INTERFACE or raises the existing
% singleton*.
%
% H = GUI_INTERFACE returns the handle to a new GUI_INTERFACE or the handle to
% the existing singleton*.
%
% GUI_INTERFACE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_INTERFACE.M with the given input arguments.
%
% GUI_INTERFACE('Property','Value',...) creates a new GUI_INTERFACE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUI_interface_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUI_interface_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 GUI_interface
% Last Modified by GUIDE v2.5 12-Feb-2013 11:49:17
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_interface_OpeningFcn, ...
'gui_OutputFcn', @GUI_interface_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 GUI_interface is made visible.
function GUI_interface_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 GUI_interface (see VARARGIN)
% Choose default command line output for GUI_interface
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI_interface wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = GUI_interface_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 ACTIVATE button.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% test
pause off
Canvas = single(zeros(800,700,3));%set resolution
resolution = 'MJPG_640x480';%set resolution
rgb2i = vision.ColorSpaceConverter('Conversion', 'RGB to intensity');
C1Vid = imaq.VideoDevice('winvideo',1, resolution);%C1
C2Vid = imaq.VideoDevice('winvideo',2, resolution);%C2
hVideo1 = vision.VideoPlayer;
hVideo1.Name = 'Camera 1 (Left)';
hVideo1.Position = [0,500,640,480];
hVideo2 = vision.VideoPlayer;
hVideo2.Name = 'Camera 2 (Right)';
hVideo2.Position = [640,500,640,480];
hVideo3 = vision.VideoPlayer;
hvideo3.Name = 'Output1';
hVideo3.Position = [0,50,640,480];
hVideo4 = vision.VideoPlayer;
hvideo4.Name = 'Output2';
hVideo4.Position = [640,50,640,480];
hdrawmarkers = vision.MarkerInserter('Shape', 'Circle', ...
'BorderColor', 'Custom', 'CustomBorderColor', [1 0 0]);
C8geotrans = vision.GeometricTransformer(...
'OutputImagePositionSource', 'Property',...
'OutputImagePosition', [1 1 1280 720]);
%C8geotrans = vision.GeometricTransformer(...
% 'OutputImagePositionSource', 'Property');
% Create a geometric Transformer Estimator object
gte = vision.GeometricTransformEstimator;
gte.Transform = 'Affine'; %was Nonreflective similarity
gte.RefineTransformMatrix = true;
C8AlphaBlend = vision.AlphaBlender;
C7AlphaBlend = vision.AlphaBlender;
AlphaBlend = vision.AlphaBlender;
nFrames = 0;
while (nFrames < 30)
C8frame = step(C1Vid);
C7frame = step(C2Vid);
C8frameGrayScale=step(rgb2i,C8frame);
C7frameGrayScale=step(rgb2i,C7frame);
ptsC8frame = detectSURFFeatures(C8frameGrayScale, 'MetricThreshold',100);
ptsC7frame = detectSURFFeatures(C7frameGrayScale, 'MetricThreshold',100);
[C8features, validC8Pts] = extractFeatures(C8frameGrayScale, ptsC8frame);
[C7features, validC7Pts] = extractFeatures(C7frameGrayScale, ptsC7frame);
C82C7index_pairs = matchFeatures(C8features, C7features,'MatchThreshold',100, ...
'MaxRatio', 0.6);
C8matchedToC7 = validC8Pts(C82C7index_pairs(:,1));
C7matchedToC8 = validC7Pts(C82C7index_pairs(:,2));
strongestC8 = C8matchedToC7.selectStrongest(50);
strongestC7 = C7matchedToC8.selectStrongest(50);
matC8coords = strongestC8.Location;
matC7coords = strongestC7.Location;
% Display the current image and the corner points
DetectedImage1 = step(hdrawmarkers, C8frame, matC8coords);
DetectedImage2 = step(hdrawmarkers, C7frame, matC7coords);
% step(hVideo1, C8frame); %CanvasAndC8
% step(hVideo2, C7frame); %CanvasAndC7
% step(hVideo3, DetectedImage1);
% step(hVideo4, DetectedImage2);
nFrames=nFrames+1;
end
[C8tform, C8inlierIdx] = step(gte, C8matchedToC7.Location, C7matchedToC8.Location);
C8transformed = step(C8geotrans,C8frame,C8tform);
%figure(1)
%imshow(C8transformed)
CanvasAndC7 = step(C7AlphaBlend,Canvas,C7frame);
CanvasAndC8 = step(C8AlphaBlend,Canvas,C8transformed);
Blend1 = step(AlphaBlend,CanvasAndC8,CanvasAndC7);
Blend2 = step(AlphaBlend,CanvasAndC7,CanvasAndC8);
FullBlend = step(AlphaBlend,Blend1,Blend2);
figure()
image(FullBlend);
release(C1Vid);
release(C2Vid);
% --- Executes on button press in PAUSE button.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pause on
pause
% --- Executes on button press in Resume.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pause off
% --- Executes on button press in SYSTEM REST button.
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)
imaqreset
imaqfind
clear all
clc
% --- Executes on button press in CLOSE PROGRAM button.
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)
quit
quit force
% --- Executes on selection change in Individual Camera Selection.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
imaqreset
hVideo1 = vision.VideoPlayer;
hVideo1.Name = 'Camera 1 (Left)';
hVideo1.Position = [0,500,640,480];
hVideo2 = vision.VideoPlayer;
hVideo2.Name = 'Camera 1 (Left)';
hVideo2.Position = [0,600,640,480];
resolution = 'MJPG_640x480';%set resolution
rgb2i = vision.ColorSpaceConverter('Conversion', 'RGB to intensity');
C1Vid = imaq.VideoDevice('winvideo',1, resolution);%C1
C2Vid = imaq.VideoDevice('winvideo',2, resolution);%C2
nFrame=0;
nFrame2=0;
contents = cellstr(get(hObject,'String'));
A=contents{get(hObject,'Value')};
if strcmp(A,'~Select Individual Camera Feed~')==1
elseif strcmp(A,'Camera 1')==1 ;
while (nFrame<200)
C8frame = step(C1Vid);
step(hVideo1, C8frame); %CanvasAndC8v
nFrame=nFrame+1;
end
else strcmp(A,'Camera 2')==1;
while (nFrame2<200)
C7frame = step(C2Vid);
step(hVideo2, C7frame); %CanvasAndC7
nFrame2=nFrame2+1;
end
end
release(C1Vid)
release(C2Vid)
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Mosaick View.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of togglebutton1
% --- Executes on key press with focus on listbox1 and none of its controls.
function listbox1_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
Answers (0)
Categories
Find more on National Instruments Frame Grabbers in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!