If you need this to be fast, you’ll want to avoid BufferedImage as much as possible. If all that you need from the Robot class is taking screenshots, that can be achieved a lot more efficiently with FFmpeg and JavaCV. There is some sample code for that here, among other places:
  

      github.com/bytedeco/javacv
  

  
    
  
	  
  

  
    
      ScreenCapture on Windows using new FFmpegFrameGrabber("screen-capture-recorder");
    

    
      
        opened 
        
          
        
        Aug 24, 2014
      
      


      
        
          
          Nackloose
        
      
    

    
        
          enhancement
        
        
          help wanted
        
    
  


  
    Apparently ffmpeg supports screen capture on Windows according to this:
https://…trac.ffmpeg.org/wiki/Capture/Desktop

Attempting to do so using:

```
        FrameGrabber grabber = new FFmpegFrameGrabber("screen-capture-recorder");// As well as FFmpegFrameGrabber("UScreenCapture");
        grabber.setFormat("dshow");
        grabber.setFrameRate(30);
        grabber.start();
```

Results in:

```
run:
Exception in thread "main" org.bytedeco.javacv.FrameGrabber$Exception: avformat_open_input() error -5: Could not open input "screen-capture-recorder". (Has setFormat() been called?)
    at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:368)
    at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:318)
    at testarea.JavaCVDemo.main(JavaCVDemo.java:40)
[dshow @ 154dc160] Malformed dshow input string.
[dshow @ 154dc160] Malformed dshow input string.
Java Result: 1
BUILD SUCCESSFUL (total time: 9 seconds)
```

This may possibly have something to do with(maybe???): https://trac.ffmpeg.org/wiki/DirectShow#Specifyinginputframerate

This is here as a resource in case other people experience this error and wish to look into it, as well as a reminder to myself to do so in the future.
If you find any solutions or fixes, please let me know.
  

  

  
    
    
  

  


FFmpegFrameGrabber.grab() returns Frame objects, but what you want from them is Frame.image[0], which is typically just a ByteBuffer in BGR24 format from which we can easily create a Tensor.
And while you’re at it, you may want to try TF Lite since it is probably going to give you lower latency than TF Core:
  
      

      github.com
  

  
    javacpp-presets/tensorflow-lite at master · bytedeco/javacpp-presets 1

  master/tensorflow-lite

  The missing Java distribution of native C++ libraries