A while back, I wrote a blogpost about using computer vision techniques to play an automated game of pong. This was accomplished by scanning the screen for a white pixel and moving the mouse to this position.
In that particular blogpost, I didn’t really go deep into the optimization that can be done when using Java for computer vision. So this time, I’d like to try some techniques and benchmark them to find out how to shorten the execution time.
The benchmark is prepared as follows:
- An image is loaded from disk
- The benchmark timer starts
- The image is converted to grayscale one hundred times
- The benchmark timer stops
- The image is written back to disk to manually verify the results
For each benchmark, a couple of variables are prepared:
- imageO containing the original image as a BufferedImage object
- imageN containing a blank target image as a BufferedImage object
Lets try some techniques, starting with a worst-case scenario: