Thursday, April 29, 2010

GNU Scientific Library

Recently, I spend some time in looking for libraries that can fasten my software development. The reason is simple, if I want to develop my software for example doing a common algorithm, I don't need to spend time for developing the algorithm which might not be optimized and unstable.

The fact is that many people out there who share the same need and they have already created a group for developing an open source softwares/libraries. The advantage of such a group is that many people evaluates the software and many people will criticize when there's a bug in the software while the others will contribute to resolve the bug. Quite wonderful right? You have a lot of bright people from around the world assisting you (not exaggerating but it's quite true..).

GNU Scientific Library provides some scientific calculation such as linear least squares, FFT, Linear Algebra, Numerical Differentiation, etc. You might want to see this website for the available routines provided by GSL. It helps you focus on your task and appreciate others who has contributed their time developing this library.

After spending the whole afternoon configuring my compiler to work with this library, got a lot of error messages which are discouraging, finally I found the library that has been ported into Windows platform here

Before using this library, the compiler has to be configured. The configuration includes setting the
additional include path and the library path. After that your compiler is ready to use. My compiler is Borland C++ Builder, you need to convert the library into the Borland format instead of using Ms VC++ format (see my note about implib)

Finally, I tried this sample code from the documentation:

#include < stdio.h >
#include < gsl/gsl_sf_bessel.h >

int main (void)
double x = 5.0;
double y = gsl_sf_bessel_J0 (x);
printf ("J0(%g) = %.18e\n", x, y);
return 0;

and it works :D

I plan to use this library for my projects, it will reduce my work in implementing the basic functions.

Labels: , , ,

Wednesday, April 28, 2010


If you're working with Borland C++ Builder compiler and you want to use functions from a DLL file, usually you have to make a library file first. Otherwise your compiler will produce an error message showing that there's an error in linking with the library. Something like this:

[Linker Error] Unresolved external 'name_of_the_function_from_the_library' referenced from E:\TEST\MAINFORM.OBJ

Then in order to resolve this problem, you need to build a library that is suitable with your compiler. Most of the library files shipped with the product are made for Microsoft's compiler, so you need to make some modification to the library file.

These are some possible steps that you need to do before using the library/dll file:
1. If you have the library file for Microsoft Visual C++, then you have to convert it into Borland C++ Builder library by using 'coff2omf' command line program.

example: coff2omf cv.lib cv2.lib

2. If you have the dll file together with the header file and you have to generate the library file by yourself, you have to use 'implib' command line program.

example: implib -a fftw3-3.lib libfftw3-3.dll

These programs are provided by Borland C++ Builder, you can find them in the installation directory. For example, mine is in "C:\Program Files\Borland\CBuilder6\Bin" and it depends on where you installed your compiler, they will be available in the Bin\ directory. My compiler is a rather old compiler because I'm having difficulties in upgrading to newer version. Some of my hardwre doesn't support the new C++ Builder version. So I stick with this version.

Hope this tip will be useful for you. It works with me, so if it doesn't apply to your situation, just let me know. I might be able to explain what's wrong.

Good luck!

Labels: , ,

Friday, April 16, 2010

Visual C++ library error

If you have a problem when extracting the library from a DLL file in Visual C++ and you got this error message: Application unable to start, mspdb80.dll was not found.

Then, we have the same experience.
It has something to do with the environment variables, all you have to do is to run a script to set this. Here's how to do it:

1. Go to : c:\Program Files\Microsoft Visual Studio 8\VC and run vcvarsall.bat

c:\Program Files\Microsoft Visual Studio 8\VC>vcvarsall.bat

Setting environment for using Microsoft Visual Studio 2005 x86 tools.
and after that you can run all the tools (I hope so), it works with me.

Good luck.

Sunday, April 11, 2010

Using Message Map in Borland C++ Builder

If we want to pass information from a thread to the windows, we need to pass it safely. There are several ways that I know on how to perform this. One is by using a Message Map, which is a default message passing method in MFC(Microsoft Foundation Classes), another one is by overriding the Windows Process, i.e. the WndProc function.

There is another way of doing this in Borland C++ builder, but I found it is not stable. I don't know the reason, so I decided to change the other method. Ok, let's start.

First, you need to define the name of the windows message that you want to pass, in order to simplify, give an intuitive name e.g. UPDATE_TIMER


then, create a handler function that will process this message, for my application, I use something like this:

void updateTimerProc(CMMTimer &Timer);

CMMTimer is a multimedia timer class wrapper that I used, I downloaded it from this website in codeproject.

then begin delaring the message map


and finally, we have to pass the message to the message map system, this can be performed as follow:

SendMessage(this->Handle, UPDATE_MMTIMER, 0, 0);

Then, one more thing that you have to do is to declare the function to perform some tasks such as updating the UI, etc.

void TFormMain::updateTimerProc(CMMTimer &Timer)
//put your code here


Call this function from your callback function or your thread. And, Voila! you will get your windows UI updated from the thread.

Labels: , , ,

Thursday, April 08, 2010

Configuring OpenCV Library in Microsoft Visual Studio Environment

I have a plan to change my compiler to Visual Studio because I want to use OpenMP in the near future. However, my dream is to write machine vision algorithm that is platform-dependent, it can work with any image grabbing cards, any camera and runs at any OSs (this one might not too important for now).

Although many programmers have posted these tips, I still want to post this kind of information so that when I need to re-configure my Visual Studio I can find these steps easily, from my own blog.

First thing you need to do is go to the project setting:
We need to tell Visual Studio which directory to the include files of OpenCV, we can do this by choosing the "Additional Include Directories"

Then, choose the General part of Linker tab in the Project settings and add the additional library directory:
Then the last step is to add the additional dependency on the Input part of Linker tab and add these values.

Then, to test whether this this settings is correct or not, you can create a simple project like this:


int main(int argc, char ** argv)
const char* filename = argc >=2 ? argv[1] : "C:\\Users\\mario\\Desktop\\vc++\\testsaveimage\\debug\\1.JPG";
IplImage * im;

im = cvLoadImage( filename, CV_LOAD_IMAGE_GRAYSCALE );
if( !im )
return -1;

cvNamedWindow("win", 0); cvShowImage("win", im);

Try to build this project and see whether you have an error message or not.

Good luck.

Labels: , ,

Friday, April 02, 2010

Copying Euresys EImage into OpenCV IplImage

I tried to find a way to copy Euresys' EImage to OpenCV's IplImage. The reason is that I want to develop my algorithm based on the free OpenCV library so that I can try it anytime in my laptop without having to attach Euresys cards or license key.

Another advantage of doing this is that when I change to another image grabber card, I can still use my algorithm with some data conversion process. Speeding up will be a further issue after the algorithm is proven to work correctly.

So, here it is, by using this piece of code you can copy the EImage data seamlessly into IplImage.

Suppose that we have these objects:
IplImage *GLCVImage;
EImageBW8 GLImage;

We can copy the data directly by passing the pointer;

GLCVImage->imageData = reinterpret_cast < char* >(GLImage.GetImagePtr());

Hope it works with yours. I use this quite often and I post this here to make it easier for me in case I need to do the same thing again.

Labels: , , ,