anchor.diff:  
   == Final Notes
   
  -After creating link:https://github.com/HebiRobotics/HebiCam[HebiCam] we were able to develop and run the entire stereo vision + controls demo entirely in MATLAB. However, we still decided to never develop a custom stereo vision setup solely for an exhibit demo again. The colors and lines on the carpet caused the camera calibration to fail repeatedly and we ended up spending more time on getting the cameras calibrated than we spent on the entire initial development of HebiCam.
  -
  +After creating link:https://github.com/HebiRobotics/HebiCam[HebiCam] we were able to develop and reliably run the whole demo entirely in MATLAB. However, during the setup at the conference site we ran into the issue that the colors and lines on the carpet caused the camera calibration to fail repeatedly, and we ended up spending more time on getting the cameras calibrated than we spent on the entire initial development of HebiCam. We've since shied away from developing custom stereo vision setups solely for exhibit demos.
  +
  +For us, the biggest lesson learned was that shared memory can be used to efficiently transfer large amounts of data into MATLAB. We also found that shared memory can serve as a convenient way to exchange data between multiple MATLAB instances. For example, one instance could track a target at a lower rate, while another instance could use its output for robot control at a higher rate.
  +
  +////
   The biggest takeaway for us was that MATLAB supports shared memory. We had used shared memory before for inter-process communication in Java and C++, but we somehow assumed that MATLAB wouldn't support it. We eventually looked into this and found that MATLAB does have support, and that the implementation is actually quite nice. The data definition can even map the memory to an array of structs with multiple variables.
   
   Using shared memory allows us to transfer data very efficiently and to include meta data such as timestamps or frame sequence numbers. However, for us the most interesting application is still its use for inter process communication. For example, we can have two MATLAB instances exchange almost arbitrary aounts of data by simply defining a common shared struct.
  
positive.code: image = reshape(vector,h,w,c);
  ----
  
  *5. MATLAB Layout as Shared Memory*
  
  This approach is the same as 4. with the difference that the Java translation layer is bypassed entirely by using shared memory via link:https://mathworks.com/help/matlab/ref/memmapfile.html[memmapfile]. Shared memory is typically used for inter-process communication, but it can also be used within a single process. Running within the same process also simplifies synchronization since MATLAB can access Java locks.
  
negative.code: 
  == Technical Background
  
  Most video streams that are sent over the network get compressed in order to save bandwidth (exceptions include GigE cameras). While the cameras often include specialized hardware (link:https://en.wikipedia.org/wiki/Application-specific_integrated_circuit[ASIC]) to do the encoding, the decoding on the computer side tends to happen in Software. Since this can take a significant amount of time, it is common practice to move the acquisition to a separate thread in order to reduce the load on the main processing thread.
  
  [NOTE]
  Note that Intel has added hardware support for encoding and decoding H.264 to their CPUs starting in 2011 (link:https://en.wikipedia.org/wiki/Intel_Quick_Sync_Video[QuickSync]), but there is unfortunately a lack of library support.
  
  Due to MATLAB's single threaded nature, we needed to resort to external languages for getting background threads. Out of the box MATLAB provided two interfaces to other languages:  https://www.mathworks.com/help/matlab/matlab_external/introducing-mex-files.html[MEX] for calling C/C++ code, and the https://www.mathworks.com/help/matlab/matlab_external/product-overview.html[Java Interface] for calling Java code. For a variety of reasons, such as simplified development and cross-platform deployment, we decided to use the Java interface. The diagram below shows a simplified overview of the resulting system.
  
  [.text-center]
  .System overview for a stereo vision setup
  