Thursday, July 31, 2014

OpenCV Linux Install

Follow this step:

https://help.ubuntu.com/community/OpenCV

Remember to make sure CheckInstall is installed.

In code block project, include the header:

/usr/local/include

include the library:

/usr/local/lib/libopencv_core.so
/usr/local/lib/libopencv_highgui.so

include files:

#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"

c++ read file

 string line;  
 while(getline(myfile,line))  
 {  
     istringstream is(line);  
     vector<double> tmp(3);  
     is>>tmp[0]>>tmp[1]>>tmp[2];  
     pts.push_back(tmp);  
  }  

Friday, July 25, 2014

[Linux] Linux Tips

1.  how to open file from terminal?

Suppose you have installed Geany.

Then go to the folder and type "geany xxx.txt"

2. how to show hidden files?

ctrl+H

3. open terminal from here:

You have to install the Install nautilus-open-terminalnautilus-open-terminal package :
sudo apt-get install nautilus-open-terminal
Then:
nautilus -q
in order to reset Nautilus

4. Open a directory window

nautilus /path/to/open

5. start a program without blocking

emacs ....txt &

Wednesday, July 23, 2014

Git Merge

Recently I had a problem when using git.

The thing is that I tend to learn something only when I need it. So I know the basic functionality of git. It works quite well for me.

The problem came when I modified a file, and before committing it, that file is already updated by my friend. This is hard feeling for computer I guess, since he would not know which version to keep if I want to commit my change.

But I don't want my change in that file. However I am not able to commit other changes, nor can I pull or push. I solved this by doing the following things:

git checkout source_branch(usually it's master) filepath (check this out will update the file I modified to match the version in the index tree)

git reset filepath

git add -p filepath

git commit -m "merge the changes"

Update: use this one: git checkout master .

An example of using PCL

 #include <pcl/visualization/cloud_viewer.h>  
 #include <iostream>  
 #include <pcl/io/io.h>  
 #include <pcl/io/pcd_io.h>  
 #include <fstream>  
 #include <sstream>  
 #include <string>  
 #include<vector>  
 using namespace std;  
 using namespace pcl;  
 int main()  
 {  
   ifstream myfile("lasercam_000200.txt");  
   vector<vector<double> > pts;  
   string line;  
   int ptNum1=0;  
   while(getline(myfile,line))  
   {  
     istringstream is(line);  
     vector<double> tmp(3);  
     is>>tmp[0]>>tmp[1]>>tmp[2];  
     pts.push_back(tmp);  
     ptNum1++;  
   }  
   myfile.close();  
   ifstream myfile2("raytrace_000200.txt");  
   while(getline(myfile2,line))  
   {  
     istringstream is(line);  
     vector<double> tmp(3);  
     is>>tmp[0]>>tmp[1]>>tmp[2];  
     pts.push_back(tmp);  
   }  
   myfile2.close();  
   cout<<pts.size()<<endl;  
   pcl::PointCloud<pcl::PointXYZRGB> cloud;  
   cloud.is_dense = true;  
   cloud.points.resize (pts.size());  
   for (size_t i = 0; i < cloud.points.size (); ++i)  
   {  
     cloud.points[i].x = pts[i][0];  
     cloud.points[i].y = pts[i][1];  
     cloud.points[i].z = pts[i][2];  
     uint8_t r,g,b;  
     if(i<ptNum1)  
     {  
       r=255;  
       g=0;  
       b=0;  
     }  
     else  
     {  
       r=255;  
       g=255;  
       b=255;  
     }  
     uint32_t rgb = ((uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b);  
     cloud.points[i].rgb=*reinterpret_cast<float*>(&rgb);  
   }  
   pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer");  
   pcl::PointCloud<pcl::PointXYZRGB>::Ptr ptrCloud(&cloud);  
   viewer.showCloud (ptrCloud);  
   while (!viewer.wasStopped ())  
   {  
   }  
   return (0);  
 }  

Tuesday, July 22, 2014

Install PCL in Linux

The bottom line is that in order to install pcl, you have to install boost

The command for boost installation is:

sudo apt-get install libboost-all-dev
 
The lib files can usually be found at:
 
 /usr/lib or usr/lib/x86_64-linux-gpu

After that, you can install PCL,

the command is (assume its ubuntu)

sudo add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
sudo apt-get update
sudo apt-get install libpcl-all
  
 
Then, suppose you are using codeblock

You need to add search directories of include (under global compiler settings):

/usr/include/pcl-1.7
/usr/include/pcl-1.7/pcl/surface
/usr/include/eigen3
/usr/include/vtk-5.8

and add link libraries (under linker settings):

/usr/lib/libvtk*
/usr/lib/x86_64-linux-gnu/libpthread.so
/usr/lib/x86_64-linux-gnu/libboost_thread.so
/usr/lib/libpcl*
/usr/lib/x86_64-linux-gnu/libboost_system.so

Thursday, July 17, 2014

SSH and SCP

To SSH a remote machine, use the following command:

ssh username@xxx.xxxxxx.edu

To SCP a file or folder from remote to local, use the following command

scp -r(for folder) username@xxx.xxxxxx.edu:filename/foldername .(local current folder)

 To scp from local to remote, use the following command:

scp runstereoflow username@xxx.xxxxxx.edu:/home-XXX/XXXXXX

Wednesday, July 16, 2014

Bitbucket Linux Setup and Usage 5 min Tutorial

1. First you need to set up your git locally using the following command if you have not done so:

sudo apt-get install git
$which git (to see if it is installed)
git config --global user.name "FIRST_NAME LAST_NAME"
git config --global user.email "MY_NAME@example.com"

2. Then you need to create a git repository. If you already have it or you are joining someone else' repository, skip to step 3:

click create button at the top of the bit bucket page.

3. Clone your repository to local system:

mkdir /path/to/your/project
cd /path/to/your/project

git init      (initialize your repository locally)
git remote add origin https://xxxxxx@bitbucket.org/xxxxx/sgmstereoflow.git      (connect your repository with bitbucket)
git pull     (pull files from remote repository, if it is a new one you don't need to do that)

4. Every time you made a change or want to add some code,  do the following:

git add .    (add all local existing files)
git commit -m 'Initial commit with contributors'    (commit the change with a message)
git push -u origin master  (push the change back to the repository)

5. You can view the commit history, revert to a previous commit, modify readme, update wiki in bitbucket repositories.

Monday, July 14, 2014

Another linux script

 #this file is to execute the stereo flow algorithm on multiple files in a folder  
 #the format of the image name should be six-digit numbers.  
 if test $# -lt 5 ; then  
      echo "usage: stereoflowbatch left_image_folder right_image_folder calibration_file start_id end_id"  
 else  
      for ((i=$4;i<=$5;i++))   
      do  
           lin=$(printf %06d.png ${i%.png})  
           flin="$1/$lin"  
           frin="$2/$lin"  
           j=`expr $i + 1`  
           lin2=$(printf %06d.png ${j%.png})  
           flin2="$1/$lin2"  
           echo $flin  
           echo $frin  
           echo $flin2  
           if [ -f $flin ] && [ -f $frin ] && [ -f $flin2 ]; then  
                ./runstereoflow $flin $frin $flin2 $3  
           fi  
      done       
 fi  

Sunday, July 13, 2014

Ubuntu terminal root

sudo -s

A simple script

 # This script is written to combine all the commands of sgm stereo flow. We need extensions such as .png.  
 if test $# -lt 4 ; then  
   echo "Usage: runstereoflow left_image_t0 right_image_t0 left_image_t1 calibration"  
 else  
   echo "running stereo"  
   ./sgmstereo $1 $2  
   echo "estimating fundamental matrix"  
   ./siftfund $1 $3  
   echo "running flow"  
   l=$1  
   ln=${l%.*}  
   f="_fund.dat"  
   fn=$ln$f  
   ./sgmflow -i $1 $3 $4 $fn  
   echo "estimating alpha"  
   ld="_left_disparity.png"  
   lld=$ln$ld  
   lf="_flow.png"  
   llf=$ln$lf  
   m="_mot.dat"  
   lm=$ln$m  
   ./estalpha $lld $llf $4 $fn $lm  
   echo "running stereo flow"  
   ./sgmstereoflow $1 $2 $3 $lld $llf $lm  
   echo "running smooth fit"  
   ./smoothfit $1 $lld $lm  
 fi  

Friday, July 11, 2014

Simple VIM Tutorial

Run VIM, you cannot edit directly.

Press "I" then you go into insert mode, where you can start input.

Press ESC, then you are back to command mode.

In command mode, write :w filename, then it will save

:w! overwrite
:wq quit without save.
:edit path (edit file)

Thursday, July 10, 2014

How do I run cmakelist under ubuntu

First you need to install cmake, cmake build, cmake gui, and probably codeblock. Then u can use cmake gui to generate build files for code block, and it is all set