Friday, 21 November 2014

Saving Numpy arrays to Matlab compatible files

Working in Python but want to use you data in Matlab too.

A simple function call can do this. Here is the code:

import as spio
             dict(matlabVarName = pythonVarName, matlabVarName1 = pythonVarName1))

Here savemat from stores a number of arrays to a Mat file, that can be easily opened in Matlab. Hope this could help someone.

Source: converting-numpy-arrays-to-matlab-and-vice-versa

Thursday, 20 November 2014

Hello to SyntaxHighlighter

I am trying to check if I can make SyntaxHighlighter work on my blog. This would really help me in a number of future blogposts.

#include <iostream>

int main()
     std::cout << "Hello SyntaxHighlighter" << std::endl;
     return 0;
I use html encode from here to encode the < > characters as they conflict with the HTML Tag Syntax . The code is copied directly into HTML code for this post using the <pre> Tag as:
<pre class="brush:cpp">
#include <iostream>

int main()
std::cout << "Hello SyntaxHighlighter" << std::endl;

return 0;

This is very useful and I think I will try to update all my codes in previous posts with this.

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 -; 

// 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,;

// 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.

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.