MLNI – Body Flow (Billy Zou)

Body Flow

This week I developed a generative animation program utilizing BodyPix in ml5.js and p5.js.

Basically it reads data from BodyPix and stored points contained by the body. To improve performance, I chose grids of 20 pixels. It will draw white circles in areas covered by the body detected. If a circle area was covered by body in the previous frame but not the current frame, a falling circle of random color will be generated. In short, if you move fast in front of the camera, abundant colorful circles will appear on the screen. Also if the area covered by body is large enough, the canvas will be magnified.

Store BodyFix data

I created some classes to store the results. Instead of using a global variable to constantly track results from the model, I directly store the data into an instance of my class.

Here class BodyMap is a singleton, quite similar to the global variable in the class example. It can draw white circles representing the body, and at the same time keep track of changes of the body.  Every time it finishing updating the data, it will compute the ratio between body covered area and the uncovered area. If the index is large, a CSS transform: scale(n); attribute will be added.

Difference between sequential frames

A grid has a boolean attribute active . If the attribute is previously true and currently false, a colorful particle is generated. It will also draw a white circle to represent areas covered by body.

An array of particles is stored in a grid object. The way to clean particles is also very simple. Just check whether a particle’s y-position is larger than the canvas height.

Colorful particles

This is a very simple class. I used a constant number to simulate the gravity.

In practice, since I did not directly modify pixels of image, the rendering process is a little slow. That is the reason why I chose 20 as grid size.

Conclusion 

BodyPix is a very powerful tool. I found apart from drawing the whole body, it can also recognize different parts of the body. I think this is a useful feature to develop something interesting. I will learn more about it and maybe utilize it in my midterm project.

MLNI – Cut The Ball (Billy Zou)

Cut The Ball

In this assignment, I combined ml5.js with p5.js and developed a simple interactive game, with the help of PoseNet.

Basically, the player should cut the circle with his/her nose. Position of player’s nose is tracked all the time. When player’s nose penetrate a circle, the circle will be destroyed.

Nose Detection

Nose is detected using PoseNet.

Among all body parts, I picked the nose and saved its position in an object. This object would also be used by circle objects to detect penetration.

Penetration

Penetration is divided into to parts. The first part is nose coming from outside the circle and the other part is nose leaving the circle. If both conditions are satisfied, a penetration is detected. Then, the ball will be destroyed and the system will record this action as a successful cut.

Limit Objects

There are two parts in this program that require object limit. First is cleaning the circle cut or expired. Since there will be at most 1 big circle on the screen and a new circle will be generated every 5 seconds. What I did was not displaying the circle when it was not available and when a new object was assigned to the variable, the old one would be cleaned automatically.

When a circle is cut, there will be an explosion effect. In fact it is hundreds of small circles. All circles will be removed after 1 second. Of course they are stored in an array first, and finally the array will be emptied.

I find that what PoseNet does is quite similar to Kinect SDK. I am looking forward to utilizing more interesting machine learning modals.

MLNI – Fireworks (Billy Zou)

FireWorks

This week I developed a simulation of colorful fireworks using p5, in an object-oriented way.

fireworks

Classes 

I used two classes to implement this effect, Spark and SparkManager .

The previous one is the particle itself and the latter one is the manager of particles.

Spark

In fact, they are circles filling with different colors.

The particle has properties position, velocity, size and color. The color is totally random. In order to produce the effect of explosion, sparks close to the center are larger than sparks with higher initial velocity.

As time goes by, sparks will fall more and more quickly and at the same time, they will become smaller and smaller. Finally all sparks will disappear.

SparkManager

Basically, this class is an array of sparks and some methods to manipulate the array. In practice, this class has only one instance.

Every frame, it will update all sparks and remove sparks that are not visible. Finally it will draw all sparks. Sparks are stored in an array.

Main Process

The main process is quite straightforward. This assignment is simple, however, object-oriented-programming is what we will keep using. OOP is a powerful way to program, especially program relating to visual effects.

MLNI – Interface with ML or AI (Billy Zou)

Interface with ML or AI

Neural Machine Translation

From wikipedia:

Neural machine translation (NMT) is an approach to machine translation that uses an artificial neural network to predict the likelihood of a sequence of words, typically modeling entire sentences in a single integrated model.

With neural network, machines do not translate text separately, instead, they can analyze the context of the text and pick words that fit the context most. This technology can be used widely in language-related fields.

Practical Application

Language Learning Helper

This technology is quite helpful in learning foreign languages. When people learn new languages, they tend to translate content direly from languages they are familiar with to the language they are learning. Therefore, some expression used by these language learners are like the text translated by a machine without neural network enhancement.

A straightforward solution to such problems are getting some native speakers to review the text, and that was what I did for my roommate when he learned Chinese in the freshman year. However, there are not always native speakers ready to help. With the help of NMT, we can develop an application to automatically review text for language learners and teach them how to organize sentences like native speakers.

Artistic Application

Slang Bot

With NMT, machines can understand slangs. I think the way people understand slangs are just like machines with neural network. Sometimes it is difficult to give an accurate definition of a slang, and people usually understand slangs with the contexts they are used.

The “Slang Bot” is a bot enthusiastic about slangs. When you say a sentence with slang, it can detect the slang you use in the sentence and reply you with another sentence including the same slang.

NMT introduces a new way for machines to process language. In the old days, machines understand language like a map that maps lexis to its definition. However, neural network helps machines understand language with context. In this way, machines can process language in an emotional way.

I believe it will be funny to see humans talking with robots using slangs. 

MLNI – Colorful Particles (Billy Zou)

Colorful Particles

This week I developed a simple sketch using p5 basic shapes and some transform functions.

Colorful particles

Particle

I coded these particles using class syntax. Since circles and squares in this case have a lot of properties in common, I used an abstract class Particle to include the common properties.

Problems

I did not directly draw particles at point (x, y). What I did was using

translate method to change the origin point of the canvas and draw the particle on (0, 0). What’s more, I used rotate functions to rotate squares.

The problem I had was that translate function, once called, would permanently change the origin of the canvas. Therefore, I had to correct the origin every time a particle was drown. Also I had to rotate it back.
 

Remove particles

When particles are out of canvas and are invisible, we should remove them. I did not notice this problem at first. As a result, my webpage becomes laggy soon after the program started.

The solution was dynamically removing particles that were out of the canvas. Particles were stored in an array, so I could use some array methods to remove them. After I implemented this, the performance of my program was better.