I've been trying to use the OpenCV 1.0 but apparently (for some reason) it does not work well with my PC. Bear in mind that there could be several reasons, i.e. I didn't set up my Ubuntu, C/C++ compiler, OpenCV correctly (although I already followed the instructions in the OpenCV Wiki... or at least I think I did.) According to the Wiki, to install OpenCV 1.0 I would need to have;
- GTK+ 2.x
- pkgconfig
- libpngzlib ... etc (Please refer to the Wiki if you want to know the complete list)
---------------------------------------------------------------------- Libraries have been installed in: /opencv_library_install_path/opencv-1.0.0/lib |
... which I never did. So I wondered if it got installed correctly or not. The Wiki tells to do "make check" at the terminal to "... check whether the library is installed properly ..." But when it was finished, it didn't give any confirmation like "Yes, OpenCV is installed properly on your machine" or "No, your machine sucks" or something.
Regardless, I think it's installed so I tried a simple program to just load an image:
// loadimage.cpp
// load an image and display it on a window using OpenCV library
#include <stdlib.h>
#include <stdio.h>
#include <cv.h> // an OpenCV header file
#include <highgui.h> // another OpenCV header file
int main() {
IplImage* img = 0;
// img : variable for the image
// IplImage is a data type for images in OpenCV
img = cvLoadImage(“photo.jpg”, 1);
// load image “photo.jpg”
cvNamedWindow(“mainWin”, CV_WINDOW_AUTOSIZE);
// create a window named “mainWin” to display the loaded image – set on autosize so it matches the dimensions of the image
cvMoveWindow(“mainWin”, 100, 100);
// place the window in the coordinates (x: 100, y: 100) -- the origin (0, 0) is the top left corner of the screen
cvShowImage(“mainWin”, img);
// display the loaded image (photo.jpg) in the created window (mainWin)
cvWaitKey(0);
// do nothing/wait until a key is pressed – then continue to the next line
if (img) printf(“success!”);
// if the image is successfully loaded, print “success!” on the screen
cvReleaseImage(&img);
// clear the memory that was used to load the image
}
// end of program
I tried compiling my program using command such as:
g++ loadimage.cpp -o loadimage -I /usr/include/opencv -L /usr/lib -lhighgui -lcv -lml |
..because the .h files are in the /usr/include/opencv folder, and the library files (libhighgui.*, libcv.*, libml.*, and libcvaux.*) are in the /usr/lib folder (I've checked). No compilation errors. All good...? Not quite.
When I run it using:
./loadimage
This is what I got:
OpenCV ERROR: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support)
in function cvNamedWindow, window.cpp(71)
Terminating the application...
called from cvUnregisterType, cxpersistence.cpp(4933)
Terminating the application...
called from cvUnregisterType, cxpersistence.cpp(4933)
Terminating the application...
called from cvUnregisterType, cxpersistence.cpp(4933)
Terminating the application...
called from cvUnregisterType, cxpersistence.cpp(4933)
Terminating the application...
called from cvUnregisterType, cxpersistence.cpp(4933)
What the...?? When i removed the cvNamedWindow, cvMoveWindow, cvShowImage, and cvWaitKey, it worked however -- no compilation error, and it displayed "success!" So what's wrong??
Searching through the web, I found several people had very similar problems... however, there's a slight difference (and I don't know how significant this is) that instead of saying:
in function cvNamedWindow, window.cpp(71)
they had:
in function cvNamedWindow, window_lnx.cpp(822)
One of the replies said they were able to solve the problem by installing some other libraries such as: libwxgtk2.4 and libgtk2.0-dev as was said here (but he used Knoppix 4.0.2) -- so I tried installing those (again from the package manager), to no avail.
So I asked my friend who is more familiar with Linux/UNIX environment (I'm still a newbie at Linux)... he recommended that I look into the environment variables and make sure that the directories where the OpenCV library and header files are listed in the PATH. I checked it using:
echo $PATH
Well, it's not there. So I added to the path:
/usr/include/opencv:/usr/lib:/opencv_library_install_path/opencv/lib
to my PATH; I modified the etc/environment file using gedit as root:
sudo su (to get into root)
(in etc folder): gedit environment
and add my path there and saved it. I'm curious though, most people said their library is in /usr/local/include/opencv and /usr/local/lib ... peculiar... is it Ubuntu specific? Or something's wrong with my configuration?
Nope, that didn't work -- I still get the same thing: no compilation error, and the same error during execution.
So i tried the next thing mentioned in the Wiki, when compiling the program, set the PKG_CONFIG_PATH variable. Here's the guide.
Nope, still didn't help.
I couldn't find many resources to solve the problem, so finally I tried searching for OpenCV through the package manager -- I found the OpenCV version 0.9.7 for Ubuntu. Being a bit disappointed that I can't get the 1.0, I tried it anyway and the package manager automatically installed it for me. The library and header files are located in: /usr/lib and /usr/include/opencv, respectively but with suffixes 0.9.7 on the file names; so, for example: libhighgui.so is libhighgui0.9.7.so and so on.
And so, now I compile my program using the following:
g++ loadimage.cpp -o loadimage -I /usr/include/opencv/ -L /usr/lib -lcv0.9.7 -lhighgui0.9.7 -lml
..no compilation error. OK... so let's run it
./loadimage
Lo and behold! There's my image, showing up in all its glory!!! It finally worked! I'm so moved that I decided to write this entry and share my excruciating experience with you.
So, what can we get from this experience? Does this mean OpenCV 1.0 does not work with Ubuntu 6.10 yet, and only 0.9.7 works so far? Or, I messed up the installation process and my configurations... If somebody could point that out, I would be so very grateful. It's been a puzzling pain this past few weeks.
However, I don't think it's 100% working well... I still get
Segmentation fault (core dumped)
..after I hit Enter after the image loaded. Not sure what causes this yet.
I guess not many people encountered this problem, so I really would like to know what causes this. I refer to the Wiki a lot and said it didn't work, but don't think I'm blaming it or saying that it is useless ... I refer to it because I think that is the most standard guide for using OpenCV, it should work with properly configured machines -- it just turns out that it didn't work for me and my machine.
I tried some other things under Eclipse as well (setting include & library paths)... but didn't work. But I haven't tried it again after it worked with 0.9.7.
Sorry if the formatting is messed up. I still have yet to figure out how this blogging tool works.
2 comments:
Just a quick comment. I'm using Ubuntu Feisty with opencv, and was getting a segmentation fault error.
My error went away after installing the python-opencv package from synaptic. Even though it was counter-intuitive that I'd need something labeled "python" for a c++ project, it worked.
Try the steps that Artineering recommends (in this post and the update), and if those fail, try installing python-opencv.
My client, Lance Dehne', business owner of ARTineering since 1985 and trademark holder of ARTineering requests that you immediately cease and desist using his Company name.
Post a Comment