Pages

Showing posts with label Tutorial. Show all posts
Showing posts with label Tutorial. Show all posts

Monday, 28 March 2016

Designing an algorithm - from ideas to code

I had always been interested in solving sudoku puzzles, partly because there are too many combinations that make each Sudoku unique. Since my work involves writing and using programming in different scenarios, I thought why not try using my skills on Sudoku. So there I was on a London Underground train to Barbican - looking at a Sudoku puzzle at the back of a morning newspaper, wondering how I can write an algorithm to solve it. I figured out a few simple tricks that I have always used in algorithm design. Here I explain what thoughts I had while designing my very own Sudoku solver and how I transformed those ideas into a working prototype.

First of all lets have a look at a typical Sudoku puzzle and some basic rules:

Sudoku Puzzle
Yes - it has got everything to do with numbers!! lots of numbers!

A Sudoku puzzle typically has 81 boxes where each box can have a number between 1 to 9. However, all these boxes follow some rules that make it all interesting. You may have noticed 3x3 squares grouping the number boxes. A correct solution of Sudoku ensures no repetition of numbers from 1 to 9 inside each of the 3x3 squares, in each horizontal line and each vertical line. When solving a Sudoku puzzle, this is exactly where I look for a solution, and exactly where my thought process starts for my Sudoku solver algorithm.

Wednesday, 7 October 2015

Different types of Randomness..

Randomness is an integral part of a number of programming algorithms. In fact most of my research until now has been based on a computer algorithm that only uses random numbers for learning a specific task.

A while back I was trying to write some code to define and visualize different Random number generation models. For this task I was playing with a number of different algorithms and visualizing the output on a (kind of a ) probability map. [Not to mention that I use OpenCV for this project as well].

Some of these maps looked pretty cool, so I am just embedding them in this post - also if anyone is interested I have shared the link to this project at the bottom of this post, check that and modify --> make your own random distributions :D

So the input to each of my functions is a Uniform Distribution which looks like this:
A 2D Uniform Distribution

Monday, 16 March 2015

Executing Matlab scripts on different Operating Systems

Just a quick post about making matlab scripts run on different OS.

Writing a matlab code that works on both Windows and Linux is a little challenging, especially when accessing the disk both OS use a slightly different syntax for filesystem.

One solution to this is using computer string to check the OS. Once checked you can use if condition statements to execute relevant code on each system.

The script for this is pretty straight forward and is listed below:

%compile everything
if strcmpi(computer,'PCWIN') |strcmpi(computer,'PCWIN64')
   compile_windows
else
   compile_linux
end



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

Monday, 31 March 2014

Compiling OpenCV-3.0 with Matlab Support

A big uppercase HELLO to everyone!  I am back and after a long time (yet again) I am going to write a tutorial. The thing I am able to achieve here is awesome for us computer vision researchers. Yes! you heard it correct, exciting stuff.

I have been using OpenCV for quite sometime now. As good as it is for real-time computer vision applications, it can also be time consuming when it comes to exploring and implementing new research designs. Matlab on the other hand has always been flexible and a quick work around to achieve my research goals. The only problem, though, with matlab is that it is not real-time or even worse is that if you plan to implement code in OpenCV for real-time application, you would have to write the algorithms all over again as the usage of Matlab toolboxes is different than using the same methods in OpenCV.

Now comes the fun part, what if you can access OpenCV function calls within Matlab code? What if you can have easily transferable code from Matlab to C++?  This is all possible now with the OpenCV 3.0 Dev including matlab mex wrappers, which really is a good big step in the right direction. So lets start compiling the code.

Wednesday, 5 February 2014

Algorithm to check Sudoku puzzle!

I have got a couple of interviews this week, which I love preparing for as it a good way to refresh my C++ and at the same time, I get to implement some pretty interesting algorithms.

As most of us would do, I have been searching for the past few days about frequently asked interview questions and have been trying to solve most of the algorithm design questions myself. This post is about an interview question asked by google interviewers for an internship position. The question is about checking if a Sudoku Solution is correct or not.


Puzzle picture taken from: www.puzzles411.com

Monday, 12 August 2013

Setting up freeglut and GLTools with Visual Studio 2010

It's good to be writing a tutorial after a long time and there are a number of reasons for that. First of all, I have been really busy with a lot of work and research (well actually I still am!). On the other hand, it is only until recently that I have been struggling with a setup which has little tutorials documented, while there seems to be a lot of beginner developers facing the same problem as I am.

This particular tutorial deals with setting up a Microsoft Visual C++ 2010 Project for use with examples found in the OpenGL Superbible 5th Edition. The book has a section which details the same process for a Visual C++ 2008 project, which is completly different than this tutorial. As always, I have tried to keep everything simple and straightforward so even a person who has no knowledge about these settings can make them work.

Wednesday, 4 July 2012

Compiling OpenCV with OpenNI for Microsoft Kinect Sensor

I have implemented code for using OpenCV 2.4.x with latest OpenNI 2.x SDK. Detailed tutorial and code on this newer method can be found here

After installing OpenNI, as I am more familiar with OpenCV, therefore I wanted to work with the data from Kinect sensor using OpenCV. I searched online and a lot of people had been able to compile and run OpenCV with OpenNI. However I could not find any guide on how to do this. I managed to compile OpenCV successfully with OpenNI after some research, and now I am writing this tutorial for those of you who are in the same situation as me.

If you already know how to compile OpenCV with Visual C++ then this tutorial will be straight forward for you. However for completeness sake I will write everything in detail, so even if you are new to OpenCV you wont have any problems compiling from the source code.

If you want to use OpenCV with Microsoft Kinect using OpenNI SDK then, obviously, the first pre requisite is that you should have already installed and set up Kinect sensor using OpenNI and NITE libaries. If you have not already done that then please head over to OpenNI installation Tutorial and first install everything needed to set up. If you have successfully set up everything correctly then precompiled samples inside OpenNI and NITE folders should be working with your Kinect Sensor., which means you are good to go with this tutorial.

Thursday, 21 June 2012

Installation of OpenNI with NITE middleware for Microsoft Kinect

Update (31/03/2013): Since writing this blog post, there have been a number of updates to the OpenNI SDK. Now the framework is totally changed, and the links to the OpenNI and NITE binaries used in this tutorial have been moved to another location. You will need to download the specific version of binaries from the new links, rest of the installation process is still the same.

Okay, so this post is again a guide for installation of another library. This time it is OpenNI library for Microsoft Kinect. I am currently working on a computer vision project which utilizes the power of Microsoft Kinect's depth sensor. While researching for my project, I found out that OpenNI library is better than Kinect SDK in many ways. It is opensource, cross-platform, has skeletal as well as hand tracking (which I needed for my project), gesture recognition and ability to use OpenCV were many reasons for choosing OpenNI over Kinect SDK.

OpenNI contains the SDK to access RGB and Depth data from depth sensors containing primesense hardware which includes Microsoft Kinect. However to use skeletal tracking, hand tracking, gesture recognition or any other natural interaction functions in an application a natural interaction library called NITE is required. To use these libraries with Microsoft Kinect, drivers for using Kinect sensor with OpenNI and NITE are required. To install these libraries and drivers is the easiest part, however to make the sensor working with these libraries is really difficult. I followed a number of guides online, however I could not find any guide which could completly resolve all the problems which come after installation and make the sample programs work. I am writing this guide to make sure that most people get the sensor working with these open source libraries.

Monday, 12 September 2011

Linux Like Installation of OpenCV 2.3.0 on Windows

So you have been using Linux for opencv programming lately and now, for some reason, have no other option then to work on Windows. I too have to go through the same situation when I had nothing but Windows on my desktop and I was been too lazy to install Linux or maybe I wanted Windows for gaming.

Well this is your lucky day then, because I will be guiding you through 'Linux-Like-Installation' of OpenCV 2.3.0 on Windows. This guide will use minimum possible Linux System installation , hence it wont take much time to setup except for OpenCV compilation which takes sometime (and hey we all need sometime to relax)
First step is to download all the packages required for setup. Here are the direct links to the packages. You can also google these packages if, for some reason, you can not download them from here.
  1. Minimalist GNU for Windows: TDM-MinGW-4.5.2
  2. Cmake 2.8.4: cmake-2.8.4-win32-x86
  3. MSYS 1.0.10: MSYS-1.0.10
  4. OpenCV 2.3.0 Source: OpenCV 2.3.0

Saturday, 21 May 2011

Easily Compile and Build OpenCV codes in Windows MinGW Setup

After successfully setting up OpenCV2.0 with MinGW in windows, I started off with my project.

I was really annoyed at copying long string to cmd.exe to compile and link my project and then to execute by opening .exe file.

So I started searching about dos batch and wrote my own script to compile and execute my project in one go.
The script is as follows:
cls
@ECHO OFF
e:
cd\cvprog

:St
echo Enter the file to compile and link (enter for last file)
set/p "filee=>"

g++ -Ic:\OpenCv2.0MingW\include\opencv -oo -g3 -Wall -c -otemp.o %filee%.cpp
g++ -Lc:\OpenCv2.0MingW\lib -o%filee%.exe temp.o -lcv200d -lcvaux200d -lcxcore200d -lcxts200d -lhighgui200d -lml200d

echo Bazzingaaa!!
%filee%.exe
set/p "in=>"
if %in%==q goto exita
if %in%==Q goto exita
goto St
:exita

I am doing all my coding in the folder e:\cvprog , therefore everytime it runs it goes to that folder first. You can change the folder location to your own project folder.

How to use it? Simple! Copy paste this script in Notepad and save as run.bat on desktop. Open by double clicking run.bat then enter filename excluding the extension (which this script takes as .cpp but can be changed for ones requirement) to compile and execute your code. After first compiling and executing a code, the script loops back to start. Now if you want to compile and execute the same code again, you can just press enter key, the script will automatically take the last entered filename.

Thats all for now, right now I dont have much time to improve this script as I am working on my project. Soon I will be posting about my own project as well. Till then cyaa, happy coding :D

Wednesday, 4 May 2011

Setting up Opencv2.0 with MinGW on Windows

I have been using OpenCV for quite long now, and well I must say it is a very good library for implementing different image processing technique in real time. Previously I was using Ubuntu 10.04 along with OpenCV 2.20, which was very easier to setup as compared to my recent venture.

In order to test my projects on a slower system, I decided to work with OpenCV on my old desktop with Windows Xp. I thought it would be much easier and less time consuming to set up everything as Windows is always considered to be better at interacting with user. However after few hours, I was proven wrong.

Since I previously worked in Linux Envoirnment and my old desktop was slow enough to not smoothly run any IDE software, I wanted to setup something similar to linux terminal and gedit. After googling for few minutes, I successfully found the fastest, or should I say the slowest way, of setting up OpenCV. It involved using MinGW (minimalist gnu for windows) and OpenCV 2.0 precompiled library for MinGW. After installing everything, when I compiled a simple helloCV program, it crashed!