GUI with GUI Live RGB-Plot of Video Data

Hello there, I´m creating a customized image processing software with the Image Acquisition Tool. I would like to implement a Live RGB-Plot of Preview-Data. By using the preview function, I pass the preview Data to an axes.handle, which works fine. The I like to pass the data into a customized function (to plot the RGB channels) and pass the plot to another axes-handle (I guess I have to use Event.Data, which is created by the preview function]). But it doesnt work properly. I already tried to use the UpdadepreviewWindowFunction. Does someone have any suggestions?

2 Comments

Adam
Adam on 31 Aug 2018
Edited: Adam on 31 Aug 2018
Well, the problem is precisely what the error states. 'event' does not exist as a variable in that scope. You say it is created by the preview function yet you don't have any output arguments when you call preview so nothing will be passed from it into this Config_Callback function.
What does preview do exactly and what are you expecting 'event' to be such that it has a .Data field?
Hey Adam, thanks for your answer. In the Matlab-Documentation is is written: "When preview invokes the function handle you specify, it passes three arguments to your function: obj, himage and the event-structure (containing the fields Data, Resolution, Status, Timestamp). So you suggestion is to write it like that?: [objt, hObject, Event]=preview(handles.VidObj,handles.hImage)

Sign in to comment.

 Accepted Answer

Linda Kampe
Linda Kampe on 31 Aug 2018
Edited: Linda Kampe on 31 Aug 2018
In Progress...// So the Live-RGB-Histogram seems to be working. But there is still one Problem left. As you can see in the picture, the Histogram is outside of my GUI. I don´t know how to pass the axes handle to the 'setappdata(im_handle1, 'UpdatePreviewWindowFcn',@update_livehistogram_display)'. There must be a way to deliver the axes handle to my updatefunction ('update_livehistogram_display')? Any suggestions? My code is the following:
% if true
% function Config_Callback(hObject, eventdata, handles)
vid = videoinput('winvideo',1);
im_handle1 = image(zeros(1280,720));
setappdata(im_handle1, 'UpdatePreviewWindowFcn',@update_livehistogram_display);
axes(handles.Camera)
preview(vid,im_handle1);
end
function update_livehistogram_display(obj,event,hImage)
set(hImage,'CData',event.Data);
Red = event.Data(:,:,1);
Green = event.Data(:,:,2);
Blue=event.Data(:,:,3);
[yRed, x] = imhist(Red);
[yGreen, x] = imhist(Green);
[yBlue, x] = imhist(Blue);
% figure('name','value')
% axes(handles.RGB)
plot( x, yRed, 'Red', x, yGreen,'Green', x, yBlue,'Blue');
title('RGB-Live_Histogram')
ylabel('Rate')
xlabel('Intensitiy from 0 to 256')
end
% end

3 Comments

You can create an anonymous function to pass further arguments e.g.
setappdata(im_handle1, 'UpdatePreviewWindowFcn',@(obj,event,hImage) update_livehistogram_display( obj,event,hImage, handles.axesHistogram ));
Then add a 4th argument to the function signature for update_livehistogram_display as e.g. hAxes and use this to pass to any plotting instructions. Obviously replace 'handles.axesHistogram' with whatever your actual axes handle is.
Hey Adam, thank you so much-that was exactly the solution I was searching for! Sorry for my delayed answer- now everything works fine :)
Can you help me. I did the code test and it marks me error, could you share part of your code?

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!