Archive for the ‘C/C++’ Category

This is point cloud of Chiang Kai-shek Memorial Hall (中正紀念堂) Point Cloud. It has 559219 points and loaded using PCL.

In this article i will explain to how compile C++ library (OpenCV as an example), how to include the headers, linking the .lib files, and put the .dlls

You can read these two links to know the differences between Static Library (http://en.wikipedia.org/wiki/Static_library) and Dynamic Library (http://en.wikipedia.org/wiki/Dynamic-link_library)

This article assumes you have some knowledges in C/C++.  For short, compiling OpenCV and another C++ libraries is always similar and pretty easy after you know how. This tutorial will be in Visual Studio environment (2008 or 2010) .

1. The first step is to install CMake 2.8.x on your computer (http://www.cmake.org/). What is this CMake program? It simply prepares the C++ codes to be ready compiled from specified compiler (you know for windows, there are several compilers such as Cygwin, MinGW, Visual C++, etc.). This CMake is really useful to distribute C++ source code so it can be independent from other people’s Compiler and IDE.

2. Then download OpenCV library from sourceforge, the latest version is OpenCV 2.4.0 (http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.0/)

3. Since CUDA is getting popular and OpenCV also implements some of their libraries using CUDA, you can try to install CUDA.  But this is optional since not all computers have NVIDIA GPU. If you need to install CUDA, you can find it here (http://developer.nvidia.com/cuda-downloads)

(more…)

I was experimenting surface reconstruction on point cloud. I used Greedy Triangulation Projection implemented in PCL. Here’s the input point cloud (i used dataset from here http://svn.pointclouds.org/data/tosca_hires/) :

The result was saved in .PLY file format and displayed using MeshLab (http://meshlab.sourceforge.net/)

The result is not really good since the points are not dense enough. On the sparse areas it can easily produces holes. But I should admit this algorithm is really fast. I think I’ll try another algorithm such as poisson surface reconstruction to see whether it has better result or not :)

Currently i need to obtain depth map using stereo images and  Block Matching Algorithm in OpenCV painfully requires many parameter adjustments.  Then i found out Stereo BM Tuner by Martin Perris (http://blog.martinperis.com/2011/08/opencv-stereo-matching.html) is quite handy and useful. The only problem he developed this tool using Linux and Gtk+ (Ok, i am Visual Studio user XD ) so i need to port it to Windows.

Actually the porting was not that difficult, and after 2 hours of googling i found the solution:

First you need to download Gtk+ fow Windows 32bit and you should download the all-in-one bundle version (http://www.gtk.org/download/win32.php, dependencies included), zipped version, contains all dll, lib, and include files.

Open your Project through Visual Studio and right click–> Project Properties –> C/C++ section –> Additional Include Directories:

{your gtk+ bundle directory}\include;
{your gtk+ bundle directory}\include\gtk-2.0;
{your gtk+ bundle directory}\include\atk-1.0;
{your gtk+ bundle directory}\include\freetype2;
{your gtk+ bundle directory}\include\gail-1.0;
{your gtk+ bundle directory}\include\gdk-pixbuf-2.0;
{your gtk+ bundle directory}\include\gio-win32-2.0;
{your gtk+ bundle directory}\include\glib-2.0;
{your gtk+ bundle directory}\include\pango-1.0;
{your gtk+ bundle directory}\lib\glib-2.0\include;
{your gtk+ bundle directory}\include\cairo;
{your gtk+ bundle directory}\lib\gtk-2.0\include;

Project Properties –> Linker –> General –> Additional Library Directories:

{your gtk+ bundle directory}\lib

Project Properties –> Linker –> Input –> Additional Dependencies:

atk-1.0.lib
cairo.lib
expat.lib
fontconfig.lib
freetype.lib
gailutil.lib
gdk_pixbuf-2.0.lib
gdk-win32-2.0.lib
gio-2.0.lib
glib-2.0.lib
gmodule-2.0.lib
gobject-2.0.lib
gthread-2.0.lib
gtk-win32-2.0.lib
intl.lib
libpng.lib
pango-1.0.lib
pangocairo-1.0.lib
pangoft2-1.0.lib
pangowin32-1.0.lib
zdll.lib

And don’t forget Project Properties –> Linker –>System –>  SubSystem should be set as Console (/SUBSYSTEM:CONSOLE)

Then we need to modify every callback function, for example:

extern "C" __declspec(dllexport)
G_MODULE_EXPORT void on_adjustment1_value_changed( GtkAdjustment *adjustment, ChData *data )
{
    ...
}

Last step you need to copy the .glade file and all of files in {your gtk+ bundle directory}\bin (except the .exe files) on the binary folder (bin\Debug or bin\Release)

I am planning to do 3D object reconstruction using stereo camera so first i need to do stereo calibration on my 3D camera.

The stereo camera i am using is Fujifilm w3 3D Camera. This camera produces MPO file image which is JPG in stereo format. For pre processing of course it is need to be converted into pair of images which can be read by OpenCV by using Stereo Photomarker (SPM) (http://stereo.jpn.org/eng/stphmkr/).

One thing you should notice when using this SPM when converting .MPO into pair of JPG images is to reset the automatic alignment (press “Home” to reset the alignment).  SPM automatically aligns the .MPO image so it can be viewed better when you use 3D glasses, but this alignment will crop the images. I don’t want this cropped images since resulted images won’t have the same size and it’s disaster.

The stereo calibration code can be read on here: http://blog.martinperis.com/2011/01/opencv-stereo-camera-calibration.html.

if it is success you can get xml calibration file similar to this:

<?xml version="1.0"?>
<opencv_storage>
<Q type_id="opencv-matrix">
  <rows>4</rows>
  <cols>4</cols>
  <dt>d</dt>
  <data>
    1. 0. 0. -2.8327271270751953e+002 0. 1. 0. -1.5946473121643066e+002
    0. 0. 0. 1.0546290540664800e+003 0. 0. -2.3597727835463600e-001
    -1.7014427703509563e+000</data></Q>
</opencv_storage>

At first i use chess pattern with 9×6 inner corners, 11 pairs of image, 1024×768 in size. And the result is really bad distortion, as you can see in corners of the image below

Then i figure out i need to use larger chess pattern and more pair of image. Then i use 15×8 inner corners, 26 pairs of image, and 1024×768 resolution. The rectified result looks better

This week i was trying to get 3D keypoints from Point Cloud. I use PCL and the algorithm is based on 2004 David G. Lowe paper. In PCL, the algorithm is extended 2D + 1 in the spatial domain.
I was able to obtain the keypoint extraction through Difference of Gaussian. Currently i need to compute the keypoint descriptor and match it up to another point cloud. Unfortunately, since Point Cloud is 3D data, we can’t implement SIFT Descriptor instead it is replaced with PFH Descriptor.

Note: the red dots are the keypoint




Right now i’m experimenting with Kinect to animate a 3D model or model skinning by using Kinect. To calculate the joint orientation, first i need to obtain the three orthonormal axes (X, Y, and Z) and create Quaternion to change every bone orientation. By this way, the noise produces by Kinect can be reduced and character movement can look smoother and independent from position. Another advantage of using joint orientation, character movement isn’t depended to body posture and model scaling.

More info and source code: http://code.google.com/p/ogrekinect/

Hello PCL

Posted: February 9, 2012 in C/C++, Point Cloud
Tags: ,

Hi, this article is about the very basic of PCL, how to install the dependencies, get PCL source code and build it :)

The first step is download all dependencies at the web page below:

http://pointclouds.org/downloads/windows.html

On that page, OpenNI version is still 1.3, you can use the newer one, OpenNI 1.5.2. My system is Windows 7 x64 but all the dependencies are 32bit (it should be okay)

The next step is install OpenNI and Kinect driver first (http://www.openni.org/Downloads/OpenNIModules.aspx):

  1. OpenNI 1.5.2 Dev Stable
  2. Primesense NITE 1.5.2 Dev Stable
  3. OpenNI Kinect Driver, https://github.com/avin2/SensorKinect

Then All PCL dependencies:

  1. QHull 6.2.0
  2. VTK 5.8.0
  3. FLANN 1.7.1
  4. Eigen 3.0.3
  5. Boost 1.47.0
  6. NVIDIA GPU Computing SDK (optional)

Get PCL source by using SVN

http://svn.pointclouds.org/pcl/trunk/

How to compile PCL Library using Visual Studio:

http://www.pointclouds.org/documentation/tutorials/compiling_pcl_windows_3rdparty_installers.php

Try out some OpenNI samples:

Hi, it’s been long time since my last post. I’ve just finished a project titled “Launch Launch Launch Saturn V”.  I made this using OGRE 3D and Bullet Physics. Oh yeah, if you want to look at the code you can get it from google code: http://code.google.com/p/azbullet/

std::vector

Posted: October 17, 2011 in C/C++, Programming
Tags: , ,

vector, in C++ can act as a ArrayList,  similar to Java or C#. vector itself is included as a part of STL. In this article i just introduce some basic usage of vector, the rest can read here.

Here’s the instantiation of vector:

std::vector<AnObject*> objectList;

To add a member, we can use push_back()

objectList.push_back(anObject);

vector’s size it very simple to be obtained:

objectList.size();

The fun part of using vector when we’re accessing its member, it’s same as we use array :D

objectList[a]->aMethod();

To delete a member, it is little different, we should use iterator:

objectList.erase(objectList.begin() + a);

When a is the index of a member we want to delete and objectList.begin() is a method to obtain the initial iterator.