Tuesday, December 23, 2008

Serious problem

[vnl_quaterion]

I made a mistake when coding with quaterion related sections!!

the paper format [R X Y Z]

vnl coding format [X Y Z R]

damn!!!

That means I have to compare the version between vnl_quaterion and VW::QUATERION

[vnl_matrix_fixed] "fill" member related

The source of the problem is that VXL uses explicit instantiation of Templates as opposed to ITK that uses implicit instatiation. This means that in vnl you can only use types that have already been explicity instantiated in the library. If you need to use a new combination, then

you have to add the corresponding explicit instantiation. The vnl_fixed_matrix is only instantiated for a

certain number of template parameters. You will find them under: Insight/Utilities/vxl/core/vnl/Templates They are

vnl_matrix_fixed+double.1.1-.cxx
vnl_matrix_fixed+double.1.2-.cxx
vnl_matrix_fixed+double.1.3-.cxx
vnl_matrix_fixed+double.2.1-.cxx
vnl_matrix_fixed+double.2.2-.cxx
vnl_matrix_fixed+double.2.3-.cxx
vnl_matrix_fixed+double.2.4-.cxx
vnl_matrix_fixed+double.2.6-.cxx
vnl_matrix_fixed+double.3.1-.cxx
vnl_matrix_fixed+double.3.2-.cxx
vnl_matrix_fixed+double.3.3-.cxx
vnl_matrix_fixed+double.3.4-.cxx
vnl_matrix_fixed+double.3.5-.cxx
vnl_matrix_fixed+double.4.1-.cxx
vnl_matrix_fixed+double.4.2-.cxx
vnl_matrix_fixed+double.4.3-.cxx
vnl_matrix_fixed+double.4.4-.cxx
vnl_matrix_fixed+double.6.6-.cxx
vnl_matrix_fixed+float.1.2-.cxx
vnl_matrix_fixed+float.1.3-.cxx
vnl_matrix_fixed+float.2.1-.cxx
vnl_matrix_fixed+float.2.2-.cxx
vnl_matrix_fixed+float.3.1-.cxx
vnl_matrix_fixed+float.3.3-.cxx
vnl_matrix_fixed+float.3.4-.cxx
vnl_matrix_fixed+float.3.5-.cxx
vnl_matrix_fixed+float.4.3-.cxx
vnl_matrix_fixed+float.4.4-.cxx
vnl_matrix_fixed+int.2.2-.cxx
vnl_matrix_fixed+int.3.4-.cxx
vnl_matrix_fixed+vnl_bignum.3.3-.cxx
vnl_matrix_fixed+vnl_rational.3.3-.cxx
vnl_matrix_fixed_pairwise_ops.cxx
vnl_matrix_fixed_ref+double.3.3-.cxx
vnl_matrix_fixed_ref+double.3.4-.cxx
vnl_matrix_fixed_ref+float.3.3-.cxx
vnl_matrix_fixed_ref+float.3.4-.cxx

As you can see, there is no instantiation for a matrix of size over 6 x 6 which is what you seems to be trying to instantiate.

Read More...

Monday, December 8, 2008

Few problems u might possibly encounter when deriving class from base class

1. undefined reference to `vtable for XXXXXXX'

vtable means virtual table, all errors about undefined reference to vtable are caused due to virtual function in class!
This error might raised due to you declare the virtual functions which are inherited from base class in derived class without implementation.

e.g.

class Base
{
public:


Base();
virtual ~Base();

virtual void foo() = 0;
};

class Dclass : Base
{
public:

Dclass();

~Dclass();


void foo();

};

Dclass::Dclass() : Base()
{}

Dclass::~Dclass()
{}

void Dclass::foo() // will cause error if not be implemented!!!
{}

e.g


if you declare some virtual functions in xxx.h file, you must implement them(those virtual functions) after ctor implementation. or it will cause undefined reference to `vtable for XXXXXX'

Read More...

Wednesday, September 24, 2008

Coding Log

2008 08/27

  • Prymidal down sampling using Class method
    performance: ~1.8 ms @ Pentium M 1.73GHz 

2008 08/29

  • Lucas-Kanade Optical Flow tracker ( tracking 1 feature point ) 
    performance: ~0.13 0.7 ms @ Pentium M 1.73GHz

2008 09/11

  • demo:


    Drift problem is still not solved.

2008 09/14

  • when coding matrix operation in the way like matlab, must add library "libvcl.a, libvnl.a, libvnl_algo, libvnl_io.a, libvnl_xio.a" into library setting and include every header file you need.
    [ download project in C::B ]

2008 09/20 ( sequential build Log )

  • LKTracker.h & LKTracker.cpp
    • class LKTracker ( completed
      .
  • Feature_Init.h & Feature_Init.cpp
    • class Particle ( completed )
    • class FeatureInitInfo ( todo )
      .
  • identifier.h & identifier.cpp
    • class Extradata ( completed )
      .
  • ThreeDbase.h & ThreeDbase.cpp
    • class Point3D ( completed ) ( need test! )
    • namespace THREED
      .
  • function.h & function.cpp
    • some functions like Jocobian calculator and quaterion transformation ( need indentified )
      .

2008 09/21~24

  • Settings.h & Settings.cpp ( read and write control in file ) ( need? ) ( suspended )
    • class Settings
      • class Section
        .
  • Model_base.h & Model_base.cpp ( need indentification
    • class Motion_Model
    • class ThreeD_Motion_model : public Motion_Model
    • class Motion_Model_Creator
    • class Feature_Measurement_Model
    • class Fully_Initialized_Feature_Measurement_Model : public Feature_Measurement_Model
    • class Partially_Initialized_feature_measurement_Model : public Feature_Measurement_Model
    • class Feature_Measurement_Model_Creator
    • class Internal_Measure_Model
    • class Internal_Measure_Model_Creator

Read More...

Wednesday, September 3, 2008

Difference between structure of image and frame

If you have a static image, the pixel sequence of the data structure is top-to-bottle and left-to-right

0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24          
30                  
40                  
50                  
60                  
70                  
80         85 86 87 88 89
90 91 92 93 94 95 96 97 98 99

 

if you capture a frame from camera, the pixel sequence of the rawdata structure is bottle-to-top and left-to-right

90 91 92 93 94 95 96 97 98 99
80         85 86 87 88 89
70                  
60                  
50                  
40                  
30                  
20 21 22 23 24          
10 11 12 13 14 15 16 17 18 19
0 1 2 3 4 5 6 7 8 9

Read More...

Tuesday, August 19, 2008

Method of processing pixel of image

1.
Include file:

#include <wx/rawbmp.h>

Pre defination:

typedef wxPixelData<wxBitmap, wxNativePixelFormat> PixelData;

Code example:

unsigned char grey = 0;

wxBitmap* m_pbmp = new wxBitmap(wxT("name.bmp"), wxBITMAP_TYPE_BMP);

PixelData data(*m_pbmp);
PixelData::Iterator p(data);
p.Offset(data, 0, 0);

for ( int y = 0; y < data.GetHeight(); y++ )
{
PixelData::Iterator rowStart = p;

for ( int x = 0; x < data.GetWidth(); x++, p++ )
{
grey = (unsigned char)(0.212671*p.Red() + 0.715160*p.Green() + 0.072169*p.Blue());
p.Red() = (unsigned char)grey;
p.Green() = (unsigned char)grey;
p.Blue() = (unsigned char)grey;
}

p = rowStart;
p.OffsetY(data, 1);
}

2.

Include file: None.
Pre defination: None. Code example:

wxImage temp_wxImage;
unsigned char* manipulator = NULL;
manipulator = temp_wxImage.GetData();
int width = temp_wxImage.GetWidth();
int height = temp_wxImage.GetHeight();

int grey = 0;
for(int j = 0; j < height; j++)
for(int i = j*3*width; i < (j+1)*3*width; i+=3)
{
grey = (unsigned char)(0.212671*manipulator[i] +
0.715160*manipulator[i+1] + 0.072169*manipulator[i+2]);
manipulator[i] = grey;
manipulator[i+1] = grey;
manipulator[i+2] = grey;
}

or

wxImage temp_wxImage;
unsigned char* manipulator = NULL;
manipulator = temp_wxImage.GetData();
int width = temp_wxImage.GetWidth();
int height = temp_wxImage.GetHeight();
int grey = 0;
for(int j = 0; j < height; j++)
for(int i = 0; i < width; i++)
{
grey = (unsigned char)(0.212671*manipulator[(i+j*width)*3] +
0.715160*manipulator[(i+j*width)*3+1] +
0.072169*manipulator[(i+j*width)*3+2]);
manipulator[(i+j*width)*3] = grey;
manipulator[(i+j*width)*3+1] = grey;
manipulator[(i+j*width)*3+2] = grey;
}

Read More...

Wednesday, August 6, 2008

Integral table computation

The raw data:

a

b

c

d

e

f

g

h

i

j

k

l

m

n

o

p

q

r

s

t

u

v

w

x

y

 

The integral data:

E

F

A

B

G

C

D

H

I

 
     The integral rule is that each element in the integral table is sum of upper-left elements( including itself ). e.g,
  • A = a + b + f + g
  • B = a + b + c + f + g + h
  • C = a + b + f + g + k + l
  • D = a + b + c + f + g + h + k + l + m

We can, therefore, simply archive the integral table by 4 "for loop"

for(int j = 0; j < height; j++) 
{
for(int i = 0; i < width; i++)
{
integral[j][i] = 0;
for(int y = 0; y <= j; y++)
{
for(int x = 0; x <= i; x++)
{
integral[j][i] += rawdata[y][x];
}
}
}
}


but it is too inefficiency and consuming too many operations when computing in such simple way . Thus, we can examine the integral table, it can be found that D could be get from the 3 nearest upper-left element A, B, C. So D = m + B + C - A. In addition we must consider the boundary problem, when processing the first row it's just the sum of the current raw data and the left integral data, e.g, F = d + E. The same as above, when processing the first colume it's just the sum of the current raw data and the upper integral data, e.g, H = p + G. Therefore, the computation can be archieved by using only 2 "for loop"



for(int j = 0; j < height; j++) 
{
for(int i = 0; i < width; i++)
{
if((j == 0) && (i == 0))// process the first col and row element
integral[j][i] = rawdata[j][i];
else if((j == 0) && (i != 0))// process the first row element
integral[j][i] = rawdata[j][i] + integral[j][i-1];
// F = d + E
else if((j != 0) && (i == 0))// process the first col elements
integral[j][i] = rawdata[j][i] + integral[j-1][i];
// H = p + G
else // process the normal element
integral[j][i] = rawdata[j][i] + integral[j-1][i] +
integral[j][i-1] - integral[j-1][i-1];
// D = m + B + C - A
}
}


[ Download ]: test file (C::B project)

Read More...

Sunday, May 18, 2008

Building Boost C++ lib for MINGW and coding in Code::Blocks

boost + splash_new blank

Boost C++ Libraries is one of the most highly regarded and expertly designed C++ library projects in the world. It provides many efficient algorithms to help App developers to improve their program. However, the Boost's official website offers only source files and Build Tools ( Boost JAM ), we must build the suitable Lib according to the compiler ( like GNU GCC Compiler, Borland C++ Compiler or VC++ Compiler ). Althought, there're many pre-builded destro providered by some unofficial website, most of them are for VC++ Compiler.

Here's a tutorial for building Boost C++ Lib for MINGW GCC Compiler.

  • First of all, Download Boost from the Boost website. You will need the actual Boost package (source) and the Boost Jam package (binary NTx86). Unpack the first package to any location on you harddisk and unpack the file "bjam.exe'' from the second package to a directory contained in your search path (e.g. "C:\MinGW\bin'' or "C:\Program Files\CodeBlocks\MinGW\bin").
  • Then open a shell (cmd.exe) and change into the directory you have unpacked the Boost package to. Type the following command:
    C:\....\boost_1_35_0\>bjam --toolset=gcc --prefix=C:\Boost install
  • While building, it'll take 30 mins up to couple hours depends on your machine. So be patiant.
  • Then Boost C++ Lib will be installed in "C:\Boost\include\boost-version"

After that. we can use Boost to code for MINGW GCC Compiler in Code::Blocks IDE. Before coding, add the Boost "include" and "lib" into the compiler search dictionary.

  • Open the Code::Blocks IDE, then click on "settings""compiler and debugger...", change to "search dictionary" page and add "C:\Boost\include\boost-1_35" into "compiler" page.sshot-1
  • Then add "C:\Boost\lib" into  "Linker" page.

Creat a new Console Application project for C++,  click "Project" → "Build options...". Add the lib you need in your project (e.g. C:\Boost\lib\boost_signals-mgw34-mt-1_35.lib)

sshot-1

Then code following code in main.cpp

// Boost.Signals library

// Copyright Douglas Gregor 2001-2003. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// For more information, see http://www.boost.org

#include
#include
#include
#include

struct HelloWorld
{
void operator()() const
{
std::cout << "Hello, World!" << std::endl;
}
};

int
test_main(int, char* [])
{
// Signal with no arguments and a void return value
boost::signal sig;

// Connect a HelloWorld slot
HelloWorld hello;
sig.connect(hello);

// Call all of the slots
//sig();
return 0;
}


Compilation will be completed.

If you have any question, it's great to post in comment :-)


Read More...