Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Tuesday, January 5, 2010

OpenCV libcv.so.2.0 error

Sometimes after a fresh install of OpenCV in a fresh install of Linux you may come across the error:

error while loading shared libraries: libcv.so.2.0: cannot open shared object file: No such file or directory


If you do then follow the instructions provided by an OpenCV thread on nabble.com. Click here

Wednesday, October 28, 2009

Gnuplot - Simple Tutorial

There are a ton of tutorials on how to use gnuplot, but most can be convoluted. Here is a simple example/tutorial for gnuplot.

1. Put data in a file (e.g. plot1.dat).  X-axis data followed by a space and Y-axis data

1 23.8
2 23.8
3 23.8
4 23.8
5 23.75
6 23.75
6.5 24.15
6.75 24.45
7 24.95
7.25 25.15
7.5 25.30
7.75 25.40
9 25.70
10 25.83
11 25.88
12 25.89
13 25.90
14 25.90

2. Put the setup commands in another file (e.g. plot1.setup)

# Basics
unset log
unset label
unset arrow
set xtic auto 
set ytic auto 
set autoscale

# Title Information
set title "Temperature vs. Time - Trial 1"
set xlabel "Time (min)"
set ylabel "Temperature (celsius)"

# Initial Point (1,23.80)
set label "i" at 2,24.8 font "Arial,25" offset 1
set arrow from 2,24.80 to 1,23.80

# Final Point (14,25.90)
set label "f" at 13,24.90 font "Arial,25" offset 1
set arrow from 13,24.90 to 14,25.90

# Time fired (6,23.75)
set label "a" at 6,24.75 font "Arial,25" offset 1
set arrow from 6,24.75 to 6,23.75

# Temp reaches 60% (7.1,25.04)
set label "b" at 8.1,25.04 font "Arial,25" offset 1
set arrow from 8.1,25.04 to 7.1,25.04

# Max Temp (13,25.90)
set label "c" at 12,24.90 font "Arial,25" offset 1
set arrow from 12,24.90 to 13,25.90

# Make the plot
plot "plot1.dat" with linespoints

3. Run the following command
   a. gnuplot -persist -raise plot1.setup

Thursday, September 24, 2009

Some Interesting Bash Functions

In Linux there is a type of scripting that can be done in the Bash shell.  This is a very powerful feature of Linux, as Bash offers many advanced features.  This blog will show some of the features I have learned.  I will not attempt to cover a tutorial but rather varying functions that I have found useful.

IFS
   One of the interesting things that I have learned is the usage of IFS.  According to wikipedia it stands for Internal Field Separator.  What it does is allow you to define what Bash defines as a separator.  Bash defaults to space as the separator, therefore functions that utilize IFS will separate items based on spaces.

  While scripting you might want to change this.  Maybe a comma or a new line will be what is wanted.  Here is an example that sets the value to a new line and then back to the default.


#set IFS to be a new line
IFS="
"
#set IFS to be a space
IFS=" " 

Checking Arguments
  When you are implementing a bash script you can pass in arguments to the program.  Each argument is listed as $(value) where value ranges from 0 on up.  $0 is your program, $1 is the first passed in argument, etc.

Now what we want to do is check how many the user input.  Maybe we only want 2 values to be input, so we should check that.  Here is an example that checks for 2 inputs.


if [ $# -ne 2 ]; then
  echo "You did not input 2 arguments, try again!"
  exit
fi

Iterate Through all Files in CWD
  Sometimes it is necessary to iterate through all files in a certain directory.  There are a few ways to do this, but if you are dealing with files that may have spaces in them, the best way is the following.


for file in `ls -A $src`; do 
  sourceFile="$src/$file"
  # Now do what you want it to do with each source file
done


* Note: In the above example you will note $src, this is the full length path where you are searching files.  This can be a hard coded variable or possibly an argument to your function.

* Note: Whenever you reference sourceFile make sure to use quotes

Checking for Certain Things
  When you are coding you might want to check what something is.  Here are a few ways to check.

Checking that a directory exists

if [ ! -d "$dir" ]; then
  #do something since the directory does not exist
fi

Checking for a regular file

if [ -f "$file" ]; then
  #do something since it is a normal file
fi

Checking if file1 is newer than file2

if [ "$file1" -nt "$file2" ]; then
  # file1 is newer, so do something here
fi

Thursday, August 20, 2009

How to Create a GUI with C++ (Linux Edition)

There are 2 main options when creating a GUI in C++ while in Linux. The options are GTK+ or QT.

GTK+

If using GTK+ w/ C++ you will want to see this page.

Ubuntu Install Instructions:
  • sudo apt-get install libgtkmm-2.4-dev
Eclipse Setup Instructions:

Add this line to your code:
  • #include <gtkmm.h>
Add the following to your optimization settings for GCC C++ Compiler
  • `pkg-config gtkmm-2.4 --cflags --libs`
Add the following to your Directories settings for GCC C++ Compiler
  • /usr/lib/gtkmm-2.4
  • /usr/include/gtkmm-2.4
Add the following to your Libraries under GCC ++ Linker
  • Under Libraries (-l):
    gtkmm-2.4
Now if you follow the gtkmm website examples you should be able to run them in eclipse.

Thursday, August 13, 2009

How to download & compile the latest OpenCV

Once you have your environment set up you will be able to download and compile OpenCV to your Linux environment easily. Some Linux distributions are easier than other to setup. Sabayon is one such distro that comes with many of the necessary packages already installed.

Execute the following commands:
  1. mkdir opencv
  2. svn co https://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/trunk opencv
  3. cd opencv/opencv
  4. mkdir release
  5. cd release
  6. sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ../
Now make sure everything worked and was found. If you get errors you need to fix them now or else you will have issues completing a successful install.

Execute the following:

  1. sudo make
  2. sudo make install

If everything goes as planned OpenCV should compile successfully (100% during the make). If not check your libraries and if all else fails try getting the code from the SVN again.

There it is, you have installed OpenCV from source!

Update #1:
   If you receive the error from cxcorr.hpp indicating that ptrdiff_t does not name a type, please add this line of code to cxcorr.hpp (as indicated by stackoverflow.com):

  1. #include <stddef.h>

Setting up Ubuntu for OpenCV

This article relates how to setup a fresh Ubuntu (9.04 - Jaunty Jackalope) so you can download the latest OpenCV from the repository and then compile it from scratch. Downloading and compiling will be a separate article.

First install some packages using the following commands:
sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install mplayer
sudo apt-get install subversion
sudo apt-get install ffmpeg
sudo apt-get install swig
sudo apt-get install python-all
sudo apt-get install python-all-dev
Second install some libraries using the following commands:
sudo apt-get install libxine1
sudo apt-get install libfftw3-3
sudo apt-get install libfftw3-3-dev
sudo apt-get install libfftw3-dev
sudo apt-get install libvorbis-dev
sudo apt-get install libavcodec-dev
sudo apt-get install libavdevice-dev
sudo apt-get install libavfilter-dev
sudo apt-get install libavformat-dev
sudo apt-get install libavutil-dev
sudo apt-get install libmad0
sudo apt-get install libmad0-dev (maybe not necessary)
sudo apt-get install libpostproc-dev
sudo apt-get install libswscale-dev
sudo apt-get install libxine1-ffmpeg
sudo apt-get install libjasper-dev
sudo apt-get install libtiff4-dev
sudo apt-get install libv4l-dev
sudo apt-get install libslang2-dev
sudo apt-get install libxine-dev
sudo apt-get install libdc1394-22-dev
sudo apt-get install libgstreamer0.10-dev
sudo apt-get install libgtk2.0-dev
Now go into Add/Remove Programs
  1. Search for java runtime
  2. Install Sun Java 6 Runtime
*Note: You will want to select All available applications under Show:
Now install unicap

Follow the directions here, then run the following commands:
sudo apt-get install libunicap2
sudo apt-get install libunicap-dev
sudo apt-get install libucil2
sudo apt-get install libucil-dev
sudo apt-get install libunicapgtk2
sudo apt-get install libunicapgtk-dev

* You can also dowloand the tar.gz and compile and make that by hand

* If you are having trouble writing to files with OpenCV after you have installed all the above, please read this link for the fix.