1/31/2013

Drag and Save source code using openCV

When we study machine learning, we have to get a lot of image data.
And we should cut off only positive region on the image.

If we have many image to crop positive region, this source code is useful.

---------------------------------------------------------------------------------------------------
The method to use is..
1. input the path to crop image data.
2. number of image data 

On the image,
Click and Mouse drag ( green box line is drawn)
Space bar(save and next image)


----------------------------------------------------------------------------------------------------
environment
vs 2008
OpenCV 2.43

source code

1/25/2013

To save Txt file in the Matlab (dlmwrite function)

When you want to save vector values to Txt file, use dlmwrite function.
more detail information find in the matlab help file. (help dlmwrite)

-------------------------------------------------------
 simple example.
>>
>>dlmwrite('./saveV.txt', [1 2 3 4 5], 'delimiter', ' ');


 ->saveV.txt
1 2 3 4 5

--------------------------------------------------------

Thank you. ^^

1/13/2013

Car number plate image data

6 yeasrs ago, Han professor ask me. Don't open this image data.
But because a lot of time has passed.
I think sharing is not illegal. ^^


flate and car #1
flate and car #2
flate and car #3


346 images
< number flate only >

Image data of Car side view - 550

550 images of side view car

I don't remember how to get this images exactly.
I can not sure I made or get other site..

But this image will be useful to someone, so I share this images.

down >



1/12/2013

CvFilter2D example source code, various Filter masks

double K[] = { 1, 2, 1, 2, 4, 2, 1, 2, 1 };

float t=0;
for(int i=0; i< (3*3); ++i)
     t = t + K[i];
for(int i=0; i< (3*3); ++i)
     K[i] = K[i] / t;

CvMat Kernel=cvMat(3, 3, CV_64FC1, K); 
cvFilter2D(InputImg,OutputImg, &Kernel);


various type of filter mask
 
Gaussian Filter 
Average Filter
High pass Filter
Horizontal Prewitt Filter
Vertical Prewitt Filter
Horizontal Sobel Filter
Vertical Sobel Filter
Laplacian Filter
Sharpen Filter
 
Sharpen Low Filter

1/10/2013

C file Write, Read by Binary - example source code

C file Write, Read by Binary - example source code


#include < stdio.h >
#include < stdlib.h >
#include < time.h >


void main()
{


 //////////////////////////////////////////////////////////////////////////
 //File Write by binary
 srand( time(0));
 float feature[10];
 for(int i=0; i<10; ++i) 
  feature[i] = rand()/100; 

 //data confirm
 for(int i=0; i< 10; ++i) 
  printf("%lf\n", feature[i] );

 FILE * fp;
 fp = fopen("output.txt", "wb");
 fwrite(feature, sizeof(float), 10, fp);
 fclose(fp);

 printf("//////////////////////////////////////////////////////////////////////////\n");


 //////////////////////////////////////////////////////////////////////////
 //File Read by binary
 float feature_r[10];
 FILE* fp2;
 fp2 = fopen("output.txt", "rb");
 fread(feature_r, sizeof(float), 10, fp2);
 fclose(fp2);

 //data confirm
 for(int i=0; i< 10; ++i) 
  printf("%lf\n", feature_r[i] );
 //////////////////////////////////////////////////////////////////////////


}




881A sonar sensor - data acquisition source code

881A sonar sensor - data acquisition source code





source code >

This code is also made by VS 2008.
This source code included 'interface_881A' class.
You can get the data easily using the class.





//port open
CString strPort = "COM5";
int baudrate = 115200;
int data = 8;
int parity = 0;
int stop = 0;//1;
C881A.OpenPort2(strPort,baudrate,data,parity,stop);


//request data
C881A.SendData();


//data acquisition part
//The data is saved in the Command_881A_GetData struct
CString str;
 str.Format("%s", C881A.ReceiveData.DataHeader.c_str());
 m_List.AddString(str);

 str.Format("Head ID : %d", C881A.ReceiveData.HeadID);
 m_List.AddString(str);

 str.Format("Head Position : %lf", C881A.ReceiveData.HeadPosition);
 m_List.AddString(str);

 str.Format("Head direction : %d", C881A.ReceiveData.Direction);
 m_List.AddString(str);


 str.Format("Range : %d", C881A.ReceiveData.Range);
 m_List.AddString(str);

 str.Format("Profile Range : %d", C881A.ReceiveData.ProfileRange);
 m_List.AddString(str);

 str.Format("Data Byte : %d", C881A.ReceiveData.DataBytes);
 m_List.AddString(str);
 

 m_List10.ResetContent();
 for(int i=0; i< 500; ++i)
 {
  str.Format("[%d] = %d", i, C881A.ReceiveData.Data[i]);
  m_List10.AddString(str);
 }
 
///////////////////////////


//close port
C881A.ClosePort();



Thank you.


3DM-GX3 IMU sensor - Data acquisition source code

3DM-GX3 IMU sensor - Data acquisition source code


Code is made by Visual studio 2008(C++).


There is "3DM_GX3_interface" class In the source code.
You can get IMU data easily using the class.



//Open Port 
CString strPort = "COM7";
int baudrate = 115200; //19200;
int data = 8;
int parity = 0;
int stop = 0;//1;
C3DM_GX3.OpenPort2(strPort,baudrate,data,parity,stop);


//Request Data to the IMU, This function need one time when start to acquisition.
C3DM_GX3.SendData()

//Get Data loop until end.
C3DM_GX3.ReceiveData.roll/3.14*180 ;
C3DM_GX3.ReceiveData.pitch/3.14*180 ;
C3DM_GX3.ReceiveData.yaw/3.14*180 ;

//Close Port
C3DM_GX3.ClosePort();




"How to change 4byte bit data to float" is used to get the roll, yaw, pitch.
The method is introduced on my blog here.


this code is useful to you.
Thank you.

1/02/2013

Matlab dimension change function -> reshape

Useful function ~ ^^

A = magic(3)

A =
     8     1     6
     3     5     7
     4     9     2

>> B = reshape(A, 1, 3*3)

B =
     8     3     4     1     5     9     6     7     2


Image Normalization using Standard deviation - example source code

You can understand Standard deviation normalization, referenced on this web page.
http://www.d.umn.edu/~deoka001/Normalization.html
This web page introduce that..(wrote by Siddharth Deokar)

-------------------------------------------------------------------------
Normalization by Standard Deviation
We normalize the attribute values by using standard deviation.

For Example:

Consider 5 instances which has attribute A with the follwing values: {-5, 6, 9, 2, 4}

First we calculate the mean as follows:

Mean = (-5+6+9+2+4) / 5 = 3.2

Second, we subtract the mean from all the values and square them:

(-5-3.2)^2 = 67.24
(6-3.2)^2 = 7.84
(9-3.2)^2 = 33.64
(2-3.2)^2 = 1.44
(4-3.2)^2 = 0.64

Then we find the deviation as follows:

Deviation = sqrt ((67.24 + 7.84 + 33.64 + 1.44 + 0.64) / 5) = 4.71

Now we normalize the attribute values:

x => (x - Mean) / Deviation

-5 => (-5 - 3.2) / 4.71 = -1.74
6 => (6 - 3.2) / 4.71 = 0.59
9 => (9 - 3.2) / 4.71 = 1.23
2 => (2 - 3.2) / 4.71 = -0.25
4 => (4 - 3.2) / 4.71 = 0.17

-------------------------------------------------------------------------



This is sample source code:

//

int i,j,z;
 double sum=0; 
 double Mean;
 
 //sum, mean
 for(j=0; j< Height; ++j)
 {
  for(i=0; i< Width; ++i)
  {
   sum = sum + Pdata[i][j];
  }
 }

 Mean = sum/(Height*Width);
 
 //Deviation
 double dSum=0;
 double deviation;
 double std_dev; 
 
 for(j=0; j< Height; ++j)
 {
  for(i=0; i< Width; ++i)
  {        
   Pdata[i][j] = (Pdata[i][j] - Mean);

   dSum = dSum + (Pdata[i][j]*Pdata[i][j]);
  }
 }
 
 deviation = dSum / (Width*Height);
 std_dev = sqrt(deviation);
 
 //Normalization
 for(j=0; j< Height; ++j)
 {
  for(i=0; i< Width; ++i)
  {        
   Pdata[i][j] = (Pdata[i][j] / std_dev);
  }
 }