fork download
  1. #include <highgui.h>
  2.  
  3. #include <stdio.h>
  4.  
  5. #include <iostream>
  6.  
  7. #include <math.h>
  8.  
  9. #include <conio.h>
  10.  
  11. #include "Cpl64.h"
  12.  
  13. #include <fstream>
  14.  
  15. #include <iomanip>
  16.  
  17. #include"memory.h"
  18.  
  19. #define fileNum 400
  20.  
  21.  
  22.  
  23. using namespace std;
  24.  
  25.  
  26.  
  27. HANDLE ghEvent;
  28.  
  29.  
  30.  
  31. int x=0;
  32.  
  33. int Thickness;
  34.  
  35. int Shift;
  36.  
  37. int pixel = 4096;
  38.  
  39. int height = 400;
  40.  
  41.  
  42.  
  43. unsigned char *m_pImgBuff_All[fileNum];
  44.  
  45. void __stdcall MyCallBack(int Handle, int EventType, void *pBuffer, int Size)
  46.  
  47. {
  48.  
  49. //cout<<"b mode "<<x<<endl;
  50.  
  51. if(x<fileNum)
  52.  
  53. {
  54.  
  55. unsigned char *temp1=(unsigned char *)pBuffer;
  56.  
  57. cout<<(int*)m_pImgBuff_All[x]<<","<<(int*)temp1<<endl;
  58.  
  59. memcpy(m_pImgBuff_All[x], temp1, pixel*height*4); //將buffer內的data另外存到m_pImgBuff_All[x]
  60.  
  61. }
  62.  
  63. x++;
  64.  
  65. }
  66.  
  67.  
  68.  
  69. int main()
  70.  
  71. {
  72.  
  73. int Handle1,rtn;
  74.  
  75. int num=4096;
  76.  
  77. int cali_num=2048;
  78.  
  79. void *pBuffer;
  80.  
  81.  
  82.  
  83. float *cali2re = new float [cali_num];
  84.  
  85. float *avgR = new float [num];
  86.  
  87.  
  88.  
  89. unsigned char *tempArray[fileNum];
  90.  
  91.  
  92.  
  93. for(int j=0;j<fileNum;j++)
  94.  
  95. {
  96.  
  97. unsigned char *tempDeliver=new unsigned char [pixel*height*4];
  98.  
  99. tempArray[j]=tempDeliver;
  100.  
  101. cout<<j<<endl;
  102.  
  103. }
  104.  
  105. for(int j=0;j<fileNum;j++)
  106.  
  107. {
  108.  
  109. m_pImgBuff_All[j]=tempArray[j];
  110.  
  111. }
  112.  
  113.  
  114.  
  115. ifstream loadCali("LamdaCali_2048points.txt"); //這是calibration好的檔案
  116.  
  117. for(int w=0;w<cali_num;w++)
  118.  
  119. {
  120.  
  121. loadCali>>cali2re[w];
  122.  
  123. //cali2re[w]=cali2re[w]-1728;
  124.  
  125. }
  126.  
  127. loadCali.clear();
  128.  
  129. loadCali.close();
  130.  
  131.  
  132.  
  133. Handle1 = Cpl64_OpenDevice( 0, 0); //check your cardid and channel on CamCreator
  134.  
  135. //cout<<"Handle1 = "<<Handle1<<endl;
  136.  
  137. Cpl64_LoadCamFile(Handle1,"E:\\sd oct\\new800\\camfile\\Basler sprint spL4096-140km3D.ini");
  138.  
  139. //cout<<"here1"<<endl;
  140.  
  141. rtn=Cpl64_SetCallback(Handle1, 0, MyCallBack);
  142.  
  143. //cout<<"here2"<<endl;
  144.  
  145. ghEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  146.  
  147. rtn=Cpl64_StartCapture(Handle1, fileNum);
  148.  
  149. cout<<"Press Enter to Save Files"<<endl;
  150.  
  151. getch();
  152.  
  153. rtn = Cpl64_CloseDevice(Handle1);
  154.  
  155.  
  156.  
  157. //----------------------------------------------------------以下存檔-----------------------------------------------------------------------------
  158.  
  159.  
  160.  
  161. char fileNamePosition[80];
  162.  
  163. for(int j=0;j<fileNum;j++)
  164.  
  165. {
  166.  
  167. cout<<"存檔"<<j<<"中請稍候"<<endl;
  168.  
  169. unsigned char *temp2=(unsigned char *) tempArray[j]; //存下來的data拿出來
  170.  
  171.  
  172.  
  173. //---------------------------------平均頻譜--------------------------------------------------
  174.  
  175. float *in1 = new float [num];
  176.  
  177. float *out1 = new float [num];
  178.  
  179. for(int line=0;line<height;line++)
  180.  
  181. {
  182.  
  183. //cout<<"處理中:"<<line<<"/2000"<<endl;
  184.  
  185. for(int j=0;j<num;j++)
  186.  
  187. {
  188.  
  189. in1[j]=(int(temp2[2*j+2*line*num]))/16+16*int(temp2[2*j+1+2*line*num]);
  190.  
  191. }
  192.  
  193. for(int i=0;i<num;i++)
  194.  
  195. {
  196.  
  197. if(line==0)
  198.  
  199. out1[i]=in1[i];
  200.  
  201. else
  202.  
  203. out1[i]=out1[i]+in1[i];
  204.  
  205. }
  206.  
  207. }
  208.  
  209. for(int i=0;i<num;i++)
  210.  
  211. {
  212.  
  213. avgR[i]=out1[i]/height;
  214.  
  215. }
  216.  
  217. delete [] in1;
  218.  
  219. delete [] out1;
  220.  
  221. //----------------------------------------------------------------------------------------
  222.  
  223.  
  224.  
  225. sprintf(fileNamePosition,"E:\\sd oct\\new800\\3d\\test%d.bin",j);
  226.  
  227. ofstream savespec(fileNamePosition,ios::binary);
  228.  
  229.  
  230.  
  231. float *in2 = new float [num];
  232.  
  233. float *out2 = new float [num];
  234.  
  235. for(int line=0;line<height;line++)
  236.  
  237. {
  238.  
  239. for(int j=0;j<num;j++)
  240.  
  241. {
  242.  
  243. in2[j]=int(temp2[2*j+2*line*num])/16+16*int(temp2[2*j+1+2*line*num])-avgR[j];
  244.  
  245. }
  246.  
  247.  
  248.  
  249. for(int n=0;n<cali_num;n++)
  250.  
  251. {
  252.  
  253. if((cali2re[n]-int(cali2re[n]))==0)
  254.  
  255. out2[n]=in2[int(cali2re[n])];
  256.  
  257. else
  258.  
  259. out2[n]=in2[int(cali2re[n])]+(cali2re[n]-int(cali2re[n]))*(in2[int(cali2re[n])+1]-in2[int(cali2re[n])]);//(int(cali2re[n])+1-cali2re[n])*(pSignal2[int(cali2re[n])+1].re()-pSignal2[int(cali2re[n])].re()));
  260.  
  261. }
  262.  
  263. savespec.write((char*)ou
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty