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:

RECT dimensions = rGameWindow.GetDimensions();
int width = dimensions.right - dimensions.left;int height = dimensions.bottom - dimensions.top; 
cv::Mat temp = cv::Mat::zeros(height, width, CV_8UC3); cv::Mat tempImage;   
glReadPixels(0,0, width, height, GL_RGB, GL_UNSIGNED_BYTE,temp.data);
cv::cvtColor(temp, tempImage, CV_BGR2RGB); 
cv::flip(tempImage, temp, 0);
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.

Saturday, 27 September 2014

Saying hello to the Internet of Things!

A while back I signed up for Microsoft Developer Program for Internet of Things ( #iot for more info ). As much as I love exploring new things this was extremely exciting thing for me.

I have always had the curiosity to know more and try to hack things my own way. Even as a kid I had an investigative mind which always tried to discover more about how everything works. You can imagine this curiosity by the fact that I got severe electric shock as a kid, when I tried to cut a live wire from "Clothes Iron". This curiosity grew more and more in me, to a point that I did an engineering degree (Yes! I was born with an engineer's mind). I have always been interested in hacking different devices to make something more useful out of it.

Friday, 26 September 2014

Gif animation using ImageMagick Command-Line

I have used GIFs in a number of presentations I have done and they are very useful if, like me, you are working with images/data which changes over time. Luckily I have found a very easy method of converting an image sequences into a GIF.

All you need is a working installation of ImageMagick.

Sunday, 6 July 2014

Déjà vu

I have been yet again busy with a lot of work, this time its quite exciting stuff.

Anyways, today I saw something really amazing that I had to share it. If you guys have seen my older posts, you might have come across a post showing the journey of my sketches. I would like to show a sketch titled "Lost!?" which I did in 2010:


This sketch was totally a creation of my imagination, I had never seen any place like this before. That is only until today, when I was left completely speechless. I  was in Hyde Park and what I saw was completely fascinating:


How did this even happen? I have no explanation to this. Undoubtedly this is a moment when you can perfectly use the phrase "Déjà vu"

Sunday, 25 May 2014

The journey of my sketches

Okay, this post is not related to anything this blog is about, however I have a feeling that this might be interesting for atleast someone.

Well when I started to write this post, it was more about how I learned to sketch with all the sketches I did and the reasons why I did them. Now after writing this post, it looks more like a journey, a journey which started sometime back. I had no skill, no proper tools, no knowledge about sketching and at some point I never thought I would do it at all. This all started one day when I was extremely bored and free, and I thought it would be cool to learn how to sketch. I started looking at other people's sketches on deviantart and tried to replicate most of the things they had done in their sketches.

My first sketch had soldiers in them. At the time I used to watch TV series "Band of brothers" and thought it would be cool to do one of the wallpapers in pencil. It was hard at first, but gradually I learned a few tricks. This was pretty basic and required not a lot of skill.

click to enlarge