show image in axes in serial callback function
Show older comments
i need your help
I'm trying to display an image in GUI but a problems is that I can not display image in axes in the function I added:
function Serial_Callback(obj,event,handles) , when i call : axes(handles.axes1) imshow('image.jpg') then it do not display in axes but display in new window figure1. If i call axes(handles.axes1); imshow('image1.jpg') in any button function, it correctly display in that axes. Why?
this is my code:
s = serial('COM1','Baudrate',9600,'DataBits',8,'Parity','none','StopBits',1);
s.ReadAsyncMode = 'continuous'; %read direction
s.InputBufferSize=2;
s.OutputBufferSize=1;
s.Terminator = 'CR';
s.BytesAvailableFcnCount = 1;
s.Timeout = 1;
s.BytesAvailableFcnMode = 'byte';
s.BytesAvailableFcn = @Serial_Callback;
try
fopen(s);
catch err;
if (strcmp(err.identifier,'MATLAB:serial:fopen:opfailed'))
msgbox('Open COMport fail!!! Please try again!','Error','error');
end
end
function Serial_Callback(hObject,eventdata,handles)
global video hinh I J K a P S s;
video = videoinput('winvideo',2);
hinh = getsnapshot(video);
imwrite(hinh,'anh.jpg');
a = imread('anh.jpg');
axes(handles.axes1);
imshow(a);
J = rgb2gray(a);
J = imadjust(J);
K = im2bw(J,0.7);
K = imfill(K,'hole');
K = bwareaopen(K,2500);
axes(handles.axes2);
imshow(K);
Accepted Answer
More Answers (0)
Categories
Find more on Image Arithmetic 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!