5/31/2015

Setup Opengrok and tomcat on Ubuntu

To install the tomcat 7 you need to run:

  $ sudo apt-get install default-jdk tomcat7
  $ cd /usr/share/tomcat7/bin/
  $ ./catalina.sh

Then edit your ~/.bashrc and include using the directory pointed by CATALINA_BASE include the following var:

  export CATALINA_HOME=/usr/share/tomcat7/
  export OPENGROK_TOMCAT_BASE=$CATALINA_HOME
Run the tomcat and check if it is working:

$ . /etc/init.d/tomcat7
Open web address: http://localhost:8080/
Result on your browser:

Install OpenGrok
First, you need to install the exuberant C tags

$ sudo apt-get install exuberant-ctags openjdk-7-jdk
Download Opengrok binary from the bellow link:
http://opengrok.github.io/OpenGrok/
After download and extract it (E.g. I put it under /home/darrenl/tools/opengrok-0.12.5):

$ tar -zxvf opengrok-0.12.1.5.tar.gz
Second, create a folder and soft link to your code in order to generate index
  • $ cd ~ ; mkdir local_src ; cd local_src/ ; mkdir data src ; cd src/ $ ln -s ~/code/base/mir/ mir
My case (Create soft links from ~/development/android_core, ~/development/caffe, etc..):
  • $ ln -s ~/development/android_core ~/local_src/src/ $ ln -s ~/development/caffe ~/local_src/src/


Third, edit your ~/.bashrc again and paste the bellow text to add the path of OpenGrok binary to path environment var.
  • export OPENGROK_INSTANCE_BASE=~/local_src
  • export PATH=$PATH:~/tools/opengrok-0.12.1.5/bin

In the end, using OpenGrok to deploying, index the source in ~/local/src/
  • $ source ~/.bashrc $ cd ~/tools/opengrok-0.12.1.5/bin; sudo ./OpenGrok deploy $ OpenGrok index You can ingore some files by setting IGNORE_PATTERNS $ IGNORE_PATTERNS="-i *.git -i *.so -i *.apk -i d:.git" OpenGrok index
Run it on browser:
http://localhost:8080/source/

Besides, co-workers can see the code accessing the following addresses: <IP>:<PORT>/source or <hostname>:<PORT>/source

Update index

Whenever you create a link or source files in ~/local_src, you need to call $ OpenGrok index to update. And then refresh your browser screen again (F5).

Run $OpenGrok index on start up:

    $ cd ~/.config/autostart; vi opengrok.desktop
Paste the bellow content to opengrok.desktop and save it. Then, the computer will execute $ OpenGrok index when booting up.

[Desktop Entry]
Name=OpenGrok
GenericName=A fast and usable source code search and cross reference engine
Comment=A fast and usable source code search and cross reference engine
Exec=OpenGrok index
Terminal=false
Type=Application
StartupNotify=false


Note: If your OS is based on Linux, I strongly recommend that you should use Opengrok + Docker.
Please refer to https://hub.docker.com/r/tzutalin/opengrok/









5/13/2015

Using OpenCV with Eclipse

Step1:
Download and install Opencv and Eclipse C++


Step2:
Launch Eclipse and create a C++ project and select Linux GCC

Go to "Properties/C/C++ Build/Settings/"
Select GCC C++ Linker/ Libraries
Paste each of them to "Libraries (-l)"
  opencv_core 
  opencv_highgui 
  opencv_features2d 
  opencv_superres opencv_video 
  opencv_calib3d opencv_flann 
  opencv_videostab 
  opencv_calib3d  
  opencv_objdetect 
  opencv_imgproc

You should check whether your opencv libraray exists in ldconfig by $ sudo ldconfig -v | egrep -i opencv.  If it does not exist in ldconfig, you should paste the specified library path to "Library search path(-L)" as follow:
  /usr/local/lib

If your opencv verison >= 3.0, you can paste them and you have opencv contrib module
  opencv_imgcodecs
  opencv_imgproc
  opencv_highgui
  opencv_ml
  opencv_rgbd
  opencv_core
  opencv_stereo
  opencv_viz
  opencv_video
  opencv_features2d
  opencv_calib3d
  opencv_objdetect
  opencv_flann


Step3:
Select GCC C++ Compiler/includes. You should check whether the header of your opencv. It might be placed in  /usr/include or /usr/local/include. So you can use $ find -iname 'opencv' first. After you find it, paste it to " include path(-l) "
 /usr/include  or /usr/local/include




Step4:
Paste the snippet of the code:

#include <opencv2/opencv.hpp> 
using namespace cv;
int main(int argc, char** argv)
{
    Mat inputImage = imread(argv[1]);
    imshow("Input Image", inputImage);
    waitKey(0);
    return 0;
}

Step5:
Ctrl+B to build it
Run the program using terminal: e.g.: $ ./main ~/lena.jpg

If cannot find opencv_core.xx.so at runtime, please add the bellow cmds to .bashrc
export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib"

Related Reference:


Caffe on Ubuntu / Eclipse C/C++

Purpose

After building Caffe framework, you can use Eclipse to develop and build your own application by including Caffe. Here is an article to teach you how to set up Eclipse for Caffe on Ubuntu14.04 and Eclipse C/C++.

Step 1: 
Open Eclipse, create a C++ project and select Linux GCC toolchains.

Step2:
Go to "properties->C/C++ Build->Settings-> GCC C++ Compiler ->includes" to set Caffe's include path. Add two paths to be included:
   to/your/path/caffe/include
   to/your/path/caffe/distribute/include

Notes: Whenever Caffe releases, need to run all build coomands


Step3:
  Go to "properties->C/C++ Build->Settings-> GCC C++ Linker ->Libraries" to set Caffe's libray path.

Add the bellows to "Library search path(-L)"
     to/your/path/caffe/build/lib

Paste it to " include path(-l) "
     caffe


Step4: (Optional)
Because I didn't use GPU to compute, so I set CPU_ONLY=1 for preprocessor.
 




Step5: 
To let Linker find libcaffe.so , you need to specify libcaffe.so in Properties->C/C++ Build->Setting->GCC C++ Linker->Miscellaneous->Other objects

If you does not want specify libcaffe.so in Eclipse.
You can Set LD_LIBRARY_PATH to ~.bashrc to find libcaffe for linker
$ echo 'export LD_LIBRARY_PATH="to/your/path/caffe/build/lib/"' > ~/.bashrc

In my case:
export LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib:/home/darrenl/developments/caffe/build/lib/"

Step6:
Add a *.cpp file and include caffe.hpp to build.

#include <caffe/caffe.hpp>
using caffe::Blob;
using caffe::Caffe;
using caffe::Datum;
using caffe::Net;
using caffe::shared_ptr;
using caffe::vector;
using caffe::MemoryDataLayer;
int main() {
    Net<float> *caffe_net;
    return 0;
}
You can refer to my source code:
$ git clone https://github.com/tzutalin/caffe_test.git

Build and Run
Build: Project-> Build Project  (ctrl + b)
Run: Run as Local C++ application (ctrl + F11)