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.