in colours, games, machine learning, python, tutorial

Game Barcode: A Study of Colours in Games

Share Button

This tutorial shows how to download videos from YouTube and to process their frames with Python; I have used this technique to create game barcode, an image created by sorting the colours in each frame of a particular video. You can see some of most intriguing here:

This tutorial is divided in four parts:

Introduction

The idea for this tutorial came to me after reading a post on Reddit titled The average color of every frame of a given movie. I immediately wanted to apply this technique to games. The main reason is that games, compared to movie, have much smoother transitions. This allows to see how colours change very clearly. On top of that, I wanted to explore this concept further, by applying the techniques I’ve discussed in The Incredibly Challenging Task of Sorting Colours. I tested my hypothesis on a short clip from a game I am working on, and the result was quite stunning.

colours_StillTime_600

Another important reason why I wanted to use games rather than movies, is that working with the latter brings you dangerously close to the neutral zone of piracy and copyright infringement. Switching to games, however, you are forced to used a particular Let’s Play video. All the game barcodes in this post have been generated from Let’s Plays I have found on YouTube. I have no affiliation with their respective creators. You can see all the game barcodes here.

GameBarcode: A Study of Colours in Games

Step 1. Processing a video

Let’s start with a top-down approach. Each movie is processed by the process_video function. Frames are extracted using the library OpenCV, then passed through process_frame which returns the list of sorted colours within that frame.

Finally, all the sorted colours are given to generate_pic which joints them together to create the final picture.

Step 2. Processing a frame

Processing a frame is relatively straightforward. First, the frame is reduced in size to save time and memory. Then, is it reshaped into an array and sorted. For this process I have chosen to sort the colours in the HSV space, since it is more consistent across different frames. In the last step, the sorted array is converted back into an image and interpolated to the requested size using cv2.resize.

The function to resize the original frame is this one:

Step 3. Creating the barcode

The final step to create the image is to join all the sorted columns together. We also convert the image back to RGB.

If you want to resize the image to a more manageable size, you can use this code:

Step 4. Downloading from YouTube

Since many Let’s Play are on YouTube, it makes sense to invest some time to download them directly. I have used pafy, a Python library which allows to query YouTube.

If you work is derivative (i.e.: if you are using someone else video), don’t forget to credit them.

Conclusion

If you are curious to see this technique applied to movies, there is a nice selection here.

View post on imgur.com

Other resources

Support this blog! ♥

In the past two years I've been dedicating more and more of my time to the creation of quality tutorials, mainly about game development and machine learning. If you think these posts have either helped or inspired you, please consider supporting this blog.

PatreonBecome a Patron Oo4th_patreon_name
PaypalDonate on PayPal
Twitter_logoFollow on Twitter

Don't miss the next tutorial!

There's a new post every Wednesday: leave your email to be notified!


Write a Comment

Comment

Webmentions

  • Something for the weekend #010 | OZARIN

    […] Zucconi shares his colour study techniques in Game Barcode: A Study of Colours in Games. Using Python, Zucconi shows how to output a colour script from a play through video. This is a […]

  • You’re looking at a video game stripped down to its colors, frame-by-frame | RocksGame

    […] all colors into each slice. It sounds complicated, but it's really not. In fact, Zucconi has a tutorial on his website so you can create your own […]