Video preview speeds up when moving cursor, laggy otherwise

9 visualizzazioni (ultimi 30 giorni)
I'm writing an AppDesigner GUI that previews video data from FLIR camera in real-time. I've noticed that the preview updates faster when I move the cursor across the computer screen, but slows down/stays still when cursor is not moving (even if the camera itself is moving). Strange.
I want the preview to update automatically without needing to move the cursor. Has anyone else experienced something like this? Thanks.

Risposte (1)

Sanchari
Sanchari il 29 Dic 2023
Modificato: Sanchari il 29 Dic 2023
Hello Katya,
I understand you want to resolve the lag being caused in previewing a video in AppDesigner GUI. The behavior you're experiencing, where the GUI updates more frequently when the mouse is moved, suggests that the MATLAB graphics rendering engine is being prompted to refresh more often due to the events generated by the mouse movement. This is not typical behavior and could be indicative of an issue with how the event loop is being processed or how the rendering updates are being scheduled.
Here are some suggestions to address this issue:
  • Use a Timer Object: If you're not already doing so, consider using a MATLAB timer object to periodically update the video preview. This can help ensure that updates occur at a consistent rate, independent of user input.
  • Ensure ‘drawnow’ is called: Make sure you call drawnow or drawnow limitrate after updating the GUI with the new frame. This will flush the graphics events and update the figure window.
  • Optimize video handling: Check the way you're handling video frames. For instance, if you're using ‘imshow’ to update the frame in each timer callback, consider using the ‘CData’ property of the image object instead, as it's more efficient. Use the code:
set(imageHandle, 'CData', newFrame);
  • Profile your code: Use MATLAB's built-in profiler to identify any bottlenecks in your code that might be causing the GUI to update slowly. This can help you pinpoint inefficient sections of code or functions that take too long to execute.
  • Consider MATLAB version and graphics drivers: Make sure you are using the latest version of MATLAB and that your graphics drivers are up to date. Sometimes, performance issues can be related to incompatibilities or bugs that have been resolved in later versions.
  • Adjust Figure properties: Experiment with different figure and axes properties that can influence rendering performance. For example, setting the 'DoubleBuffer' property of the figure to 'on' can help reduce flicker and improve rendering performance.
Check out the following MathWorks Documentation links:
  1. Use a Timer Object: https://www.mathworks.com/help/matlab/ref/timer.html?searchHighlight=timer%20object&s_tid=srchtitle_support_results_1_timer%20object
  2. Optimize Video handling and understand more about the set function to handle graphics object: https://www.mathworks.com/help/matlab/ref/set.html?searchHighlight=set%20function&s_tid=srchtitle_support_results_1_set%20function
  3. Profiling your code: https://www.mathworks.com/help/matlab/matlab_prog/profiling-for-improving-performance.html?searchHighlight=matlab%20profiler&s_tid=srchtitle_support_results_3_matlab%2520profiler
Hope this information is helpful to you!

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by