Displaying real time data is not efficient. Am I doing something wrong or is it app designer that is slow?
Show older comments
Hi,
I'm building a real time GUI in app designer to display 768 double pixel values from the thermal camera through serial communication at a frame rate of 16Hz. I am using the CData to update the image everytime instead of calling the imagesc in every loop, but this responds well only in 8hz not more than that and sometimes it hangs even at 8hz. Further more in the program I'm also saving the read data in the .csv file (inclusion or deleting of which doesn't cause any difference in the speed of the program) before going to the display part. What is that I'm doing wrong here? Or is there any alternative way which does this more efficiently. Thanks for your time and patience in advance.
Below is the code that I'm making use of.
properties (Access = private)
filename='C:\Users\kmana\Desktop\Matlab\Serial_Read.csv';
fileID ;
pixData=zeros(1,768);%store every pixel data
mPktCnt =0;
imData=zeros(24,32); %matrix to store whole image data
end
function startupFcn(app)
I= imagesc(app.imData,'Parent',app.UIAxes);
colormap(app.UIAxes,jet(256));
% colorbar(app.UIAxes);
delete(instrfindall); %pre-emptively close all ports
s1 = serial('COM8'); %define serial port to read the Arduino
s1.BaudRate=115200; %define baud rate
s1.InputBufferSize=2^21; % increase the buffer size
s1.Terminator = 'CR'; % set the terminator to that on arduino
fopen(s1);
s1.ReadAsyncMode = 'continuous';
app.fileID = fopen(app.filename,'w'); % open csv file to store the data
while(s1.BytesAvailable <= 0) %wait until Arduino outputs data
end
while(1)
sSerialData = fscanf(s1);
temp = strsplit(sSerialData,',');
% reading the pixel data converting it into double and storing it in the pixData array and then in the csv file
for j=1:768
app.pixData(j) = str2double(temp(j));
fprintf(app.fileID, '%2.2f,', app.pixData(j));
end
fprintf(app.fileID, '\n');
% app.mPktCnt= app.mPktCnt+1;
% app.mPktCnt
% converting pixData array into 24X32 matrix which is stored in imData
for k=1:24
for l=1:32
app.imData(k,l)=app.pixData(((k-1)*32)+l);
end
end
% use this imData to update the CData of imagesc.
I.CData(:)= app.imData(:);
pause(0.001);
%drawnow;
end
8 Comments
Walter Roberson
on 25 Nov 2018
It is more efficient to sscanf all of sSerialData at one time than to str2double() one item at a time from it.
Image Analyst
on 25 Nov 2018
Try uncommenting the drawnow so that it updates at each iteration, if that's what you want. Otherwise it might only update whenever it thinks it has enough time to do it.
Kavya Managundi
on 25 Nov 2018
Edited: Kavya Managundi
on 26 Nov 2018
Kavya Managundi
on 25 Nov 2018
Kavya Managundi
on 26 Nov 2018
Steven Lord
on 26 Nov 2018
for k=1:24
for l=1:32
app.imData(k,l)=app.pixData(((k-1)*32)+l);
end
end
Try replacing this with reshape, possibly with a transpose as well.
Have you used the Profiler to determine what part of this code is the bottleneck? Is it displaying the image on the screen or the disk access?
Kavya Managundi
on 26 Nov 2018
Walter Roberson
on 26 Nov 2018
Try
drawnow limit
Answers (0)
Categories
Find more on Develop Apps Using App Designer 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!