Pages

Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Monday, 6 June 2016

Expectation Maximization for Gaussian Mixture Model in OpenCV

I recently wrote code for Gaussian Mixture Model (GMM) based clustering in C++. As always, I found it much convenient to use OpenCV for manipulating matrices. Although there already exist an implementation of Expectation Maximization-based GMM, I tried to understand it by writing my own implementation.

The basic idea of GMM is to first randomly assign each sample to a cluster. This provides initial mixture model for clustering. This is then optimized using Expectation - or the probability/score of assigning each sample to each component in GMM - and Maximization - or updating the characteristics of each mixture component with the given probability/score . An attractive attribute of GMM is its ability to cluster data that does not have clear boundaries for clusters. This is achieved by having a probability/score for each sample from each cluster component.

Monday, 9 May 2016

Matlab script for checking and deleting folders

Just putting this simple but extremely useful matlab script for my future self and anyone trying to handle folders using matlab. This script checks all the sub directory within the starting directory and then deletes the one that do not satisfy a given criteria. In my case this was the number of image samples within a folder.

% script for deleting folders with less than a certain number of files
close all
clear all
clc

% count the number of png files
D = dir(' ');


numFoldersOrFiles = size(D, 1);

thresholdFiles = 30;

% skipping the first two which are just . and ..
for i = 3: numFoldersOrFiles
    
    if D(i).isdir
        
        Ds = dir([D(i).name '\*.png']);
        numFiles = size(Ds, 1) / 3;
        if numFiles < thresholdFiles
            
            rmdir(D(i).name, 's');
            
        end
    end
end


% all done :)

Saturday, 16 April 2016

OpenCVKinect 2.0 - Acquiring Kinect depth stream in OpenCV

It has been almost two years since I first wrote the code for OpenCVKinect. It has been really good to know that it has been used by a number of other students/developers at GitHub for collecting and analysing Kinect depth streams in OpenCV. I have had some feedback about a possible bug and some students have asked how they can visualize the depth maps in a better way. So today, after a long time, I am releasing the first official update to this project.


Sunday, 24 May 2015

What if I told you, you can use OpenCV code with Matlab mex!!



Matlab is probably one of the best tools for quickly prototyping and testing your research ideas. As quick and flexible it is, sometimes Matlab code can consume a lot of execution time. This is specifically a big hurdle when multiple experiments need to be run. A real-time execution alternative is to implement Matlab compatible C++ code and compile it with mex-compiler. While this works most of the time, it is well known that quickly implementing ideas in C++ is not possible.

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



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.

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.

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.

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.



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.

Saturday, 21 July 2012

AndroidWifi is live!

Following my post few months back about how to set up a simple script to share your connection with Android devices in particular, I found that there was no application which provided full capabilities as my batch scripts did. I started work on a very simple application to convert these scripts into an easy to use application. Today I am releasing first version of this application.




Why AndroidWifi?
While reading this post, some of you might be wondering, why use AndroidWifi? why go through all these steps?

The answer is simple. This is the only free software available to date which enables you to share all types of internet connections over wifi.

These include:
  • 3G dongle internet
  • Wired internet
  • Wifi internet from another router
  • internet accessed through USB adapters

Update 13/08/2013: I am seeing people copying this blogpost as it is on their blogs. For this reason I have put a password on the file.

The software can be downloaded at: AndroidWifi_0.9  AndroidWifi_0.91 AndroidWifi_0.95
Download password: seevisionc.blogspot.co.uk

Sunday, 10 June 2012

Select And Save - An application

This post is just to give an intro to a small and simple application I wrote which I named after what it does "Select and Save". The idea is very simple, you want to save an image or part of an image from your webcam, and at the same time sort them into a series of files with distinct but well defined names.

When you start the application, it shows a window with the webcam output and a console window for instructions. There are basically two functions which can be performed, while the capture window is in focus. These functions are explained below:

Capturing the whole frame
This is a very simple function, it captures the whole frame and saves it, as a 640x480 jpg, into a file named in a format which I will discuss towards the end of this post.

Capturing a region within the frame
This function might replace most commonly used 'cropping-the-image' by some photo tool methods. The main aim of this function is to capture only the information selected by the user. The implementation is simple and natural. You just have to point, click down, drag to required region and viola!!

Now some word about the file name format. The files are stored in the folder where the application is running, with the following format:
Image-YEAR-MM-DD_HR_MIN_SEC.jpg
This name takes the current local date and time, which is really distinct for two images taken, considering they are not taken within a second of each other.

Here are some screenshots of how it actually works:


Selecting a region using mouse


Selected Region output


Finally here is the link for binary for this project: mouseSelectAndSave
It uses OpenCV libraries, which I have copied inside the application folder, just in case you dont have OpenCV installed or have different version than mine.



Sunday, 3 June 2012

AndroidWifi

To read the update messages on this guide click here
 
A few months back, I bought an android phone. I found android was way better than iOS, except for one little issue, which I was fortunate enough to get around. I have always been sharing my internet connection with my phone, be it an iPhone, iPad or any other device. They all worked pretty well with my windows Ad-hoc connection sharing. Except for this phone which is really a major disadvantage.

A lot of people use connectify to get around this on windows 7. For me, as it has always been, I wanted something simple and fast. I did some search, and found out an easy way of making a virtual router. This involved using command line to give commands for enabling virtual wifi, so it was easy for me to write a batch script which did all the work for me. Its pretty much same as connectify, but way faster and simpler, plus instead of using that 'advertising' SSID in connectify, you can choose your own SSID name with this method. I have divided the setup into few simple steps, so everyone can understand easily.

Settings on your phone

While I was trying to make a virtual router on my laptop I could connect successfully but after a while the phone had problem browsing, connecting or even discovering the virtual router. I started troubleshooting, and found out that the problem was not with the virtual router, but it was in the phone settings. My android phone used network based location services which, whenever the phone connected, tried finding the location using the network. It was this service which made the wifi connection impossible. I disabled this and it started working as a charm. To disable this service on Nexus S (Ice Cream Sandwich), go to Settings->Location Services and disable all services as shown below.


Disabling these options will be similar in other android phones as well. Just look for Location options in settings, and you will get there.

Settings on your pc
 
UPDATE (21/07/2012): I have written an application for doing this step. 
Here is the link: AndroidWifi is live!
If you use this application then this step can be skipped. 

I have written this guide using Windows 7, however similar method can be used on Windows Vista. To start with settings on your pc, first thing you have to do is make a batch file. To do this open a new notepad window and copy the following lines.
netsh wlan set hostednetwork mode=allow ssid=MySsid key=MyPassword keyUsage=persistent 
netsh wlan start hostednetwork
Replace MySsid with the SSID name you want, and MyPassword with your own password. Save this file as TurnWirelessOn.bat, and make sure the extension is .bat.

As you might have already guessed this batch file will be used to turn on the wireless connection. We need one more batch file to turn off the virtual router. To do this follow the same procedure as above replacing the commands with the following commands.
netsh wlan stop hostednetwork
 Name this file as TurnWirelessOff.bat for simplicity.












Sharing your connection
Now comes the tricky part. You have to run the above batch file, which will first create a virtual wireless connection. After it has been created, you can use it to share your LAN connection to. To do this, right click  on TurnWirelessOn.bat file and select run as administrator.



 This will enable an internet connection with the SSID and password you provided. Now go to Network and Sharing Center->Change Adapter Settings. You will notice two wireless connections, as shown below:






Note down the name of the wireless connection which uses Microsoft Virtual Wifi Miniport. In this case it is called Wireless Network Connection 2.

Now right click and open properties of Local Area Connection. Go to Sharing and enable  connection sharing and choose Wireless Network Connection 2.




Once you apply the settings, you might get a notification that the connection is currently active. This can be fixed by TurnWirelessOff.bat. Opening this file as administrator will turn the connection off, enabling you to set the sharing options.

Once everything is set up, just use the two batch scripts to share your internet connection to your android, and enjoy!

Update (07/07/2012):  As I can not try this method on different version of windows, with different models and android version, therefore I request everyone to please leave a comment with windows version, mobile model, type of internet shared and android version

If it is working great for you, why not share it with others. It will just cost you a simple LIKE at alternativeto page for this software (I don't really think it is, but lets just call it a software)

Cheers!
 
This work is produced under the following creative commons license: 
 
Creative Commons Licence
AndroidWifi by Muhammad Asad is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Based on a work at http://seevisionc.blogspot.co.uk/2012/06/androidwifi-alternative-to-connectify.html.

_______________________________________________________________________________________
Update(13/08/2013): I am seeing a lot of bloggers copying this blogpost as it is on their blogs without mentioning the source where they copied it from. For this reason I have created a creative commons license for this, which means that you can copy, modify and use the content as long as you share your software free of charge and mention the source.
_______________________________________________________________________________________

Update (11/03/2013): I have been really really busy with work, and therefore have limited time to answer everyone's questions. If you get stuck somewhere, then please read all comments as solution to almost every problem you can come across can be found in the comments. If you succeed please post the following details in comments below, as these might help anyone trying to share internet with similar setup as yours:

1. Windows Version
2. Mobile Model
3. Type of Internet Shared 
4. Android Version.

If you find out any additional detail that is missing, or anything which solved the problem you are having and is not listed below, PLEASE DO WRITE IN COMMENTS BELOW. THANK YOU!!

_______________________________________________________________________________________
Update (21/04/2013): I am seeing a number of interesting links coming in to this post. I thought it might be interesting for you people to find out about what other devices/areas this script is able to work.

1. This guide has been used by a user of roku streaming player to share his existing internet connection with the roku player. The original forum post can be found here, and might be able to solve a very common issue of not being able to access internet, despite being connected to the virtual router.

2. A question from a reddit user, which can be found here.

3. Other bloggers, translating and writing the same guide again with some modifications, so people can understand in their native language. This post can be accessed here

4. A senior forum member at xda developers forums recommended this method to other users. The full thread including the post can be found here

5. Users have recommended this method on pcmweb.nl forums. This post in Dutch. Thanks to google translate, the users are recommending this method over buying a wireless repeater hardware.

Click here to go to back to the start of this post
_______________________________________________________________________________________

Wednesday, 25 January 2012

GSVI v2.0 real-time

After having finished the prototype guidance system earlier, an idea struck into my mind to make it real-time. Since everything was implemented in matlab (for the prototype) and because matlab is not good for real-time systems, I had to implement everything again (well sort of) in C++. I love working with OpenCV so there I began, doing all the stuff again in C++ using OpenCV library.

After much work, and tunning it with different algo's, i finally had it up and running. However, now came the main problem of testing this system in a real envoirnment, and since I have implmented everything on my desktop, it was impossible to take the desktop in a real path. So I took my camera and shot a small clip simulating a blind person walking, and deviading in both left and right directions slightly and then coming back to straight path.
I opened up this video using OpenCV and simply ran my code, the output was really impressive. This was the first time my system was working in a real world scenario, without controlled conditions.

Here is the output from the actual code:


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!