anchor.diff:  
   == Motivation
   
  -For our booth at ICRA 2014 we put together a demo system in MATLAB that used stereo vision for tracking bean bags, and a robot arm to pick them up. We used two IP cameras that sent video via link:https://de.wikipedia.org/wiki/H.264[H.264] over link:https://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol[RTSP]. While developing the image processing and robot control parts were comparatively simple, it proved to be a challenge to get streaming video data from both cameras into MATLAB fast enough to be useful.
  -
  -* link:http://www.mathworks.com/hardware-support/ip-camera.html[IP Camera Support] didn't exist at the time and only supported MJPEG over HTTP
  +For our booth at ICRA 2014 we put together a demo system in MATLAB that used stereo vision for tracking bean bags, and a robot arm to pick them up. We used two IP cameras that streamed link:https://de.wikipedia.org/wiki/H.264[H.264] video over link:https://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol[RTSP]. While developing the image processing and robot control parts were comparatively simple, it proved to be a challenge to get streaming video data from both cameras into MATLAB fast enough to be useful.
  +
  +* link:http://www.mathworks.com/hardware-support/ip-camera.html[IP Camera Support] didn't exist at the time and only supported link:https://en.wikipedia.org/wiki/Motion_JPEG[MJPEG] over link:https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol[HTTP]
   * link:http://www.mathworks.com/hardware-support/matlab-webcam.html[USB Webcam Support] only supported USB cameras
  -* link:http://www.mathworks.com/help/matlab/ref/imread.html[imread] and link:http://www.mathworks.com/help/matlab/ref/webread.html[webread] were limited to HTTP and too slow for real-time.
  +* link:http://www.mathworks.com/help/matlab/ref/imread.html[imread] and link:http://www.mathworks.com/help/matlab/ref/webread.html[webread] were limited to HTTP and too slow for real-time
   
   Since we didn't want to port the code to another language, we instead wrote a small library that enabled us to acquire video data in an efficient manner. The project was later open sourced as link:http://www.github.com/HebiRobotics/HebiCam[HebiCam].
   
  
positive.code: .Conversion overhead on the MATLAB thread in [ms]
  image::{imagesdir}/streaming/table_performance.svg[width=100%]
  
  The results show that the default conversion as well as jpeg compression are essentially non-starters for color images. The default approach works much better for grayscale due the conversion from a 2D array (`byte[height][width]`) being significantly cheaper, but it still is not a great option.
  
  Copying the raw pixels from a Java image is significantly faster, but there is still too much overhead caused by the need to change the memory layout.
  
  The by far best option is to convert the layout outside of MATLAB and if possible bypass the Java translation layer entirely by using shared memory. This approach scales very well and can even transfer 4K images in real-time.
  
  [Note]
  Note that we typically use lower resolution images (e.g. 480p) to speed up the processing. We only use higher resolution images (e.g. 1080p) when we use MATLAB as a live video display.
  
  == Final Notes
  
negative.code: [h,w,c] = size(this.matlabImage);  % get dim info
  vector = typecast(data, 'uint8');
  
  % (2) Interpret pre-laid out memory as matrix
  image = reshape(vector,h,w,c);
  ----
  
  