Friday, November 4, 2011

Installing OpenCV in Ubuntu with Eclipse

For some reason I had a lot of trouble installing OpenCV on a Linux system, so here's hoping this will help someone.
Although building from source offers a greater level of customization, this tutorial will not go into that for various reasons.

This was tested in Ubuntu 11.10, but it should work on older versions and/or Ubuntu derivatives (like Linux Mint, Bodhi Linux etc.) as well.
First and foremost, we will install OpenCV then move on to installing Eclipse and lastly make them work together.

Become root and enter these commands.
add-apt-repository ppa:gijzelaar/opencv2.3
apt-get update
apt-get install libopencv-dev

If there were no errors, OpenCV 2.3 should be now installed. Install Eclipse either from the repository or from their official site.

Open up Eclipse and create new C++ project. Once the project is made, right click on it and go to properties.
Select C/C++ Build from the menu on the left, then select the Settings entry from the submenu. Go to the first tab, Tool Settings and under GCC C++ Compiler select Includes (or Directories) and add the path
/usr/include/opencv
.
Adding include path
Now go to Libraries under GCC C++ Linker, and add the libraries that you need. The following libraries can be added:
opencv_core
opencv_imgproc
opencv_highgui
opencv_ml
opencv_video
opencv_features2d
opencv_calib3d
opencv_objdetect
opencv_contrib
opencv_legacy
opencv_flann

The most basic libraries are opencv_core and opencv_highgui, be sure to always add these. Under the Library search path add
/usr/lib
.
Do add these paths and libraries for both the Debug and Release builds of your project.
Adding libraries to project
Click OK to continue.
Copy an image in to your project folder, name it image.jpg then create a new main.cpp file and insert the following test code.
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cv.h>
#include <highgui.h>

int main(int argc, char *argv[])
{
IplImage* img = 0;

img=cvLoadImage("image.jpg");

cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);

cvShowImage("mainWin", img );

cvWaitKey(0);

cvReleaseImage(&img );

system("PAUSE");
return 0;
}


Build and run the project, and if you set up everything correctly, you should see a window pop up with your image inside it.
If you get compile errors reread this post and make sure you set up the includes and libraries correctly.

Friday, July 8, 2011

Heroes of Might and Magic 3 on Linux

This tutorial presumes that you have a cd or an iso of HOMM3 released by Loki Software, which runs natively on linux. This is not for the Windows version which can be run through Wine.
This is tutorial is particularly for Debian and/or Debian derivatives, but it should work for other distros as well.

Let's say the cd is mounted at /mnt/cdrom
apt-get install ksh
cd /mnt/cdrom
ksh setup.sh
At this point, sound may not work, and fullscreen may not work. Let's fix that.
cd ~
wget ftp://mirrors.dotsrc.org/lokigames/updates/heroes3/heroes3-1.3.1a-unified-x86.run
This will give some errors and possibly segfault, but don't bother with it.
sh heroes3-1.3.1a-unified-x86.run --keep
cd heroes3-1.3.1a-unified-x86/bin/Linux/x86/
The patch is of course faulty, so we'll have to patch the patch ...
rm loki_patch
wget http://icculus.org/~msphil/loki/x86/loki_patch
chmod +x loki_patch
cd ../../../
sudo sh update.sh
cd ~
At this point fullscreen works from start, but the sound may have some errors, or it may not work at all.
wget http://www.swanson.ukfsn.org/loki/loki_compat_libs-1.3.tar.bz2
tar -xf loki_compat_libs-1.3.tar.bz2
mv Loki_Compat /usr/local/lib/
And run the game with :
LD_PRELOAD=/usr/local/lib/Loki_Compat/libstdc++-3-libc6.2-2-2.10.0.so:/usr/local/lib/Loki_Compat/libsmpeg-0.4.so.0.1.3:/usr/local/lib/Loki_Compat/libsmjpeg-0.2.so.0 /usr/local/games/Heroes3/heroes3.dynamic
You can create an alias for this, and update your menu/shortcuts.
Sound should work now.

Also, remember to run the game as a regular user, otherwise your config and save files will be stored in the root's home directory.

Have fun.