Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, July 2, 2013

Command line tips


The intention of this post is to collect a list of my favorite command line tips. Feel free to leave yours in the comment section.

  • Instead of using clear you can just press ctrl-r.
  • The command units can be used for any unit conversion you can imagine. See man page.
  • You can use multitail to monitor multiple log files on a terminal.

Sources:

Saturday, June 22, 2013

Extract decimals from text using grep

Let's say you have a log file that looks like this:
I/Profiling: TimeInterval1:  3271.72 ms
I/Profiling: TimeInterval1:  3379.15 ms
I/Profiling: TimeInterval1:  3645.32 ms
...
and you want to extract all decimal numbers so that you can get the average, or plot them. Here's how you would use grep to do this:
grep -o ' [0-9]\+\.[0-9]\+' mylogfile.log
The -o option is for just printing the matching text and not the whole line.

Friday, April 5, 2013

Simple HTTP Server in Python

A very easy way to setup a simple HTTP server is by using this built-in Python capability. This will turn any directory into a web server directory. The only thing you have to do is run:
python -m SimpleHTTPServer
on the directory you want to host the files from and that's it. You can drop an index.html file in there, for example, and hit
http://127.0.0.1:8000
in your browser and voila!

Thursday, December 13, 2012

Ogre3D Object Placement Utility


I wrote an open source object placement utility that allows for placing objects (trees) on a terrain using the mouse.


It consists of a terrain and a water surface (pond). The user can select from 3 different models of trees and place them on the terrain. You enter edit mode by pressing space and a toolbar with all available models appears on the left side of the screen. The toolbar can easily be extended with more models.

I hope people will find it useful for object placement in scenes or using it as a base for terrain editors and such.

The build system is currently for Linux only (cmake and make) but it should be easy to compile in Windows or MacOS. The code is not perfect so any comments and suggestions are welcome.


Here is a demo:


Links
Souce code on GitHub
Object Placement Utility at Ogre3D Forums

Wednesday, May 16, 2012

OpenCV 2.4 on Ubuntu 12.04

Edit (August 2013): Just used these steps to install OpenCV 2.4.6.1 on Ubuntu 12.10 without problems.

OpenCV 2.4.0 was released on May 2012 providing, a lot of improvements and bug fixes. For a complete change log see here.

This post will hopefully make your life easier to configure, compile, install and test it out.

This time I tried to categorize and explain the dependencies, so that it is easier to configure it for your needs. As always, comments and suggestions are welcome.

Ubuntu 12.04 provides a package of OpenCV 2.3.1 that you can easily install by typing:
sudo apt-get install libopencv-dev
If you do not care about having the latest version you could skip the rest of the post.

Install Dependencies


Essentials
These are libraries and tools required by OpenCV.
sudo apt-get install build-essential checkinstall cmake pkg-config yasm

Image I/O
Libraries for reading and writing various image types. If you do not install then the versions supplied by OpenCV will be used.
sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev


Video I/O
You need some or all of these packages to add video capturing/encoding/decoding capabilities to the highgui module.
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev

Python
Packages needed to build the Python wrappers.
sudo apt-get install python-dev python-numpy

Other third-party libraries
Install Intel TBB to enable parallel code in OpenCV.
sudo apt-get install libtbb-dev

GUI
The default back-end for highgui in Linux is GTK. You can optionally install QT instead of GTK and later enable it in the configuration (see next section). 
sudo apt-get install libqt4-dev libgtk2.0-dev

Compile and Install

Get a copy of the source code here, extract and create a build directory:
tar -xvf OpenCV-2.4.0.tar.bz2
cd OpenCV-2.4.0/
mkdir build
cd build
Configure using CMake. You have a lot of options in this step. This is what I use:
cmake -D WITH_QT=ON -D WITH_XINE=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON ..
Notice, that by adding the -D WITH_QT=ON, the highgui module will use QT instead of GTK. If you want to go with GTK just remove this. For more information on the options, look at the CMakeLists.txt file. When you are happy with the configuration you have, you can start compiling:
make
If compilation finishes without errors, you can install by saying:
sudo make install
Finally, make sure that your programs can link to the OpenCV library in run-time by adding the following line at the end of your /etc/ld.so.conf:
/usr/local/lib
And then configure dynamic linker run-time bindings:
sudo ldconfig

Testing

An easy way to test that the compilation went well is to use the OpenCV test utilities. For example, to test the core module go to OpenCV-2.4.0/build/bin and run:
 ./opencv_test_core
You should see something like that:


Note that some failures when testing other modules may come from missing image files. To correctly run these tests or samples you should move the corresponding image files from OpenCV-2.4.0/samples to OpenCV-2.4.0/build/bin.

For testing that you can compile your own programs and link against the installed OpenCV libraries I have packaged the face detection sample with all the necessary files and a simple Makefile. Download it here, extract and type:
make
This should compile and run with a test image, so you should see something like this:



Monday, September 26, 2011

How to install CUDA 4.0 on Ubuntu 10.10 or later

First, you need to install the NVIDIA development drivers. Download the current version (270.41.19) here.
To install the dev drivers, reboot and go into recovery mode. Select the "Drop to root shell prompt" option. Now type:
sudo telinit 3
Login again using your username, then cd to the directory where you downloaded the drivers (e.g. ~/Downloads):
cd ~/Downloads
chmod u+x devdriver_4.0_linux_64_270.41.19.run
sudo ./devdriver_4.0_linux_64_270.41.19.run
Follow the instructions on the screen. Make sure you write to your xorg.conf file. When done reboot:
sudo reboot
Download the CUDA Toolkit from this page (Linux -> CUDA Toolkit for Ubuntu Linux 10.10).
cd ~/Downloads
chmod u+x cudatoolkit_4.0.17_linux_64_ubuntu10.10.run
sudo ./cudatoolkit_4.0.17_linux_64_ubuntu10.10.run
Finally, download the GPU Computing SDK from the above website.
cd ~/Downloads
chmod u+x gpucomputingsdk_4.0.17_linux
./gpucomputingsdk_4.0.17_linux
Add the these lines at the end of your ~/.profile (if your OS is 32-bit, remove the lib64 entry):
#CUDA stuff
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Now you just need to compile the samples. Assuming you installed the SDK in your home directory:
cd ~/NVIDIA_GPU_Computing_SDK
make
You can now run one of the demos, e.g. the particle demo
~/NVIDIA_GPU_Computing_SDK/C/bin/linux/release/particles
and you should see something like this:


Thursday, June 2, 2011

Install Ubuntu Tweak on Ubuntu 10.10

Open a terminal and type:
sudo add-apt-repository ppa:tualatrix/ppa
sudo apt-get update
sudo apt-get install ubuntu-tweak

Saturday, May 28, 2011

Install and Configure Tomcat6 on Ubuntu Linux

Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies.

The Java Servlet and JavaServer Pages specifications are developed under the Java Community Process.

Part 1
First, install tomcat6:
sudo apt-get install tomcat6 tomcat6-docs tomcat6-examples tomcat6-admin

Then configure a user to be manager and admin by adding the following lines
  <role rolename="admin"/>
  <role rolename="manager"/>
  <user username="YOURUSERNAME" password="YOURPASSWORD" roles="admin,manager"/>
in your /var/lib/tomcat6/conf/tomcat-users.xml. Make sure you put it between the <tomcat-users> and </tomcat-users> tags and don't forget to replace YOURUSERNAME with your actual username.
Now go to a browser and hit:
http://localhost:8080/
and you should see the welcome page.

Part 2
To restart tomcat you just need to say:
sudo /etc/init.d/tomcat6 restart
or if you want to start/stop/get status you just replace restart with start/stop/status.
To make this easier go to a terminal and type:
gedit tomcat
then add the following lines of text:
#!/bin/bash

/etc/init.d/tomcat6 $1
then save and close and type:
chmod u+x tomcat
sudo mv tomcat /usr/local/bin
so if you want to stop tomcat you can now say:
sudo tomcat stop
Let's add auto-completion to our new command now. Open a terminal and type:
gedit tomcat
then copy paste the following
_tomcat() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="start stop restart status"

    if [[ ${cur} == * ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _tomcat tomcat
save and close gedit. Now type:
sudo mv tomcat /etc/bash_completion.d
You need to restart for this to take effect, but if you want to test it right away type:
. /etc/bash_completion.d/tomcat
Then as an example, type:
sudo tomcat re
and hit tab a couple of times. It should complete the word restart for you since it's the only valid option that begins with "re".

Thursday, May 19, 2011

Install Sun Java JDK in Ubuntu 10.10

To install Sun's Java 6 JDK on Ubuntu 10.10, add the Sun Java6 Community PPA and install:
sudo add-apt-repository ppa:sun-java-community-team/sun-java6
sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-plugin
sudo update-java-alternatives -s java-6-sun

Thursday, April 7, 2011

GRUB 2 Splash Images on Ubuntu


Here is how you can get a nice background image for GRUB boot menu.
First, install the "grub2-splashimages" package:
sudo apt-get install grub2-splashimages
Then edit /etc/default/grub and add the following line
GRUB_BACKGROUND=/usr/share/images/grub/yourImage.png
Also, make sure that GRUB is loaded in the same resolution as the image
GRUB_GFXMODE=1680x1050
...and that's it. Update GRUB
sudo update-grub
and restart to see the results.

Wednesday, April 6, 2011

How to delete all .svn directories

If you are using subversion, at some point you probably tried to take some folders from one repository and try to commit then to another. Since each folder has a hidden .svn folder, subversion will complain that "they are already under version control". Here is how to recursively delete all .svn folders:

find . -name ".svn" -type d -exec rm -rf {} \; -prune -print

Friday, February 25, 2011

Copy Paste between Emacs and other applications

If you are using GNU Emacs in an X-windows environment like Gnome, you would have noticed that sometimes copy-pasting from Emacs to other applications or vice versa does not work.
To fix this, edit your .emacs file (located in your home folder) and add the following lines:
;; Send primary selection to clipboard so copy-paste works with other X-applications
(global-set-key "\C-w" 'clipboard-kill-region)
(global-set-key "\M-w" 'clipboard-kill-ring-save)
(global-set-key "\C-y" 'clipboard-yank)

OpenCV 2.2 on Ubuntu 10.10


*Update: For OpenCV 2.4 on Ubuntu 12.04 see my latest post.

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. It is released under a BSD license, it is free for both academic and commercial use. It has C++, C, Python and soon Java interfaces running on Windows, Linux, Android and Mac.

This is how to build and install OpenCV 2.2 on Ubuntu 10.10.

First, install the dependencies from the repositories:
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev
Download the source code:
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.2/OpenCV-2.2.0.tar.bz2
Extract, create the build directory:
tar xfv OpenCV-2.2.0.tar.bz2
rm OpenCV-2.2.0.tar.bz2
cd OpenCV-2.2.0
mkdir opencv.build
cd opencv.build
Configure, make and install:
cmake ..
make
sudo make install
To configure the library, edit the following file (might be empty):
sudo gedit /etc/ld.so.conf.d/opencv.conf
and add the line
/usr/local/lib
Then run:
sudo ldconfig
Finally, edit the file:
sudo gedit /etc/bash.bashrc
and add the following lines at the end:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
Most of the above was find here.

Older versions? Take a look at the following links:

OpenCV 2.1 on Ubuntu 10.04 (pretty much the same as above, but with TBB)
OpenCV 2.0 on Ubuntu 9.10

For OpenCV 2.3.1 see this post.

Saturday, February 19, 2011

Completely Disable Touchpad in Ubuntu

To temporarily disable the touchpad while typing just go to
System > Preferences > Touchpad
and check
Disable touchpad while typing
but if you want to completely disable it, you can do the following
In a terminal type:
xinput list | grep -i touchpad
to determine the device ID (in my case, 14). Then disable by typing:
xinput set-prop 14 "Device Enabled" 0
To enable it, type:
xinput set-prop 14 "Device Enabled" 1

From the Ubuntu Documentation: Synaptics Touchpad

Tuesday, February 15, 2011

Ogre3D Applications and Emacs

This is the first application of the Ogre3D tutorial, set up for compiling by calling
make -k
from Emacs. This is useful when you have a shortcut for M-x compile say, F1, so you want to be able to call make from the directory where all your source files are located. The Makefile in the root directory just removes old cmake files, then runs cmake inside build directory and creates the Makefile to build the project. Then builds and executes.

  • Cmake output is redirected to the file /build/cmake.output
  • The executable (OgreApp) is located in build/dist/build
  • The execution log is in build/dist/bin/OgreApp.log
Now you can edit the source files of your Ogre3D application, then hit F1 (or whatever key you've assigned compile to) and build/execute by just pressing one key.

You can download all files from here.

Friday, January 28, 2011

Command Line Shortcuts




I was reading this post today on how to become a command line ninja and here is some interesting stuff I learned:
  • Ctrl+U: This clears the entire line so you can type in a completely new command.
  • Ctrl+K: This deletes the line from the position of the cursor to the end of the line.
  • Ctrl+W: This deletes the word before the cursor only.
  • Ctrl+R: This lets you search your command history for something specific. For example, if you wanted to search for the recent commands that included nano, you would hit Ctrl+R and type nano. It would show your most recent  command, and you could use the up and down arrows to cycle through your history of commands using nano in them.