Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Sunday, June 4, 2017

Vim - C/C++ style indent

When edit C/C++ file with vim, sometime we have the problem that the close brace "}" cannot be indent correctly.

One solution is to use "=" utility in vim. In the normal mode, we can type gg=G. This will correct the indent issues in the current file. One of the inconvenience of this method is that you need to exit the insert mode and the edit process is interrupted.

Here is another solution. We still leverage the "=" utility in vim. In addition to that, we also need the command gi. it will send the cursor to the position where you were in the insert mode last time.

The full command is something looks like this:

    inoremap } <esc>a } ^]<s-v>=gi^]f}a

The goal is to map } in the insert mode and correct the possible indent issue and then back to the insert mode.

Initially, we are in the insert mode, <esc> let us exit the insert mode. (a }^] is to add an empty space before "}". It is not necessary for the purpose of correcting the indent issue.) <s-v> let us enter the visual mode, = will correct the indent issue of the current line. gi^] send us back to the position where the last edit occurs. f}a find the "}" and put the cursor after "}" and enter the insert mode.


Tuesday, May 30, 2017

Install OpenCV2

Step 1: Install OpenCV software

Follow the following steps mentioned in
https://gist.github.com/dynamicguy/3d1fce8dae65e765f7c4

Here we copy the commands:

# install dependencies
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y cmake
sudo apt-get install -y libgtk2.0-dev
sudo apt-get install -y pkg-config
sudo apt-get install -y python-numpy python-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libjpeg-dev libpng-dev libtiff-dev libjasper-dev

sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils

# download opencv-2.4.11
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.11/opencv-2.4.11.zip
unzip opencv-2.4.11.zip
cd opencv-2.4.11
mkdir release
cd release

# compile and install
cmake -G "Unix Makefiles" -D CMAKE_CXX_COMPILER=/usr/bin/g++ CMAKE_C_COMPILER=/usr/bin/gcc -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D BUILD_FAT_JAVA_LIB=ON -D INSTALL_TO_MANGLED_PATHS=ON -D INSTALL_CREATE_DISTRIB=ON -D INSTALL_TESTS=ON -D ENABLE_FAST_MATH=ON -D WITH_IMAGEIO=ON -D BUILD_SHARED_LIBS=OFF -D WITH_GSTREAMER=ON ..
make all -j4 # 4 cores
sudo make install


We may get some errors when trying to install some of the libraries in command line. Since if highly depends on the system, we cannot give a general solution here. At the same time, many people have experiences the same problems and it is easy to find the solution through Google.

Step 2: Add Include path and Libraries.

If everything works, now we should have opencv2 installed. The next step is to configure our IDE. In my case, I use the eclipse. The instruction can be found here:
http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_eclipse/linux_eclipse.html



Step 3: Test OpenCV

In this step, we use the first code example in the book Learning OpenCV (https://www.amazon.com/Learning-OpenCV-Computer-Vision-Library/dp/0596516134).

#include "highgui/highgui_c.h" // In the book, we have     
                               // #include "highgui.h"
                               // which is used in the old
                               // version of OpenCV


int main()
{
    IplImage* img = cvLoadImage(  "path-of-an-image-file"  );
    cvNamedWindow(  "Example1", CV_WINDOW_AUTOSIZE  );
    cvShowImage(  "Example1", img  );
    cvWaitKey( 0 );
    cvReleaseImage(  &img  );
    cvDestroyWindow(  "Example1"  );
 }


If we can see a new window of image pop up, we are all good.

Saturday, November 29, 2014

How to add application to the launcher in Ubuntu





To add application to the launcher in Ubuntu, we need create a .desktop file in the /usr/share/applications

The .desktop file has the following format:



[Desktop Entry]
Name=pyCharm
Type=Application
Exec=/home/username/Programs/pyCharm/pycharm-community-3.4.1/bin/pycharm.sh
Terminal=false
Icon=/home/username/Programs/pyCharm/pycharm-community-3.4.1/bin/pycharm.png
NoDisplay=false
Categories=Development;IDE
Name[en]=pyCharm





Wednesday, November 19, 2014

Install Java7, Java8 and Javaplugin for firefox in Ubuntu


The methods mentioned here have been tested. (11/19/2014)




Install Oracle Java7 in Ubuntu


sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

see : http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html








Install Java8 in Ubuntu


1. download jdk file
2. decompress the file tar xvzf jdk1.8*.tar.gz
3. relocate JDK 8: mv jkd1.8* / usr/lib/jvm
4. Install Oracle Java JDK 8
    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8*/bin/java 1065
    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8*/bin/javac 1065
    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8*/bin/jar 1065
    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8*/bin/javaws 1065
5. check or set the system java version in Use with: 

    sudo update-alternatives --config java

see : http://tutorialforlinux.com/2014/03/15/how-to-install-oracle-jdk-8-on-ubuntu-12-04-precise-lts-32-64bit-easy-guide/





Install Java plugin in Firefox


;;; install the Icedtea plugin
sudo apt-get install icedtea-plugin

;;; create a symbolic link
ln -s /usr/lib/jvm/jre1.7.0/lib/amd64/libnpjp2.so ~/.mozilla/plugins/

alternatively, one may find the plugins directory  in /usr/lib/mozilla

see : http://askubuntu.com/questions/354361/how-to-install-java-plugin-in-firefox