Preview switching between two videoinputs?

3 views (last 30 days)
Mark Lowder
Mark Lowder on 27 Jun 2016
Commented: Mark Lowder on 12 Jul 2016
Hey Everyone,
I'm trying to make a GUI that can record two videos at the same time to later compare for differences between them. I've been using two axes and preview(VidObj, image, 'Parent', handles.Axes) to assign the previews to the appropriate axes in the GUI. The thing is, whichever one I connect second starts to flicker between the two video feeds instead of only previewing the correct video. What's really weird is that I've done the same thing in a different GUI and had no such issue, and the code for this is copy-pasted from there.
Code:
% --- Executes on button press in startStopLeftCamera.
function startStopLeftCamera_Callback(hObject, eventdata, handles)
% hObject handle to startStopLeftCamera (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.startStopLeftCamera,'String'),'Start Left Camera')
% Camera is off. Change button string and start camera.
set(handles.startStopLeftCamera,'String','Stop Left Camera')
start(handles.LeftVideo)
vidres=handles.LeftVideo.VideoResolution;
hImage2 = image(zeros(vidres(2), vidres(1), handles.LeftVideo.NumberOfBands),'Parent',handles.LeftCamera);
axes(handles.LeftCamera)
preview(handles.LeftVideo, hImage2)
else
% Camera is on. Stop camera and change button string.
set(handles.startStopLeftCamera,'String','Start Left Camera')
stoppreview(handles.LeftVideos)
stop(handles.LeftVideo)
end
% --- Executes on button press in startStopRightCamera.
function startStopRightCamera_Callback(hObject, eventdata, handles)
% hObject handle to startStopRightCamera (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.startStopRightCamera,'String'),'Start Right Camera')
% Camera is off. Change button string and start camera.
set(handles.startStopRightCamera,'String','Stop Right Camera')
start(handles.RightVideo)
vidres=handles.RightVideo.VideoResolution;
hImage = image(zeros(vidres(2), vidres(1),handles.RightVideo.NumberOfBands),'Parent',handles.RightCamera);
axes(handles.RightCamera)
preview(handles.RightVideo, hImage)
else
% Camera is on. Stop camera and change button string.
set(handles.startStopRightCamera,'String','Start Right Camera')
stoppreview(handles.RightVideo)
stop(handles.RightVideo)
end
Any ideas as to how to keep the previews to the correct axes?

Answers (1)

Prasad Mendu
Prasad Mendu on 8 Jul 2016
The following links talk about the similar issue and it might be helpful for you to look at those links. One of the links states that to synchronize multiple devices precisely, you generally need to use devices that support hardware triggering.
  1 Comment
Mark Lowder
Mark Lowder on 12 Jul 2016
Thanks for the answer. I've looked at those pages, but the issue is that at the moment, I'm not even all that concerned about triggering them at the same exact time - merely having them both run at the same time would be nice. After a bit of digging, it looks like the issue is that the frame rate for the previews dies once the second camera is connected, and the same issue extends into recording absent any preview. In the camera's native software, both can record at the same time without a loss to performance. Is there any reason Matlab would do worse? I've considered the possibility that it is a bandwidth issue resulting from too high of a resolution, but I also can't seem to downsample that as the only listed AcceptableFormats for the video source are all 2560*1920.

Sign in to comment.

Categories

Find more on MATLAB Support Package for IP Cameras in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!