Sunday, December 14, 2014

Latex TextBox

 \begin{mdframed}[roundcorner=15pt, frametitle  
 ={Abstract},frametitlerule=true,frametitlebackgroundcolor=brown!30!white,]  
  ...  
 \end{mdframed}   

Thursday, December 4, 2014

The Truth of Being Problematic

There are two categories of students in the world:

"Good students" and "Problematic students".

I have been a good student much of the time, but I am somehow being problematic when I was in Hong Kong.

But I don't think it is a big deal. There are many problematic students (and professors) in MIT and Stanford as of what I know.

Of course I wish I were a Straight-A student which will make my life easier, but being problematic does not mean a straight fail.

Anyway I am back to the Good-Student mode now and I am totally cool about continuing this way for the rest of my life. I guess that's what others say about growing up and being mature. =)

Sunday, November 23, 2014

Torch7 Cheatsheet

1. How to start gfx session:

luajit -lgfx.start

to stop:

luajit -lgfx.stop

2. How to run gfx script:

th -i 1_vis.lua

Thursday, November 20, 2014

Pros and cons for different places to stay

China:

Pro:
Mediocre career path (IT sector).
Good housing and good food.
Close to home.

Con:
Chinese lifestyle.
Not so much freedom.
Chinese mindset everywhere.
Dictatorship. A lot of politics, censorship and restrictions.
Potential bad life quality due to pollution and unsafe food.
Isolated from the world.
Too entertaining. Hardly anyone is serious about anything.

Conclusion: OK to visit for short-term but may not be suitable to stay in the long-term.

US:

Pro:
Good career path (research).
High tech.
Good life quality.
Freedom.
Vast personal space.
Western style and mindset.

Con:
Few connections.
Far from home.
Not so good food.

Conclusion: the learning curve is high but good to stay in the long-term.

HK:

Pro:
Many connections.
Metropolitan lifestyle.
Close to home.
Good food.
Partially western mindset.
Small city. I know everyone. Feel safe.

Con:
Bad career path (if stay in IT sector).
High living cost. Bad housing.
Too materialistic and entertaining.
Crowdy and noisy. Very little personal space.
May easily get bored.

Conclusion: better than China but need sacrifice a lot of things (career interest, life quality). May need to consider other career options.

Conclusions: Both Hong Kong and US look good. But there is a trade-off between short-term benefits and long-term gains.

Monday, November 10, 2014

An Interesting Thread

I decide to write something outside latex, matlab, etc.

Yes I have been using GIMP a lot recently. Changing habit from Photoshop to GIMP takes some learning curve.

The interesting thing is, if you select some region from an image, and want to create a new image with that region (same size), what will you do?

This is the hotkey:

select->Ctrl+new->Ctrl+shift+V

Happy open sourcing.

Tuesday, November 4, 2014

latex include figure

 Method 1
 
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
 
\begin{figure}  
 \centering  
 \begin{subfigure}[b]{0.22\textwidth}  
                      \includegraphics[width=\textwidth]{img/fig1/000254.png}  
         \label{fig:left_img}  
 \end{subfigure}  
 \begin{subfigure}[b]{0.22\textwidth}  
         \includegraphics[width=\textwidth]{img/fig1/000254R.png}  
         \label{fig:right_img}  
 \end{subfigure}  
 \begin{subfigure}[b]{0.45\textwidth}  
         \includegraphics[width=\textwidth]{img/fig1/vel2.png}  
         \label{fig:vel}  
 \end{subfigure} 
 
 Method 2
 
\begin{figure}
\includegraphics[width=1\columnwidth]{img/img5/scenes.png}
\caption{.}
\label{fig:}
\end{figure}

Git Remove and Latex Bibliography

Sometimes you decide to add .gitignore in your git project in the middle, and you need to remove some files.

You can use the following command:

git rm *.aux(or blg/bbl/swp...)

To build bibliography, you need to follow the following steps:

PDFLATEX->BIBTEX->PDFLATEX->PDFLATEX

Tuesday, October 14, 2014

Baby Talk and AI

I am very fascinated by AI recently and can't stop thinking how human can see and understand things and languages.

I quote this from Internet:

Baby Talk Milestones
  • Baby talk at 3 months. At 3 months, your baby listens to your voice, watches your face as you talk, and turns toward other voices, sounds, and music that can be heard around the home. Many infants prefer a woman's voice over a man's. Many also prefer voices and music they heard while they were still in the womb. By the end of three months, babies begin "cooing" -- a happy, gentle, repetitive, sing-song vocalization.
  • Baby talk at 6 months. At 6 months, your baby begins babbling with different sounds. For example, your baby may say "ba-ba" or "da-da." By the end of the sixth or seventh month, babies respond to their own names, recognize their native language, and use their tone of voice to tell you they're happy or upset. Some eager parents interpret a string of "da-da" babbles as their baby's first words -- "daddy!" But babbling at this age is usually still made up of random syllables without real meaning or comprehension.
  • Baby talk at 9 months. After 9 months, babies can understand a few basic words like "no" and "bye-bye." They also may begin to use a wider range of consonant sounds and tones of voice.
  • Baby talk at 12 months. Most babies say a few simple words like "mama" and "dadda" by the end of 12 months -- and now know what they're saying. They respond to -- or at least understand, if not obey -- your short, one-step requests such as, "Please put that down."
  • Baby talk at 18 months. Babies at this age say up to 10 simple words and can point to people, objects, and body parts you name for them. They repeat words or sounds they hear you say, like the last word in a sentence. But they often leave off endings or beginnings of words. For example, they may say "daw" for "dog" or "noo-noo's" for "noodles."
  • Baby talk at 2 years. By age 2, babies string together a few words in short phrases of two to four words, such as "Mommy bye-bye" or "me milk." They're learning that words mean more than objects like "cup" -- they also mean abstract ideas like "mine."
  • Baby talk at 3 years. By the time your baby is age 3, his or her vocabulary expands rapidly, and "make-believe" play spurs an understanding of symbolic and abstract language like "now," feelings like "sad," and spatial concepts like "in."
Below is my own thoughts on AI:
  • We may have an understanding and simulation on how brains work (deep neural network), but we are training it in an imperfect way.  Basically we are just like giving a baby a heavy book of images with strange bounding box and labels and expect him/her to understand the world.
  • One immediate approach may be adding more profound information such as depth, shape, and abstract concepts in mathematics (which is believed to be able to derive from a set of rules), and teach the computer in a way we teach a baby, combining with the way him/her perceives the world (they have two eyes so they always take in stereo pairs).
  • Feature representations are definitely important. Although I believe data-driven is not that important. Imaging TREE. I have seen many trees before, but not all the trees in the world. I also can't exactly recall any tree I have ever seen. All I have is the concept, which is a combination of texture, shape, etc. If you illustrate a tree, I will probably be able to tell it when you are done with the trunk and some leaves (very few drawings are sufficient). You can also give me a very small fraction of the tree by showing me the trunk and its texture and I can probably tell it is part of a tree. So I believe we should take all of these features into account.
  • Structure is not that important. Even if a head is below a body, or a tree is in the sky, I can still tell it is a head or a tree. Also in natural language processing, I doubt anyone will teach a baby how to speak by starting from giving him a set of grammar rules and what is a noun and a verb. 
  • There is still a long way to go before anyone can claim real AI. ImageNet is definitely a good start, but it is just nouns from a dictionary book, and I believe we should combine other abstract concepts such as shape/space positions, and teach computers in some way. An image has more information than a set of bounding box and labels. A difference might be that computers are just passively taking in knowledge but a human beings can see, listen, eat, walk, explore and feel. We should definitely give computers some feedback as incentives. I believe we have most of the the tools we need (DNN, reinforcement learning, feature representations...), and it is time to combine all of them to push AI to a new front.

Thursday, October 9, 2014

The Future of Deep Learning

Quote from Yann LeCun:

What areas do you think are most promising right now for people who are just starting out?
  • representation learning (the current crop of deep learning methods is just one way of doing it)
  • learning long-term dependencies
  • marrying representation learning with structured prediction and/or reasoning
  • unsupervised representation learning, particularly prediction-based methods for temporal/sequential signals
  • marrying representation learning and reinforcement learning
  • using learning to speed up the solution of complex inference problems
  • theory: do theory (any theory) on deep learning/representation learning
  • understanding the landscape of objective functions in deep learning
  • in terms of applications: natural language understanding (e.g. for machine translation), video understanding
  • learning complex control.

Wednesday, October 1, 2014

Boost File and Folder Operations

#include"boost/filesystem.hpp"

using namespace boost::filesystem;

remove_all("train"); //remove folder

create_directory("train"); //create folder

exists(image_name); //check file exist

copy_file(image_name,out_image_name); //copy file

Link library:

/usr/lib/x86_64-linux-gnu/libboost_filesystem.so

Monday, September 29, 2014

Ubuntu Crashes Again

I should be very careful working with Linux console. It seems it is able to do anything including destroying itself.

Anyway, it's lucky that we can recover the system by reinstalling it. Note that reinstalling the system will usually not ruin your home folder, which means you can keep all your files and settings.

Follow the step here to do a thorough re-installation:

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

Friday, September 26, 2014

A Severe Accident with Ubuntu Kernel Update

I was being too young, sometimes naive to have the linux kernel updated since I believe it might resolve some of the bugs of the system.

The truth is: I'm wrong. After installing the latest kernel, which is 3.13.0-32-generic, I cannot boot into my system! It boots into the black screen instead.

It took me some time to resolve this, but it is actually very simple. In the grub menu, you can choose which kernel version you want to work with (in the advanced boot options). Choose the old one, and you will probably be able to have all the stuffs back.

What next? Remove all the latest kernels!

Do this:

sudo apt-get remove linux-image-3.13.0-32--generic

OK if you are unsure what kernel you have now use the following command:

cd /boot ls vmlinuz* 

It will list all the kernels you installed.

ubuntu 14.04

Nautilus sucks!

Try nemo instead.

Thursday, September 25, 2014

A Common Gitignore File

# Compiled Object files
*.slo
*.lo
*.obj

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod

# Compiled Static libraries
*.lai
*.la
*.lib

# Executables
*.exe
*.out
*.app

#dir
dataset/

*.o
bin/

Save it as .gitignroe

Tuesday, September 23, 2014

The Matlab Trick

Recently I had something tricky with Matlab.

[1 2 3]/[4 5 6]=0.4156  (this is equal to [1 2 3]*pinv([4 5 6]) )

[1 2 3]./[4 5 6]=[0.25 0.4 0.5]

These are two different things.

Sunday, September 21, 2014

Open Multi-threaded Programming

Open Multi-threaded Programming:

#include <omp.h>

Linker settings: other linker options: -fopenmp

A toy example:


  #pragma omp parallel for  
 for (unsigned vel=0; vel<laser_points_all.size(); vel++)   
 {  
       #pragma omp critical  
       {  
             laser_in_camera.push_back(lasercam);  
             intersections.push_back(intersection);  
             iplane.push_back(std::pair<int,int>(vel,inter_plane));  
        }  
 }  

Thursday, September 4, 2014

Format number and digit

If you want to format an integer to be six-digit by adding leading 0s, you can do that:
 string GetSixDigitAccuracyName(int id)  
 {  
   ostringstream oss;  
   oss<<setw(6)<<setfill('0')<<id<<"_accuracy.txt";  
   return oss.str();  
 }  

Wednesday, September 3, 2014

Parse Command Line

 ParameterStereoSlic parseCommandline(int argc, char* argv[]) {  
      // Make command parser  
      cmdline::parser commandParser;  
      commandParser.add<std::string>("output", 'o', "output file", false, "");  
      commandParser.add<double>("factor", 'f', "disparity factor of input disparity image", false, 256.0);  
      commandParser.add<int>("superpixel", 's', "the number of superpixels", false, 2000);  
      commandParser.add("verbose", 'v', "verbose");  
      commandParser.add("help", 'h', "display this message");  
      commandParser.set_program_name("smoothfit");  
      commandParser.footer("imgL0 dispL0 motion");  
      // Parse command line  
      bool isCorrectCommandline = commandParser.parse(argc, argv);  
      // Check arguments  
      if (!isCorrectCommandline) {  
           std::cerr << commandParser.error() << std::endl;  
      }  
      if (!isCorrectCommandline || commandParser.exist("help") || commandParser.rest().size() < 3) {  
           std::cerr << commandParser.usage() << std::endl;  
           exit(1);  
      }  
      // Set program parameters  
      ParameterStereoSlic parameters;  
      // Verbose flag  
      parameters.verbose = commandParser.exist("verbose");  
      // Disparity factor  
      parameters.disparityFactor = commandParser.get<double>("factor");  
      // The number of superpixels  
      parameters.superpixelTotal = commandParser.get<int>("superpixel");  
      // Input files  
      parameters.firstLeftImageFilename = commandParser.rest()[0];  
      parameters.firstLeftDisparityImageFilename = commandParser.rest()[1];  
      parameters.cameraMotionFilename = commandParser.rest()[2];  
      // Output files  
      std::string outputSegmentImageFilename = commandParser.get<std::string>("output");  
      if (outputSegmentImageFilename == "") {  
           outputSegmentImageFilename = parameters.firstLeftImageFilename;  
           size_t dotPosition = outputSegmentImageFilename.rfind('.');  
           if (dotPosition != std::string::npos) outputSegmentImageFilename.erase(dotPosition);  
           outputSegmentImageFilename += "_seg.png";  
      }  
      parameters.outputSegmentImageFilename = outputSegmentImageFilename;  
      std::string outputBoundaryImageFilename = outputSegmentImageFilename;  
      size_t dotPosition = outputBoundaryImageFilename.rfind('.');  
      if (dotPosition != std::string::npos) outputBoundaryImageFilename.erase(dotPosition);  
      std::string outputDisparityImageFilename = outputBoundaryImageFilename;  
      std::string outputFlowImageFilename = outputBoundaryImageFilename;  
      std::string outputBoundaryLabelImageFilename = outputBoundaryImageFilename;  
      std::string outputBoundaryLabelFilename = outputBoundaryImageFilename;  
      //by harry  
      std::string outputDisparityPlaneFilename = outputBoundaryImageFilename;  
      outputBoundaryImageFilename += "_boundary.png";  
      outputDisparityImageFilename += "_disparity.png";  
      outputFlowImageFilename += "_flow.png";  
      outputBoundaryLabelImageFilename += "_label.png";  
      outputBoundaryLabelFilename += "_label.txt";  
      outputDisparityPlaneFilename += "_planes.txt";  
      parameters.outputBoundaryImageFilename = outputBoundaryImageFilename;  
      parameters.outputDisparityImageFilename = outputDisparityImageFilename;  
      parameters.outputFlowImageFilename = outputFlowImageFilename;  
      parameters.outputBoundaryLabelImageFilename = outputBoundaryLabelImageFilename;  
      parameters.outputBoundaryLabelFilename = outputBoundaryLabelFilename;  
   parameters.outputDisparityPlaneFilename = outputDisparityPlaneFilename;  
      return parameters;  
 }  

run matlab function using command line

First, you need a matlab_batcher.sh file:

 matlab_exec=matlab  
 X="${1}(${2})"  
 echo ${X} > matlab_command_${2}.m  
 cat matlab_command_${2}.m  
 ${matlab_exec} -nojvm -nodisplay -nosplash &lt; matlab_command_${2}.m  
 rm matlab_command_${2}.m  

___________

Then for any matlab function you wanna run, using the following command (suppose the name of the function is smallrefine).

 ./matlab_batcher.sh smallrefine \'$lasercamclean_p_clean\',\'$raytraceclean_p_clean\',\'$planes_trans_mat\',\'$plane_refine_mat\'  

Pay attention to how we pass multiple string arguments to the matlab function.

Thursday, August 21, 2014

PCL Remove Outliers

 #include <pcl/filters/statistical_outlier_removal.h>  
 #include <pcl/filters/extract_indices.h>  
 inline void RemoveOutliers(std::vector<std::vector<double> > pts, std::vector<std::vector<double> >& pts_out, std::vector<int >& indices)  
 {  
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);  
  cloud->width=pts.size();  
  cloud->height=1;  
  cloud->points.resize(cloud->width*cloud->height);  
  for(int 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];  
  }  
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);  
  pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor(true);  
  sor.setInputCloud (cloud);  
  sor.setMeanK (50);  
  sor.setStddevMulThresh (1.0);  
  sor.filter (*cloud_filtered);  
  pts_out.resize(cloud_filtered->points.size());  
  for(int i=0;i<cloud_filtered->points.size();i++)  
  {  
     pts_out[i].resize(3);  
     pts_out[i][0]=cloud_filtered->points[i].x;  
     pts_out[i][1]=cloud_filtered->points[i].y;  
     pts_out[i][2]=cloud_filtered->points[i].z;  
  }  
  pcl::IndicesConstPtr ind=sor.getRemovedIndices();  
  pcl::PointIndices::Ptr removed_indices (new pcl::PointIndices());  
  removed_indices->indices = *ind;  
  indices.resize(removed_indices->indices.size());  
  for(int i=0;i<removed_indices->indices.size();i++)  
  {  
   indices[i]=removed_indices->indices[i];  
  }  
 }  

Monday, August 18, 2014

3D rotation matrix composition and decomposition

Decomposition

theta_x=atan2(mat(3,2),mat(3,3));
theta_y=atan2(-mat(3,1),sqrt(mat(3,2)*mat(3,3)));
theta_z=atan2(mat(2,1),mat(1,1));
param=[theta_x,theta_y,theta_z,mat(1,4),mat(2,4),mat(3,4)];

Composition:

T1=cos(y)*cos(z);
T2=cos(z)*sin(x)*sin(y)-cos(x)*sin(z);
T3=cos(x)*cos(z)*sin(y)+sin(x)*sin(z);
T5=cos(y)*sin(z);
T6=cos(x)*cos(z)+sin(x)*sin(y)*sin(z);
T7=-cos(z)*sin(x)+cos(x)*sin(y)*sin(z);
T9=-sin(y);
T10=cos(y)*sin(x);
T11=cos(x)*cos(y);

All in matlab code.

Tuesday, August 12, 2014

matlab loop through folder

 function [ flag ] = CropAll( folder_name,h )  
 files=dir(strcat(folder_name,'/*.png'));  
 for i=1:numel(files)  
   file_name=files(i).name;  
   img=imread([folder_name,'/',file_name]);  
   img2=img(1:h,:,:);  
   imwrite(img2,[folder_name,'/',file_name]);  
 end  
 flag=1;  
 end  

Friday, August 8, 2014

Some matlab expressions (updating)

1.  remove columns with all zeros

src(:,all(src==0,1))=[];

2. matlab options:

 option=optimset('MaxFunEvals',5000);

Thursday, August 7, 2014

Some Latex Exceptions

Recently I want to put some manuscript of mine in arXiv. But it only accepts latex versions.  So I have to re-compile the latex, and there are some errors when I do this, as I was running it on a clean Linux:


1. 
IEEEtran.cls:366: leading text: \normalfont
IEEEtran.cls:724: Font OT1/ptm/m/n/5=ptmr7t at 5.0pt not loadable: Metric (TFM)
install the recommended fonts to fix the problem:
§ sudo apt-get install texlive-fonts-recommended
 
2. 
Algortihm.sty not found.
 
Solution: add various algorithm packages by running: sudo apt-get install texlive-science. 

Long Equations in Latex

I recently need to solve some nonlinear least square system, and the equations soon become very complex for an A4 page to display.

Of course you can solve it using eqnarray and show it in multiple lines, but it won't work if the equation cannot be separated, such as it is a long fraction.

I resolve this by adding \small before the equations, and add \normalsize after the equations. Actually, there is something else you can use:

  1. \tiny
  2. \scriptsize
  3. \footnotesize
  4. \small
  5. \normalsize
  6. \large
  7. \Large
  8. \LARGE
  9. \huge
  10. \Huge

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

Tuesday, April 29, 2014

Latex Matrix Example

 \[  
 \begin{bmatrix}  
  X^1_1 & X^1_2 & \cdots & X^1_d \\  
  X^2_1 & X^2_2 & \cdots & X^2_d \\  
   \vdots & & & \\  
   X^N_1 & X^N_2 & \cdots & X^N_d    
 \end{bmatrix}  
 \]  
You can reference to the latex wiki page.

Saturday, April 26, 2014

Latex: a minimum working set

 \documentclass[12pt]{article}  
 \usepackage[utf8]{inputenc}  
 \usepackage{amsmath}  
 \title{Template}  
 \date{}  
 \begin{document}  
  \maketitle   
 \end{document}  

Thursday, April 24, 2014

Install GoAgent in 5 Minutes (Chrome Version)

You are in China, and you feel like you need to access beyond Chinese websites. I know how you feel, since I have been through this before. The good news is that you can now use goagent to bypass the Great Fire Wall. This tutorial shows how it can be done in 5 minutes.

Step 1. Create an application at Google App Engine. Remember the app id.


If you have already created one for the purpose of goagent before you don't need to create it again. You can use the same app to host goagent.

Step 2. Download GoAgent files. I have put a copy at my Google Drive so that you can access it here. In case you are not able to access Google Drive, I have put a copy at Weiyun which could be downloaded here.

Step 3. Unzip the files, run Server\Uploader.bat. Write down your Google App id as well as your email address and your password. After that you should be able to see Deployment Successful.

Step 4. Edit Local\Proxy.ini. Write down your appid and leave everything else as it is.



Step 5. Open Chrome and install the extension Proxy SwitchSharp here. The setting page should open automatically. If not manually open the setting page.

Step 6. In the export/import tab, you should see "Recover from local files" under "SwitchSharp options". Upload the file Local\SwitchOptions.bak. Click Yes when confirmation window popped up.

Step 7. In the "Switching Rules" tab, click "Update list immediately". However this is likely to fail as it is probably blocked by GFW, so here you should bypass it by turning on SwithSharp first. Click SwitchSharp icon on Chrome and choose "goagent".

Configuration is done. Go ahead and enjoy freedom.

Tuesday, April 8, 2014

Latex References for Equations and Hyperlinks

Equations:

 \usepackage{amsmath}  
 \begin{eqnarray*}  
 \min\frac{1}{2}w^Tw+C\sum\limits_{i=1}^l\epsilon_i \\  
 \mbox{subject to }y_i(w^T\phi(x_i)+b)\geq 1-\epsilon_i,\\  
 \epsilon_i\geq 0,i=1,...,l,  
 \end{eqnarray*}  
Hyperlinks:

 \usepackage{hyperref}  
 \url{https://www.statsoft.com/textbook/support-vector-machines}  

Sunday, March 30, 2014

Three Easy Steps to Install Scikit-Learn

1. Install WinPython: http://sourceforge.net/projects/winpython/?source=dlp

This will install python distribution package together with numpy, scipy, etc.

2. Register Python using "WinPython Control Panel.exe" under WinPython folder.

3. Download and run scikit-learn installation executable. Make sure their versions are matched.

--Simple Test

>>> from sklearn import linear_model
>>> clf=linear_model.LinearRegression()
>>> clf.fit([[0,0],[1,1],[2,2]],[0,1,2])
LinearRegression(copy_X=True, fit_intercept=True, normalize=False)
>>> clf.coef_
array([ 0.5,  0.5])
>>>

Thursday, March 27, 2014

Ridge Regression Model with Generalized Cross Validation

An introduction to GCV can be found here:

http://sfb649.wiwi.hu-berlin.de/fedc_homepage/xplore/ebooks/html/csa/node123.html

In ridge regression model with generalized cross validation, we can determine the ridge parameter by selecting \$\lambda\$ that minimizes the following:

$\displaystyle \mathrm{GCV}(\lambda)=\frac{\frac{1}{n} \sum_{i=1}^n ( y_i-\widehat{f}_{\lambda}(t_i))^2} {(1-trH(\lambda)/n)^2}\, .$
where matrix \$H(\lambda)\$ is given as
\$X(X^{T}X+\lambda I)X^{T}\$.

The code:


 void CRidgeRegressionGCV::ComputeRegression()  
 {  
      double minGCV = FLT_MAX;  
      for (int t = 0; t < m_alphas.size(); t++)  
      {  
           double alpha = m_alphas[t];  
           int m = m_X.size();  
           int n = m_X[0].size();  
           MatrixXd mat(m, n + 1);  
           VectorXd rhs(m);  
           for (int i = 0; i < m; i++)  
           {  
                for (int j = 0; j < n + 1; j++)  
                {  
                     if (j < n)  
                     {  
                          mat(i, j) = m_X[i][j];  
                          rhs(i) = m_Y[i];  
                     }  
                     else  
                     {  
                          mat(i, j) = 1;  
                     }  
                }  
           }  
           MatrixXd tmp = mat.transpose()*mat + alpha*MatrixXd::Identity(n + 1, n + 1);  
           JacobiSVD<MatrixXd> svd(tmp, ComputeThinU | ComputeThinV);  
           MatrixXd res = svd.solve(mat.transpose()*rhs);  
           vector<double> coef(n);  
           double intercept;  
           coef.resize(n);  
           for (int i = 0; i < n; i++)  
           {  
                coef[i] = res(i, 0);  
           }  
           intercept = res(n, 0);  
           double GCV = 0;  
           for (int i = 0; i < m; i++)  
           {  
                double sum = 0;  
                for (int j = 0; j < n; j++)  
                {  
                     sum += m_X[i][j] * coef[j];  
                }  
                sum += intercept;  
                double diff = m_Y[i] - sum;  
                double diffsquare = diff*diff;  
                GCV += diffsquare;  
           }  
           GCV /= m;  
           MatrixXd tmp2=svd.solve(mat.transpose());  
           MatrixXd H = mat*tmp2;  
           GCV /= (1-H.trace()/m)*(1-H.trace()/m);  
           if (GCV < minGCV)  
           {  
                minGCV = GCV;  
                m_coef = coef;  
                m_intercept = intercept;  
                m_alpha = alpha;  
           }  
      }  
 }  

Ridge Regression Model

In ridge regression model, optimal w is given by:
\$(X^{T}X+\alpha I)^{-1}X^{T}Y\$

The code:


 void CRidgeRegression::ComputeRegression()  
 {  
      int m = m_X.size();  
      int n = m_X[0].size();  
      MatrixXd mat(m, n + 1);  
      VectorXd rhs(m);  
      for (int i = 0; i < m; i++)  
      {  
           for (int j = 0; j < n + 1; j++)  
           {  
                if (j < n)  
                {  
                     mat(i, j) = m_X[i][j];  
                     rhs(i) = m_Y[i];  
                }  
                else  
                {  
                     mat(i, j) = 1;  
                }  
           }  
      }  
      MatrixXd tmp = mat.transpose()*mat + m_alpha*MatrixXd::Identity(n + 1, n + 1);  
      JacobiSVD<MatrixXd> svd(tmp, ComputeThinU | ComputeThinV);  
      MatrixXd res = svd.solve(mat.transpose()*rhs);  
      m_coef.resize(n);  
      for (int i = 0; i < n; i++)  
      {  
           m_coef[i] = res(i, 0);  
      }  
      m_intercept = res(n, 0);  
 }  

Ways to Insert Equation and Code in Blogger

For code, the simplest way is to use the following website to convert it into html block:

http://codeformatter.blogspot.com/

For equation, you can use latex in blogger following the instructions on page:

https://www.codecogs.com/latex/integration/blogger/install.php

Ordinary Least Squares Model

In ordinary least squares model, optimal w is given by:
\$w=X^{-1}Y\$

A draft function for this is written as

 void CLinearRegression::ComputeRegression()  
 {  
      int m = m_X.size();  
      int n = m_X[0].size();  
      MatrixXd mat(m,n+1);  
      VectorXd rhs(m);  
      for (int i = 0; i < m; i++)  
      {  
           for (int j = 0; j < n+1; j++)  
           {  
                if (j < n)  
                {  
                     mat(i, j) = m_X[i][j];  
                     rhs(i) = m_Y[i];  
                }  
                else  
                {  
                     mat(i, j) = 1;  
                }  
           }  
      }  
      JacobiSVD<MatrixXd> svd(mat, ComputeThinU | ComputeThinV);  
      MatrixXd res=svd.solve(rhs);  
      m_coef.resize(n);  
      for (int i = 0; i < n; i++)  
      {  
           m_coef[i] = res(i, 0);  
      }  
      m_intercept = res(n, 0);  
 }  

Wednesday, March 26, 2014

An Introduction to Eigen

What is Eigen?

Eigen is a high-level C++ library of template headers for linear algebramatrix and vector operations,numerical solvers and related algorithms.

How to install Eigen?

Get the latest Eigen package from here. Unzip it and include the appropriate header files. There is no need to compile or include binaries.

How to use Eigen?

I have included my code for computing ridge regression here to show some sample usages of Eigen. Most of the time it is very straight-forward. 


 #include<Eigen/SVD>  
 using namespace Eigen;  
 void CRidgeRegression::ComputeRegression()  
 {  
      int m = m_X.size();  
      int n = m_X[0].size();  
      MatrixXd mat(m, n + 1);  
      VectorXd rhs(m);  
      for (int i = 0; i < m; i++)  
      {  
           for (int j = 0; j < n + 1; j++)  
           {  
                if (j < n)  
                {  
                     mat(i, j) = m_X[i][j];  
                     rhs(i) = m_Y[i];  
                }  
                else  
                {  
                     mat(i, j) = 1;  
                }  
           }  
      }  
      MatrixXd tmp = mat.transpose()*mat + m_alpha*MatrixXd::Identity(n + 1, n + 1);  
      JacobiSVD<MatrixXd> svd(tmp, ComputeThinU | ComputeThinV);  
      MatrixXd res = svd.solve(mat.transpose()*rhs);  
      m_coef.resize(n);  
      for (int i = 0; i < n; i++)  
      {  
           m_coef[i] = res(i, 0);  
      }  
      m_intercept = res(n, 0);  
 }