Smart Poi

Image Classification for Magic Poi images using Machine Learning

The title says it all. Here are a couple of video’s to demonstrate the process:

Testing the version 5 ML model accuracy:

Testing the image recognition model

Deployed using temporary database:

I added a filter for different categories found by the machine learing model

Todo:

  • New images uploaded are not categorized – because I did the classification at home and just uploaded the database. I still need to get the image recognition to work on the server.
  • Scrolling is really not great, gets stuck sometimes and also new images loaded aren’t filtered.
  • Re-categorizing support – and support for more than one category per image
  • Remove bad images (or just hide them).
  • Refine the model to do better (“text-img” recognition isn’t great, for example).
  • Add more categories.

The categories are live! Check out http://magicpoi.circusscientist.com (and sign up for the good stuff).

Sign up for updates:

UPDATES:

Sign up for our update alerts:

bin files and Magic Poi

I recently received a question via email which I thought might need a bit of answering – “Hello, may I ask how to convert the image into a bin file? I couldn’t find the source code on the website and look forward to your reply. Thank you very much.” Here is my response:

(tl:dr I didn’t share source yet but there are two ways to do it)

Great question! I haven’t been working on the file access much yet for the new MagicPoi. The hardware and getting the binary files is coming second to having an easy way to manage images – which I am spending most of my time on right now.

The Android app had a bug with creating .bin files which I never managed to fix, so I did update the “Smartpoi Android App” page to link to two PC programs which you can download – see the page here: https://www.circusscientist.com/smart-poi-android-app/ – just scroll to the bottom to see the (Linux Only) versions. These are easy-to-use drag-and-drop apps which will convert the image files to .bin format and also upload wirelessly to any connected poi. The .bin files are stored temporarily in a folder in the program files, I am sure you can find them there once you try it. I didn’t share the source because frankly the code is a terrible mess which even I am embarrassed about #messyprogrammer – I am getting better at this by the way, look forward to some documentation coming soon!

Currently the magicpoi website api is limited to returning 10 image names. You can see this by typing this into the browser url bar:
http://magicpoi.circusscientist.com/api/get-filenames

To download one of the .bin files listed, you can use the filename(xxx.jpg.bin), also in the browser bar – eg:
http://magicpoi.circusscientist.com/api/output/ajzs2w1aczeq.jpg.bin

Incidentally the example PlatformIO sketch linked from the “api” section here https://www.circusscientist.com/magic-poi-api/ does exactly this, getting the list of 10 files and then using the /api/output endpoint to download .bin files – to the D1 Mini in this case – and then displaying them in 72px. I would have to check but I think maybe all .bin files are compressed to 72px.. yes I checked – currently that’s the default, with option to support any size (thank goodness).

All files which are uploaded using the magicpoi.circusscientist.com site are automatically converted to .bin files. The .bin files are simply compressed image files – with one byte representing one pixel in R3G3B2 format (in the case of MagicPoi I think I rotate them 90 degrees also for the line by line scanning).

To get any image .bin file from the MagicPoi site at the moment you can use a quick hack – if it is an image you uploaded yourself you have to “share” it for this to work. Then scroll down to where the original image is visible (on the “profile” page) – not the rotated version! Right click and select “Open image in new tab” or just “copy url” – then go to the new tab and copy the image name. Now use the name with “.bin” added on for the download api:
http://magicpoi.circusscientist.com/api/output/ajzs2w1aczeq.jpg.bin

I’m sorry I haven’t really been working on the poi hardware and that side of the project. Like I said, I’m focusing right now on front end usability for the web interface. Soon there will be categories for the images, for example, and sorting.

Once the interface is working I will return to hardware and firmware – and also documentation and new features as well as proper api accessibility.

I hope my response answered your question. Everything is a work in progress, but there is progress.

Regards

Tom

Computer generated Magic Poi patterns with P5.js

Computer generated patterns – let me count the ways.

  • C++ code on-device

    – a simple for-loop using FastLED’s “Palletes”
  • Processing code – on Android, streaming to poi.


    – created using Processing “Mask”, the coloured parts of the image change colour to create an ever-changing image sequence. I also implemented a sound activated version which shows a pattern according to volume on different frequencies (“Beats”) and a static “Cylon” effect (“Zap Game”)
  • Similarly C can be used to stream generated patterns to the poi (see here).
  • I have experimented with AI generators using different prompts – for example:

    – These are from “Midjourney”
  • Finally, my current mission, using P5.js within the magicpoi website to generate pics with code. Examples:

Example:

The above example creates an infinite succession of 72x72px images – perfect for display on my 72px poi. I adapted the code from this showcase example on the P5js website.

My plan is to add this – and many more – options to the magicpoi website. They will complement the user generated images and be downloadable directly to the internet connected Magic Poi.

PS: Currently, if you want to see what any of the images generated above will look like on the poi, you can right click on the changing image, select “open image in new tab”, download the image and then on the magicpoi profile page (you need to be signed in for this to work – sign up, it’s free!) select upload and drag the image onto the page, or choose it from the file menu. Then you can turn this: into this:

As you can see, the possibilities are endless. I plan on making the P5.js image generation into a plug-in system for Magic Poi.

Solving a simple problem with ML

ChatGPT has been helping me out

A fair amount if I am going to be honest here. The problem for me always comes down to syntax. Currently focused on Full Stack IOT development my day consists of switching between coding in Python (Flask api and web back-end), JavaScript (with JQuery for front-end) and C++ (embedded).

I find that one of the more interesting parts of any Full Stack IOT code base comes down to dealing with requests and responses. A website has a login page, sends a request to the server. An IOT device has a key to access the online api, sends a request to the server. The server needs to respond but first check the input is valid (sanitize it).

Python/JavaScript/C++ all have their own ways of working with text input. In JavaScript for example you need to trim() but in Python it’s strip() – and in C++ (embedded) it’s a bit more complicated operation involving char arrays. The point is that when switching around between languages I sometimes find myself going blank on the specifics of each approach. That’s when ChatGPT comes in handy for me – as a helper, faster than a google search.

I recently came across an issue which was helped by ML in a different way – namely parsing unstructured text input.

The Problem

I had a series of spreadsheets which I was extracting data from (using Pandas) but the date format was unfortunately unstructured. For example:

12th, 13th Dec 2022 and 5th-8th Jan 2023

In order to continue with the project I needed the date in Pandas date format

2022-12-12

If you give it “12th December 2022” as an input, Pandas can do this for you, but it couldn’t cope with the format in the spreadsheets. Regular expressions weren’t going to do the job either, considering the range of formats. So I asked ChatGPT. The prompt:

Please can you parse the following dates as separate dates in list format, suitable for python pandas usage:
12th, 13th Dec 2022 and 5th-8th Jan 2023

The reply:

['2022-12-12', '2022-12-13', '2023-01-05', '2023-01-06', '2023-01-07', '2023-01-08']

As you can see, this is exactly what I was looking for! Unfortunately my ChatGPT free trial has ended – not that I am opposed to paying for software but that’s not the only issue stopping me from using the api for this. I have been burned in the past by proprietary software solutions which have arbitrarily changed and/or cancelled a product which I relied on. This is a simple use case but I can imagine myself taking advantage of it more and more, then OpenAI pulling the rug (or just raising prices) and leaving me with a whole bunch of useless code.

The Solution:

After looking around I found NLPCloud (no affiliation, just it looks cool and works for me*). They use Open Source Generative AI models which in theory I could replicate and host anywhere. I decided to give it a try.

It works! The free plan api key is now plugged into my program and when my program encounters a date format it can’t deal with, a query is sent.

response = client.chatbot(f"Please can you parse the following dates as separate dates in list format, suitable for python pandas usage: {dates_unformatted}", "Human asking AI for help with a text summarization task. ", [])  #text, context, history

The response is exactly the same quality as the ChatGPT one, using the “finetuned-gpt-neox-20b” model.

What simple things has ML been helping you out with?

*Update: A couple of months later, tried out NLPCloud again and it’s broken. Luckily the same code works fine using hugging-chat-api. I really need to get onto self-hosting, every api breaks sooner or later it seems.

Upgrading the Magic Poi site

Currently the Magic Poi site relies on some Processing (Java) code which is called from python – as well as other bash scripts to do certain things. I wanted to make it faster and cleaner by using Python for everything, so I did some test scripts. (Github). Also, the Processing code required a virtual screen buffer to run on the server constantly!

The main functionality involves compressing images into the .bin files which are saved to the poi memory for display. Since there is limited memory, and to save bandwidth, I am using the R3G3B2 algorithm to compress images. The poi only accepts images which are rotated 90 degrees clockwise, so that needs to happen too, as well as dynamically re-sizing any images which are wider than the 72px available.

I am still conflicted about whether to keep the Android app as the control for the poi, or to do something else, but making everything available as an api on the server keeps it flexible for now. The RotateImageVisualPoiStyle api can be accessed right now. Upload your image, and see what it will look like on the poi!

# change the /path/to/image.jpg to your own image file name
curl --location --request POST 'http://magicpoi.circusscientist.com/api/rotate_visual_poi_style' --form 'file=@"/path/to/image.jpg"' --form 'fixed_width="72"' --output 'rotated_image.jpg'

MagicPoi – slow progress

Announcement:

The factory where MagicPoi were being developed had a fire last month! All of the prototype poi melted, so all I have left is my breadboard version. This is going to cause some delays..

Updates:

  • The Magic Poi website now saves .bin files for every image uploaded. This is accessible via an api which I am working on accessing from the ESP32 and ESP8266. The .bin files are byte compressed images for display on the poi.

    Example – list all shared .bin files on the server:
    curl http://magicpoi.circusscientist.com/api/get-filenames

    One thing to note is that for testing purposes, all new .bin files are shared now. Please be aware that your images could be accessed (temporarily). This is because authentication is an extra step, so I’m working on the basic functionality first, with a public folder. The authentication works using jwt and I am having to access it from Java and C++. I already have a working Arduino test code which implements jwt correctly – security is important, so I want to do it right. One problem I already had to overcome is the fact that LittleFS file system has a limit of 31 characters for filenames (including path). The randomly generated filenames on the server are longer than this.
  • Not sure if I mentioned this before, the SmartPoi “Upload for offline use” option in the Android app doesn’t upload the whole image at the moment. I am not sure why, perhaps it’s something to do with the timing loop moving to the next image too fast.
    This option is going to be replaced by the web api anyway, so it’s not a priority, but I have compiled a desktop app which I use for converting and uploading (Linux only). You can get that for 36px here or 72px here – it can upload 20 images, just drag and drop your pics (need to be 90 degrees rotated, unlike the website) onto the window, connect to Poi AP and press “Upload”. You need to extract it and run from the command line but it should work on any Linux distro (tested on Ubuntu and Arch).
    At some point I will probably get annoyed at having to use my Laptop to upload images and fix the app though. Do email me if you need this for Windows, I might be persuaded to compile it for you using a VM if you ask nicely.
  • With the new APA102 2020 version being more available now, when Magic Poi is eventually launched it will have at least 100px, I’m thinking 128 is a good number but don’t quote me.
  • You may have noticed all of the hype around AI lately. A few years ago I used GAN with PyTorch to generate images for the poi (after training with around 100 poi pics, probably not enough). It was a big fail, but maybe it’s time to take another look. Would it be cool if you could just tell your poi what type of image you want to display, and it did it instantly?
    I do already have loads of Processing sketches I made to try and computer generate nice pics (some are on the Android App).

Feedback is always welcome.

Ubuntu Snap update SPOILED the World Cup

Goodbye Ubuntu, Goodbye Snaps

I missed two goals in the World Cup Finals because of this. It’s not the first time Snap has been a problem, but it’s most definitely the last straw.

What happened?

I was happily watching the second half of the Fifa World Cup Final, using “ShowMax” – a South African paid streaming platform, on Firefox. All of a sudden the screen freezes and the Firefox Snap decides to update. I couldn’t even close the window to open up Chromium.

In a panic I force shut down the laptop but somehow the boot-up wasn’t recognizing my hard drive anymore?? I don’t know what happened there, it works now, maybe I pressed the power button too many times – I was IN A HURRY.

I ended up watching the rest of the game on my phone.

Go Argentina! If my team hadn’t won I would have probably been even more pissed.

It’s the last straw Ubuntu – I have heard that Snaps have added an “Experimental” option to ignore updates but that’s not good enough. I’m moving to something that gives me full control. You can say what you like about me – It’s my fault for using the “Schedule updates for Sunday night” option and forgetting about it, or not using the new “Ignore updates” feature I only found out about on Reddit last week, but I’m done.

From now on, I love Arch

I am going back to Arch. My computer is my computer, and I don’t care anymore how much work it takes, I’m going to take charge so nothing like this ever happens again.

Look forward to a follow-up article where I rant about annoying Arch flaws and insane breaking changes in updates. \s


Update: Wow I actually made the front page of hacker news! Lots of discussion on the topic here: https://news.ycombinator.com/item?id=34041272

Upgrading K8 Prophecy club with new battery and firmware

My K8 Prophecy clubs have reached the end of their tether. After 8 years of use! First of all, many thanks to K8Malabares for their excellent equipment. Most smartphones won’t last that long (except for my Samsung Galaxy S2, which still works). If you need juggling equipment you can’t go wrong with K8. I have some of their non-LED equipment as well and it’s just as good.

Upgrade

About six years ago I did an experiment – to see if I could emulate the K8 IR code on an Attiny85 chip. I knew they used that chip, or possibly the Attiny45, because one of my clubs was faulty and I opened it up to have a look – K8 sent a replacement, by the way, talk about great customer service!

Now that my balls and clubs are not working anymore, due to the battery reaching end of life, it’s the perfect time to test out my new code. Luckily K8 didn’t solder their chips, instead opting for a convenient chip socket for easy replacement! I made some updates to the code, adding new functionality and colours. (K8 have also done an update since I bought my equipment) The most important, for me, was adding a timeline record and playback. This means that I can record the timed colour changes for my entire show into the chip via IR remote, and play it back (in time with the music) by pressing a single button. This is similar to how Aerotech Ultimates used to work.

You can check out the code for Attiny85 here.

Batteries

The batteries were the main thing. K8 use lithium batteries with 250mah power. I found some batteries online with a capacity of 600mah which I thought I could make fit (see below for details – not quite, but I made it work). I also bought a cool new charger for the new batteries.

The procedure

For anyone who wants to try and do this, I am posting some tips and photo’s.

1. Taking apart the club

Pull off the tape from the center, then pull out the staples:

Take off the knob and top bumper:

Pull off the plastic around the handle, then unscrew the plastic spacer (needs an allen key)

The next part is really sensitive – make holes in the top of the bulb cover to let the inside pipe come out. Get it out by pushing from the bottom – I also shoved a dowel inside and pushed upwards. If you use too much force this plastic pipe could bend, so be careful.

Now pull out some more screws holding the thicker top piece of the inside pipe on, and pull the spacer out to let the electronics out.

The bottom thin pipe should come off easily, leaving the bare circuit board.

Now cut off the insulating cover, exposing the battery. See how fat it is!

Pull the battery away from the board (carefully) and cut the two wires as close as possible to the battery – we need those!

The new battery ready for placement. Also, my newly programmed chip in place (old one from K8 labelled C2.

Now comes the hard part. Making space for the new battery. I had to cut into the larger diameter tube on both sides so that this could fit. I actually bought a Dremel to do this job.

Now put the circuit back into the top pipe, and find the battery wires. Then solder the battery on – finishing with insulation. The battery should fit with only a little bit sticking out on both sides of the pipe.

I used clear tape to stick the battery in – it was already pretty snug as the holes were just right.

Putting it back together

Just like taking it apart, only in reverse (and much easier)

Put the longer circuit cover tube back in and line up the holes (with the spacer), then put the screws back in. This works fine with just pliers, just twist left and right for these, while pushing in firmly:

Now the inside tube goes back into the top of the bulb – it just snaps in easily (how hard was that to take out, though, whoah!)

After putting the top bumper back, the middle spacer goes on. I forgot to mention, that doesn’t come off without removing a plastic screw cover (yellow, bottom of thin tube) so keep that in mind if you haven’t taken this apart yet.

Finally it’s time for the wrapped plastic handle – I didn’t put the staples back, you are welcome to try and do that..

Add some tape to keep everything together, screw on the knob and your club is “as-new” again.

Just a quick tip, I noticed that there is a bit of wear where the circuit goes from thin to thick (you will see what I mean – the long bit with all of the LED’s. Some of my clubs had non-working colours due to this, and I had to bridge the gaps with wires.

Let me know if you have K8 clubs and are interested in upgrading yours, I am happy to answer any questions.