How To Install OpenCV computer vision library on Puppy

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
jyore
Posts: 43
Joined: Sat 06 Nov 2010, 15:41

How To Install OpenCV computer vision library on Puppy

#1 Post by jyore »

*******************
Verified Installs
*******************
- Original install by myself on Puppy 4.3.1
- Secondary install by myself on Puppy 4.3.0 (from fresh puppy install)
- Install by swindler on Puppy 4.3.1 (from fresh install)
*******************

I finally got OpenCV installed and running after many frustrating hours of hacking at terminal commands and tracking down libraries. Turns out it ended up being a lot simpler than I was making it, thanks to the PET package directory on the Puppy Official Site.

This is a HOW TO guide on how to get OpenCV up and running in Puppy:

First, we must install many prerequisites to even have the slighest chance at getting this thing to compile. Here are a list of all the packages that I installed before compiling. They can mostly all be downloaded from HERE

NOTE: It should be noted that before you start installing anything but the devx file, that you should verify that you have a recent version of gtk+-2.x (with the dev packages too). There should be some PETs in the same directory that the link above points to.

As noted by swindler, there may be an issue with the gtk+-2.18 PETs, but the gtk+-2.14 PETs work

The pets that are links are not in the folder mentioned above can be downloaded from the link when you click on them.
  • devx_xxx.sfs
    Python+=2.6.4-i486.pet
    ffmpeg-20080731-i486.pet
    ffmpeg_DEV-20080731-i486.pet
    zlib-1.2.3.pet
    libjpeg-6b.pet
    libpng-1.2.22-patched1-pup4.pet
    libtiff-3.7.4.pet
    fontconfig-2.6.0-prescott.pet
    fontconfig_DEV-2.6.0-prescott.pet
    x264-20080731-2245-i486.pet
    libv4l

After you have all of those packages installed, you need to get opencv
do that by running:

NOTE: <your_working_dir> indicates the path where you wish to install OpenCV

Code: Select all


#cd ~/<your_working_dir>
#svn co http://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/trunk .
After the source code finishes downloading, we can finally start installing. Run the following commands to install:

First, we make a release directory where we will be installing to and cd into that directory.

Code: Select all


#cd ~/<your_working_dir>/opencv
#mkdir release
#cd release
Next, we have to run cmake to configure the build. Followed by the traditional make and make install


NOTE: OpenCV now ONLY supports CMAKE to build. ./configure is no longer used.

Code: Select all


#cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
If your cmake ouput says the following:

-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - not found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - not found


Then we have to modify the CMakeCache.txt file. If it says that those libraries are "found", then skip this step.

First of all, verify that the videodev.h and videodev2.h files exist in the directory: /usr/include/linux

If they don't, then you are likely missing a dependency, that we need to track down for you, before you can continue this install.

If they exist, then you need to open the CMakeCache.txt file from your release folder (should be in the current directory that you ran cmake from)

Search for the lines:

Code: Select all

//Have include linux/videodev.h
HAVE_CAMV4L:INTERNAL=
//Have include linux/videodev2.h
HAVE_CAMV4L2:INTERNAL= 
And add a 1 after each equal sign to make it look like this:

Code: Select all

//Have include linux/videodev.h
HAVE_CAMV4L:INTERNAL=1
//Have include linux/videodev2.h
HAVE_CAMV4L2:INTERNAL=1 
Save the file and go back to your terminal.

Now run:

Code: Select all

#make
#make install

Now that the source has been compiled and installed, we must make some adjustments to the library path and pkg-config path in order for the libraries to be referenced from any source file on your file system.

Run the following code to add the libraries to the paths:

Code: Select all


#ldconfig -v
#export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
#cd ~/<your_working_dir>/opencv
#export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

It is a good idea to test the install now.

Run the following code to run the cxcore and cv tests:

Code: Select all


#cd ~/<your_working_dir>/opencv/release/bin
#./cxcoretest
#./cvtest -d ~/<your_working_dir>/opencv/tests/cv/testdata/cv
I had no failures on the cxcore test and a few failures on the cv test due to no data being available. I didn't have the camera working and I think they were testing video. It runs fine regardless.


Finally, it is time to have some fun! A good place to start is with the samples that install with OpenCV. You will need to navigate to the directory

Run the following to build the samples and run an example:

Code: Select all


#cd ~/<your_working_dir>/opencv/samples/c
#. build_all.sh
#./delaunay

Go ahead and try the other samples as well. Some of them are especially neat (some do require a camera).


If you have any questions or suggestions, please let me know. Also if you try it on another version of puppy, also let me know so I can add it to the verified versions.

ENJOY!!
Last edited by jyore on Mon 22 Nov 2010, 06:58, edited 7 times in total.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#2 Post by Flash »

What is Open CV good for? What would I use it for?

User avatar
jyore
Posts: 43
Joined: Sat 06 Nov 2010, 15:41

#3 Post by jyore »

OpenCV is an open source computer vision library originally put out by Intel. It is now managed by Willow Garage.

Here is a link to their web page: OpenCV

With computer vision, you can do all kinds of image processing. To list a few:

- Face recognition
- People recognition
- Find a specific letter, shape, image, etc in a larger image or video
- Movement tracking
- Reconstruct a digital version of the real world

How is all of this useful? Well, for instance, I am currently doing research in the field of autonomous construction. We use computer vision to detect all the construction equipment and payloads in the environment. The computer that is doing the computer vision issues commands to the equipment to tell them where to move, how to move, as well as what operation to carry out (pick up a payload, drop a payload, wait for the crane to move a payload, etc).

Hope this gives you a little insight on computer vision and OpenCV. If you have any further questions, feel free to ask.

User avatar
jyore
Posts: 43
Joined: Sat 06 Nov 2010, 15:41

Screen Shot

#4 Post by jyore »

Here is a screen shot of an example from OpenCV. This particular example uses the find_obj sample.

What it does is takes a certain image and finds all the objects in another image larger image that contains many objects.

User avatar
swindler
Posts: 5
Joined: Thu 15 Oct 2009, 23:57

#5 Post by swindler »

nice work on pulling together all those dependencies. that's been quite a search through the labyrinth.

have you had any luck on getting camera support working? I still can't find a gstreamer that works, and even though I have libv4l-0.5.8.pet installed, cmake can't seem to see it.

any suggestions?

User avatar
jyore
Posts: 43
Joined: Sat 06 Nov 2010, 15:41

#6 Post by jyore »

I am currently working on the video camera support on Puppy. I think the problem is in the V4L install. I'm not sure the exact problem, however.

As a sanity check when I was tracking down the dependencies, I did the same proceedures on my Ubuntu machine. Using apt makes tracking down libraries much simpler :). On my Ubuntu install, I do indeed have camera support, and I did not include any of the gstreamer stuff. Actually, the OpenCV guides never mention the need for gstreamer as a needed pre-req, just all the ffmpeg libraries.

I was originally going to include the gstreamer stuff, but was getting lots of problems from doing so. After the Ubuntu success without them, I just neglected to care about the gstreamer libraries.

If you do wish to compile with gstreamer, you will need to track down and install at least the following libraries:
  • gstreamer
    gstreamer plugins base
    gstreamer plugins good
    gstreamer plugins bad
    gstreamer plugins ugly
    gstreamer plugins dev
The only problem in finding those that I had was the dev package. I don't remember seeing the source code on the gstreamer site. This happens to be the package that has the gstreamer-app and gstreamer-video libraries. Without these, cmake will always configure gstreamer as off. I did find the dev package in Ubuntu once before, using apt I beleive...

Looking back over the differences between my Ubuntu install and my Puppy install, it seems that the main difference between the cmake outputs is on the v4l/v4l2 list item.

On Ubuntu I get: V4L/V4L2: 1/1
On Puppy I get: V4L/V4L2: /

This seems to support my theory in that the V4L stuff wasn't done correctly. Maybe the cmake didn't actually find the v4l library...I may try to download the source and compile it myself to see if there is a difference or if something missing...It is possible that both libraries may be needed as well (V4L and V4L2).

I have attached a screen shot from my Ubuntu install showing a working camera program, as well as the cmake output from Ubuntu.

I will be working on the camera stuff off and on throughout the day, so I will make note of any progress or problems to this forum page. If you get anything going or have any ideas, please let me know so I can add it.
Attachments
ubuntu_opencv_cmake_report.txt.tar.gz
This archive includes 2 items:

- screen shot from motion tracking on my Ubuntu install
- cmake output from my Ubuntu Install

It should be noticed that the only considerable difference between this cmake report and the one from both my puppy installs i
(47.54 KiB) Downloaded 724 times

User avatar
jyore
Posts: 43
Joined: Sat 06 Nov 2010, 15:41

#7 Post by jyore »

Update on the video stuff...

I believe the problem is indeed related to V4L/videodev/camera drivers, where:

V4L: video for linux libraries
videodev: video development library module
drivers: I have been trying to use the uvc drivers

What I have found is that I can get a videofeed when I run ucview. However, when I try to use xawtv or other programs/methods (including OpenCV), there is a failure to grab images from the camera.

The errors are all IOCTL errors.


I am pretty sure that the OpenCV library isn't opening the video feed because of the same IOCTL errors. The curious part is that when Cmale runs to configure the install, it does not detect the videodev.h/videodev2.h, even though they are present at the directory where Cmake is looking. My guess is that there are some hidden dependencies that OpenCV needs in addition to just the library.

I am looking more into this now.

Btw, I have added a couple more libraries, and it is recognizing that I have V4L, but not V4L2. The camera I have might be a V4L2 device, which could be the real issue. I am going to be looking for every possible library that deals with the V4L and install them and see where I get. I will make PETs of each of these libraries so that it will be easier to replicate later.

User avatar
jyore
Posts: 43
Joined: Sat 06 Nov 2010, 15:41

#8 Post by jyore »

AND I GOT IT!!!!

So, I was looking in the cmake output and noticed that there were the lines:

-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - not found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - not found


When in my Ubuntu Install, they were found...hints why I was wondering about the videodev stuff in the first place.

I tracked went to the appropriate directory, and there they were...seems odd that they exist in the correct directory, ucview uses them, cmake reported them missing, and opencv had no video support...certainly odd. But, the videodev libraries do exist, so I figured, let's get hacking.

After running cmake with the appropriate switches, there is a CMakeCache.txt file that is generated. This file has all the switches for what cmake found and didn't find, which is then used in the make/make install process. I went to the lines regarding the videodev files and modified them as shown below:

Was:

Code: Select all

//Have include linux/videodev.h
HAVE_CAMV4L:INTERNAL=
//Have include linux/videodev2.h
HAVE_CAMV4L2:INTERNAL=
Changed to:

Code: Select all

//Have include linux/videodev.h
HAVE_CAMV4L:INTERNAL=1
//Have include linux/videodev2.h
HAVE_CAMV4L2:INTERNAL=1
This basically tells the install scripts that those really do exist and to go ahead and to build the support.

After I installed, I built the samples that use a video camera, and they worked!!!!

I did, however, install a few libraries in the process, so I will add those as optional/unknown dependency in the tutorial (first post). I don't really think that any of them made a difference, so it would be nice if someone could verify. I will also add the CMakeCache hack into the tutorial as well.

Enjoy, and here is a screen shot of opencv's motion tracking sample working in puppy. (screen shot from same program as the Ubuntu post)

User avatar
swindler
Posts: 5
Joined: Thu 15 Oct 2009, 23:57

#9 Post by swindler »

after much monkeying around, (copying libs, trying various pets, etc.), I think I almost had it working but something made puppy freeze up on me. So I'm starting over with a fresh frugal install of 431, gonna flesh out this howto.

using all the pets above, with the CMakeCache.txt edits, 'make' stops at:

Code: Select all

[89%] Building CXX object apps/haartraining/CMakeFiles/createsamples.dir/createsamples
Linking CXX executable ../../bin/opencv_createsamples
/usr/lib/gcc/i486-t2-linux-gnu/4.2.2/../../../libgtk-x11-2.0.so:undefined reference to 'g_array_get_element_size'
/usr/lib/gcc/i486-t2-linux-gnu/4.2.2/../../../libgtk-x11-2.0.so:undefined reference to 'g_array_unref'
/usr/lib/gcc/i486-t2-linux-gnu/4.2.2/../../../libgtk-x11-2.0.so:undefined reference to 'g_mapped_file_unref'
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_createsamples] Error 1
make[1]: *** [apps/haartraining/CMakeFiles/createsamples.dir/all] Error 2
make: *** [all] Error 2

my guesses are:
1) there's some dependency we don't have yet (or it's the wrong version?)
2) something's in the wrong place (or hasn't gotten linked properly)

think you can track this down before I do? :wink:

User avatar
swindler
Posts: 5
Joined: Thu 15 Oct 2009, 23:57

#10 Post by swindler »

well, that was easier than I thought. The problem was with gtk+-2.18 and its DEV package. don't know what the problem was, but
opencv compiled right up when I switched them for:

gtk+-2.14.7-1-p4.pet
and
gtk+_DEV-2.14.7-1-p4.pet


(from that page of pets in the first post)
I'll also confirm that the edits to CMakeCache.txt lets opencv read from my webcam. so ... well done, jyore.

now to learn how to use this thing. :D

User avatar
jyore
Posts: 43
Joined: Sat 06 Nov 2010, 15:41

#11 Post by jyore »

Thanks for testing everything out. I added your notes on the gtk packages into the original post so that others can see it. Also, I added you to the verifications section.

Thanks again for helping with the verification. Let me know if you come across any problems.

A good place to start learning is to find some of the sample programs and go through them and pick out the useful bits for your application.

Enjoy :)

astha.aggarwal
Posts: 1
Joined: Fri 26 Nov 2010, 05:22

Not able to use cross compiled OpenCV with all webcam device

#12 Post by astha.aggarwal »

Hi,

I cross compiled the OpenCV library with arm-linux-gnueabi. and its working fine with microsoft webcam. But its giving error with T-Link webcam.
Error is "HIGHGUI ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV Unable to stop the stream.: Bad file descriptor"

What can be the reson? Or i did some mistake while cross compiling the lib and need to do some changes in CMakeCache.cmake file?and how to rectify it?

I disabled the ffmpeg as i need to capture the image only not the videos.
//Include FFMPEG support
WITH_FFMPEG:BOOL=OFF

User avatar
jyore
Posts: 43
Joined: Sat 06 Nov 2010, 15:41

#13 Post by jyore »

astha.aggarwal...which version of Puppy are you using? If you are not using Puppy, then I will still try to answer your question, even though this forum is specifically for Puppy Linux users...

I personally have not seen the error you are getting, but it seems to be some incompatibility with the V4L2 drivers and that specific camera. Do you know what drivers the camera that does not work uses on Linux systems? The Microsoft cams use the UVC drivers, which I know work with OpenCV and Linux. Also, does that camera work with other applications like ucview, mplayer, any vlc application, skype, etc?

I do not think it is the OpenCV install since it worked with the one camera.[/quote]

cannot
Posts: 2
Joined: Thu 03 May 2012, 15:11

#14 Post by cannot »

Hi! Thanks for the detailed description!! Very handy...

I'm going to install opencv on puppy, do you think your process will work smoothly on puppy 528?

ciao,
pedro

Post Reply