Wednesday, August 26, 2009

Ubuntu OpenCV FFMPEG error

If you are in Ubuntu 9.04 and attempting to write a video using OpenCV you may encounter an error such as:

OpenCV Error: Bad argument (codec not found) in CvVideoWriter_FFMPEG::open

The only solution that I have found is to install the following
sudo apt-get install libavcodec-unstripped-52

It seems to remove a bunch of packages but everything I do (reading/writing videos) seems to be working. So proceed with caution on installing this, but it may fix what ails you.

Working with gtkmm - A basic intro

I am not attempting to know everything about gtkmm or post an exhaustive tutorial on it. However if you would like to create a basic GUI in a relatively short period of time then you have come to the right place.

Here is a link to a more exhaustive tutorial (where I learned myself):Programming with gtkmm

Also visit this link which has detailed information on each class/namespace/file:
gtkmm 2.4 Documentation

Quick Introduction:

Abstract:
This tutorial covers how to create a GUI including one button arranged within a single frame. In another post I will eventually cover the basics of how to create a "more" section (i.e. hidden widgets). This is a very basic GUI that simply allows you to run commands depending on the callback of the button.

Idea:
The basic idea of gtkmm (GTK in general) is to create a gui where all elements are relative in position and size (for the most part). Each element is considered a widget and the things that hold it, containers. Elements are typically considered children, and containers parent(s).

Main.h
Add:
#include 
#include "gui.h"


Main.cpp
Add:
Gtk::Main kit(argc,argv);
gui gui;
Gtk::Main::run(gui);


gui.h
Add:
class gui : public Gtk::Window
{
public:
gui();
virtual ~gui();

protected:
//Signal handlers:
virtual void on_button_clicked();

//WINDOW - Child widgets
Gtk::Frame window_frame;
Gtk::VBox window_box;
Gtk::Button window_button,

gui.cpp
Add:
// Sets the Window Title
set_title("Window Title");

// Sets the border width of the window
set_border_width(10);

// Add the box to the window (the window can contain one widget/container)
add(window_box);

// Add the frame to the box (boxes can contain multiple widgets/containers)
window_box.pack_start(window_frame);

// Label the frame
window_frame.set_label("Main");

// Add a button to the frame (frames can contain one widget/container)
window_frame.add(button);

// This is how you do a call back (to a function where you define whatever you want)
button.signal_clicked().connect(sigc::mem_fun(*this,
&gui::on_button_clicked));


That's it. Just define your on_button_clicked() function and you are all set to make a simple GUI.

How to post code on your blog

I was unaware of how to do this and did some searching online. There are many ways of doing it. The following blog has a great way to do it and the directions are very clear and to the point.

Vivian's Tech Blog - How to post source code in blogspot.com

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.

Welcome

Welcome to the Reyco Technologies blog! I will be posting various articles that will first and foremost be related to my thesis and then various other techy articles when I learn/find something new.