Pages

Showing posts with label Graphics. Show all posts
Showing posts with label Graphics. Show all posts

Tuesday, 2 August 2016

Particles explained using Gifs!!

Over the past few months, I have been reading, understanding and implementing a number of existing algorithms in Computer Vision domain. Implementing particles and particle based algorithms have really had me excited and almost on the edge of my seat. One may ask what makes particles so interesting?? Let me try to get the concept through.

Particles, just like most existing algorithms in computer science, are inspired by nature. Have you ever seen a beam of sunlight coming through a window and illuminate a bunch of floating particles (impossible in London though I have seen it before)? When you see these tiny particles, you notice that they are suspended in air and that it's very difficult to predict their motion unless you disturb the surrounding air. This simple concept is vital for many computer algorithms that model motion/dynamics of an object.

Particles, along with their randomness, can be simulated inside a computer program. The simplest of such algorithm is called Random Walk, where a particle is modelled with its current position/state alone and a random displacement/jump determines its next position in time. Here I have shown one Random Walk particle:

A Single Random Walk Particle

Tuesday, 21 July 2015

"Welcome to the Virtual World...may I take your username?"

Quick note: I wrote this a long time back, but never published - thought it wasn't good enough. This just occurred to me --> it's just a post - doesnt need to be perfect right?!? So posting this now - Please be sure to leave a comment with what you think!



Over the last few years, there have been some amazing advancements in gadgets - specifically the new imaging devices have emerged and a new horizon for virtual reality has been set. These devices have opened up a door for limitless future development possibilities. "Occulus Rift", the virtual reality head-mounted device that was received with overwhelming Kickstarter response, has been the pioneer in developing the key tech that can realise the virtual reality. The reason behind this huge success is an amazing idea which transfers all your senses into a digitally created world. Although this concept has been recently recognised, the idea has been around for decades.

Sunday, 15 March 2015

Estimating Pi with OpenCV

Yesterday was Pi day where the date and time specifically corresponded to the value of Pi, i.e. 3/14/15 9:26  <===> 3.1415926 . What made this day extraordinary was how different ideas and videos came out, some explaining its significance while others showing fun ways to estimate its value.

One such video caught my eye in which @thephysicsgirl and @veritasium calculated the value of Pi using Monte Carlo sampling method but with a fun twist. Instead of using random particles they decided to use random darts and a modified dart board. They explain the idea in a very simple and intuitive way in the video.

Friday, 31 October 2014

Capturing OpenGL Rendered window using OpenCV

When working with graphics I wanted to store whatever was on the output of my OpenGL render window as a set of images. Typically this is achieved by using glReadPixels to read the pixels in the rendered window and store them into a byte array. This array is then converted and saved using a helper library.

I thought of doing the same thing, however, since I am more familiar with OpenCV, I wanted to use cv::Mat to do this.

Turns out it is really straight foward, all you need to do is to initialize the Mat with the required size and store the data directly onto its data container. Here is the code:

//Get dimensions of the image
RECT dimensions = rGameWindow.GetDimensions();
int width = dimensions.right - dimensions.left;
int height = dimensions.bottom - dimensions.top; 

// Initialise a Mat to contain the image
cv::Mat temp = cv::Mat::zeros(height, width, CV_8UC3); cv::Mat tempImage;   

// Read Image from buffer
glReadPixels(0,0, width, height, GL_RGB, GL_UNSIGNED_BYTE,temp.data);

// Process buffer so it matches correct format and orientation
cv::cvtColor(temp, tempImage, CV_BGR2RGB); 
cv::flip(tempImage, temp, 0);

// Write to file
cv::imwrite("savedWindow.png", temp);

Thats all! You do need to do some data conversions to match the format of OpenCV images, but its pretty straightforward and self explanatory.

Tuesday, 18 February 2014

Creating "Mood lights" animation with OpenCV

The other day I went on a typical London walk near Thames, and as always loved the lights, reflections and the view. It was amazing! One thing I really liked was the RGB mood lights on the bridge that transformed from every possible color in a way that it made the whole experience amazing!! Here is a glimpse from my instagram.



Since there was a sequence of colors involved, I thought I would at least try to replicate these mood lights using OpenCV. Turns out its not very difficult to make this animation at all. I wrote an algorithm for doing this using some clever tricks that did make it simple and interesting. Here is a gif showing how cool the animation looks when you execute the code.



Tuesday, 10 December 2013

Implementing SnakesGame using OpenCV


A long time back I used to have a nokia phone which came with this awesome and simple game. I still love nokia phones for this, and have a couple of phones just to play it (no kidding, haha). A while back I decided that I will write my own snakes game implementation, so I did. What is interesting about this post is that I did not use any graphics engine or OpenGL rendering at all. Instead this whole game was implemented using OpenCV function calls, enabling me to make my own rendering funcitons and display buffers.

Tuesday, 19 November 2013

Implementing Noisy TV in OpenCV...wait WHAT?!?

If you are a 90's kid like me, you must admit that back then there was nothing more annoying than losing signals on your TV. Before the age of internet, TV was the main source of entertainment. When signals were lost, all you could see was an infinite race of millions of flies on your screen (a noisy image) and making it more intolerable was the loud noisy sound of the noise.