10/21/2011

STL vector(with 2 more elements) sorting code / STL에서 2개 이상의 엘리먼트를 가지고 있는 vector 정렬 code

The source is simple but I always don't remember the code well.
If you similar to me, refer to my code easily.


#include <iostream>
#include <cmath>
#include <time.h>
#include <vector>
#include <algorithm>
using namespace std;

class element{
public:
    element(float a, int b){
        value = a;
        index = b;
    }
    float value;
    int index;
};

bool compare(const element &a, const element &b )
{
    return a.value < b.value; //오름차순(ascending order)
    //return a.value > b.value; //내림차순(descending order)
}

void main()
{
    srand( (unsigned int)time(NULL));

    vector< element > A;

    // 값 넣기 (input value)/////////////////////////////////////////////
    for(int i=0; i<20000; ++i){
        A.push_back( element(rand()%10, i) );
    }


    //값 출력  (data print)///////////////////////////////////////////////
    printf("정렬 전(Before ordering) \n");
    for(i=0; i<20000; ++i){
        printf("A[%d] -> value %f :: index -> %d\n", i, A[i].value, A[i].index );
    }


    //정렬 (sorting)
    sort(A.begin(),A.end(),compare);


    //값 출력 (Value print)
    printf("정렬 후(After ordering)\n");
    for(i=0; i<20000; ++i){
        printf("A[%d] -> value %f :: index -> %d\n", i, A[i].value, A[i].index );
    }
      
}

10/19/2011

Incremental K-means matlab source code

Created Date : 2011.10.
Language : Matlab 2010
Tool : -
Library & Utilized :-
Reference :An Incremental K-means algorithm(D.T. Pham, S.S. Dimov and C.D. Nguyen)
Etc. :-




I made Incremental K-means algorithm as matlab source code.
I made the code base on above table which is introduced in the paper.
The incremental K-means is similar to K-means but the different point is number of cluster class is increasing. but we have to set the maximum number.

Below figure is result of clustering. the sample data is normal vector of the 3D point that is acquied by bumblebee.
I think the K-means algorithm is sensitive to error or outlier data. because the algorithm use euclidean distance. and The result of clustering is different every time because the initial position of the class is selected randomly.

I hope my code help to your problem and study.
thank you.
Give me your valuable comments. ^^

<source code>
Clustering result of the sample datas.





enlarge image of the above figure




10/17/2011

BumBleBee 2D, 3D data acquisition source code / 범블비 2D, 3D 데이터 획득 소스

Created Date : 2009.10.
Language : C++
Tool : Visual Studio C++ 2008
Library & Utilized : Point Grey-FlyCapture, Triclops, OpenCV 2.1
Reference : PointGrey Bumblebee Reference, www.cylod.com, www.ptgrey.com/
Etc. : STL



BumBleBee Stereo Camera Data Acquisition Source code.



This is Stereo Camera. The name is BumBleBee. This is product of PointGrey Company.
This camera is IEEE 1394 capble type.
This camera can obtain 3D cloud data rapidly and continously.

I need 2 library for using this camera(Triclops SDK, FlyCapture).
You can download these libs on the www.ptgrey.com site(support).
You have to use my source after install libs. and you have to set path(To include directory, lib directory). and you also need opencv 2.1 lib.

I made the acquisition code as class. The class name is CSensorStereo2.
You can use this class like below source code.
The sequence is 'Open->GetData->Close'.
I did that 2D data save Iplimage in opencv and 3D depth data save as Txt file.
The source code is very easy to use ^^.
If you have any question, Plz give your comments to me.

Thank you.

source code is shared on Github
https://github.com/MareArts/Bumblebee_GetDataClass



#include <stdio.h>
#include "SensorStereo2.h"
#include <time.h>

void main()
{

int Width = 320;
int Height = 240; 

CSensorStereo2 CSS2;
CSS2.Initial(Width,Height); 
CSS2.Open();

cvNamedWindow("Reference");
char str[1000];

while(1) {

//get 1 frame data(Image, Depth information)
CSS2.GetData();

//Show Image
cvShowImage("Reference",CSS2.ImgReference); 

//Save Depth
sprintf(str,"./DepthData/%d_Depth.txt",time(0));
printf("%s\n", str);

FILE * fp; fp = fopen(str,"w");
for(int i=0; i<Width; ++i)
{ 
  for(int j=0; j<Height; ++j)
  {
    fprintf(fp,"%lf %lf %lf\n", CSS2.pDepth[i][j].x, CSS2.pDepth[i][j].y, CSS2.pDepth[i][j].z );
  } 
}

fclose(fp);

if(cvWaitKey(1) >= 0 )
   break;
}

cvDestroyWindow("Reference");
CSS2.Close();
}