Wednesday, December 1, 2010

from glib._glib import *ImportError: DLL load failed: The specified module could not be found.

So I was following the instructions on the pygtk website
http://www.pygtk.org/downloads.html
But I kept getting this annoying error. I knew I wasn't insane but couldn't figure out why this happened. I finally went to this page and followed the instructions to get pygtk working and it worked!
http://www.gramps-project.org/wiki/index.php?title=Windows_installer#Installation
Basically, the trick is to get the GTK runtime for windows at
http://gtk-win.sourceforge.net/home/index.php/en/Home
the other steps should be the same at pygtk.org but you can also follow all the instructions on this link and will work too. Good luck hacking up some code!

Thursday, August 12, 2010

How to install OpenCV 2.1 in Visual Studio 2010 premium

Here are some easy steps:

First make sure that you fix some issues with VS2010. It seems like by installing VS2010 Express first it would fix the errors.

1. Download OpenCV 2.1 for VS2008

2. Create a new console project in VS2010

3. Change the properties of the project to:

Configuration Properties -> VC++ Directories
Add to Include Directories: C:\OpenCV2.1\include\opencv;
Add to Library Directories: C:\OpenCV2.1\lib;
Add to Source Directories: C:\OpenCV2.1\src\cv; C:\OpenCV2.1\src\cvaux; C:\OpenCV2.1\src\cxcore; C:\OpenCV2.1\src\highgui; C:\OpenCV2.1\src\ml;
Linker -> Input -> Additional Dependencies: cv210d.lib; cxcore210d.lib; highgui210d.lib;

4. You can test it using some code like:

#include "stdafx.h"

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])
{
IplImage *img = cvLoadImage("image.jpg");
cvNamedWindow("Image:",1);
cvShowImage("image:",img);

cvWaitKey();
cvDestroyWindow("Image:");
cvReleaseImage(&img);

return 0;
}

Wednesday, August 11, 2010

How to install OpenCV 2.1 on Visual Studio 2010 Premium and Windows 7 on a 64 bit

I was so excited to get Visual Studio 2010 Ultimate running for the first time but I spent so much time trying to get OpenCV library working on it. Too much for the excitement.
I kept following this link for instructions
http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010

But I kept getting this weird Application Failed To Initialize Properly (0xc0150002) error.
After reading some blogs, forums, and then some. I realized that not even getting the Redistributable Package as some people suggested helped.
I even tried to compile OpenCV with CMake but even CMake would give me a hard time. It definitely wasn't my day. But enough complaining. So how I did I get around it?
It turned out that OpenCV works on the Visual Studio 2010 Express version with the instructions on the previous link. I got it working first on the Express version and then on the Ultimate version. It seems like there were some libraries of updates that were on the express version that the ultimate version needed. So much for being "ultimate". Well, that is enough for now. I hope this help. Happy coding. I am going to bed now :)

Thursday, June 10, 2010

Free Binarization Tool

I just released a free tool to binarize images. It uses the four popular binarization algorithms such as Otsu, Niblack, Sauvola, Kittler. It might come in handy if you need a quick way to threshold or binarize an image. I will soon make open source the main algorithms and add more algorithms. You can find the site application at:

http://binarizationsoftware.info

Let me know what you think.

Oliver

Wednesday, April 21, 2010

How to convert _TCHAR* to char* in C++

_TCHAR is a typedef of wide characters or wchar_t. Hence, we use wcstombs function to convert it to multibyte characters. This function should help you with that.

char * wchar_to_string(_TCHAR* widechar)
{
int size=0;
while( (char)widechar[size] != '\0'){
size++;
}
size++;
char * charpointer = new char[size];
wcstombs(charpointer, widechar, size );
return charpointer;
}

Wednesday, April 7, 2010

How to do Polynomial Fitting in Visual Studio

1. Install the GSL library as explained below in the previous post.

2. Follow the example in this link to do polynomial fitting with polynomial regression.

http://rosettacode.org/wiki/Polynomial_regression

3. Let me know if you have any questions. Good luck! :)

Tuesday, April 6, 2010

Getting Gnu Scientific Library working on Visual Studio 2005, 2008 express and 2010

I just tested on visual studio 2010 there is a problem with the _hypot not being included in the 2010 version. So for the code down below it will work but if you want to do something like polynomial fitting, it won't work on 2010 unless you get a work around. Hopefully they will fix this soon. I got it working on VS 2008 express and 2005 though. Here are the steps:
1. Download and install the complete GSL package for windows from:
http://gnuwin32.sourceforge.net/packages/gsl.htm
Just choose the "Complete package, except sources" link.


2. Within Visual Studio, go to:
File->New->Project,
then "Visual C++ Projects,"
then "Win32,"
then "Win32 Console Application."
Enter a name and click "OK."
On the next screen click "Finish."

3. Go to the menu Project and choose properties

4. Under Configuration Properties->C/C++->General->Additional Include Directories, type in "C:\Program Files\GnuWin32\include"


5. Under Configuration Properties->Linker->General->Additional Library Directories, type in "C:\Program Files\GnuWin32\lib"

6. Under Configuration Properties->Linker->Input->Additional Dependencies, type in: libgslcblas.a;libgsl.a;


7. Under Configuration Properties->C/C++->Code Generation->Runtime Library, select "Multi-threaded DLL(/MD)" or "Multi-threaded debug DLL(/MD)" depending on your code.

8. Replace the main .cpp file with something like the following:

#include "stdafx.h"
#include <gsl/gsl_poly.h>


int _tmain(int argc, _TCHAR* argv[])
{
int i;
double a[6] = { -1, 0, 0, 0, 0, 1 };
double z[10];

gsl_poly_complex_workspace * w
= gsl_poly_complex_workspace_alloc (6);

gsl_poly_complex_solve (a, 6, w, z);

gsl_poly_complex_workspace_free (w);

for (i = 0; i < 5; i++)
{
printf ("z%d = %+.18f %+.18f\n",
i, z[2*i], z[2*i+1]);
}

return 0;
}

-----------------------------------------------------------------

9. Hit F7 to build your program. You should now be able to run it from the command line. You'll get a result like the following:

z0 = -0.809016994374947670 +0.587785252292473360
z1 = -0.809016994374947670 -0.587785252292473360
z2 = +0.309016994374947510 +0.951056516295152980
z3 = +0.309016994374947510 -0.951056516295152980
z4 = +0.999999999999999890 +0.000000000000000000