ScriptContours.cpp (Détection optimale des contours)

1  /***********************************************************************************  
2      ImAnalyse : software in image processing and image analysis 
3     
4      Copyright (C) 27 avril 2008  <Vincent MORARD> 
5    Version: 2.0 
6      Contact: vincent<POINT>morard<AROBAS>cpe<POINT>fr 
7    Website: http://pistol.petesampras.free.fr 
8   
9      This program is free software: you can redistribute it and/or modify 
10      it under the terms of the GNU General Public License as published by 
11      the Free Software Foundation, either version 3 of the License, or 
12      (at your option) any later version. 
13   
14      This program is distributed in the hope that it will be useful, 
15      but WITHOUT ANY WARRANTY; without even the implied warranty of 
16      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
17      GNU General Public License for more details. 
18   
19      You should have received a copy of the GNU General Public License 
20      along with this program.  If not, see <http://www.gnu.org/licenses/ 
21  **********************************************************************************/ 
22   
23  #include "../CImage.h" 
24  #include "../DlgCallback.h" 
25  void Message10(HWND hList,HWND hDlg,char *Mes,int Buf) 
26  { 
27    SendMessage(hList,LB_ADDSTRING, 0, (LPARAM)Mes); 
28    SendMessage(hDlg,WM_UPDATE,Buf,0); 
29    Sleep(200); 
30  } 
31   
32   
33  DWORD WINAPI DetectionOpt_1(LPVOID lpParam ) 
34  { 
35    HWND hDlg,hOK,hwndList; 
36   
37   
38    hDlg=(HWND) lpParam; 
39   
40    hwndList=GetDlgItem(hDlg, IDC_LIST1); 
41    hOK=GetDlgItem(hDlg, IDOK); 
42   
43    int t = GetTickCount();  //initialisation du temps 
44   
45    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)"Début du traitement"); 
46   
47    char szExe[_MAX_PATH],*Q=szExe; 
48    GetModuleFileName(NULL,szExe,_MAX_PATH); 
49    while(*Q!=0)Q++; 
50    while(*Q!='\\')Q--;*Q=0; 
51    strcat(szExe,"\\monnaie.jpg"); 
52    if(Img[0].LoadJPG_GIF(szExe)==0)return 0; 
53   
54    Message10(hwndList,hDlg,"Ouverture de l'image : Fait",0); 
55    Img[0].BruitUniforme(100); 
56    if(Img[0].LaplaceI(GRAY,&Img[1])==0)return 0; 
57    Message10(hwndList,hDlg,"Laplace v4 : Fait",1); 
58   
59    if(Img[0].Sobel(GRAY,&Img[2])==0)return 0; 
60    Message10(hwndList,hDlg,"Laplace v8 : Fait",2); 
61   
62    if(Img[0].Prewitt(GRAY,&Img[3])==0)return 0; 
63    Message10(hwndList,hDlg,"Prewitt : Fait",3); 
64   
65    if(Img[0].Sobel(GRAY,&Img[4])==0)return 0; 
66    Message10(hwndList,hDlg,"Sobel : Fait",4); 
67   
68    if(Img[0].Canny(&Img[5])==0)return 0; 
69    Message10(hwndList,hDlg,"Canny : Fait",5); 
70   
71    if(Img[0].ShenCastan(&Img[6])==0)return 0; 
72    Message10(hwndList,hDlg,"Shen-Castan : Fait",6); 
73   
74    if(Img[0].Deriche(&Img[7])==0)return 0; 
75    Message10(hwndList,hDlg,"Deriche : Fait",7); 
76   
77    if(Img[0].SobelOptimal(&Img[8])==0)return 0; 
78    Message10(hwndList,hDlg,"Sobel optimal : Fait",8); 
79   
80   
81    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)"Fin du traitement, temps (ms) "); 
82    t = GetTickCount() - t; 
83    char Buf[20]; 
84    strcpy(Buf,itoa(t,Buf,10)); 
85    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)Buf); 
86   
87    EnableWindow(hOK,TRUE); 
88    return 1; 
89   
90  } 
91  DWORD WINAPI DetectionOpt_2(LPVOID lpParam ) 
92  { 
93    HWND hDlg,hOK,hwndList; 
94   
95   
96    hDlg=(HWND) lpParam; 
97   
98    hwndList=GetDlgItem(hDlg, IDC_LIST1); 
99    hOK=GetDlgItem(hDlg, IDOK); 
100   
101    int t = GetTickCount();  //initialisation du temps 
102   
103    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)"Début du traitement"); 
104   
105    char szExe[_MAX_PATH],*Q=szExe; 
106    GetModuleFileName(NULL,szExe,_MAX_PATH); 
107    while(*Q!=0)Q++; 
108    while(*Q!='\\')Q--;*Q=0; 
109    strcat(szExe,"\\contours2.jpg"); 
110    if(Img[0].LoadJPG_GIF(szExe)==0)return 0; 
111   
112    Message10(hwndList,hDlg,"Ouverture de l'image : Fait",0); 
113    //Img[0].BruitUniforme(100); 
114    if(Img[0].LaplaceI(GRAY,&Img[1])==0)return 0; 
115    Message10(hwndList,hDlg,"Laplace v4 : Fait",1); 
116   
117    if(Img[0].Sobel(GRAY,&Img[2])==0)return 0; 
118    Message10(hwndList,hDlg,"Laplace v8 : Fait",2); 
119   
120    if(Img[0].Prewitt(GRAY,&Img[3])==0)return 0; 
121    Message10(hwndList,hDlg,"Prewitt : Fait",3); 
122   
123    if(Img[0].Sobel(GRAY,&Img[4])==0)return 0; 
124    Message10(hwndList,hDlg,"Sobel : Fait",4); 
125   
126    if(Img[0].Canny(&Img[5])==0)return 0; 
127    Message10(hwndList,hDlg,"Canny : Fait",5); 
128   
129    if(Img[0].ShenCastan(&Img[6])==0)return 0; 
130    Message10(hwndList,hDlg,"Shen-Castan : Fait",6); 
131   
132    if(Img[0].Deriche(&Img[7])==0)return 0; 
133    Message10(hwndList,hDlg,"Deriche : Fait",7); 
134   
135    if(Img[0].SobelOptimal(&Img[8])==0)return 0; 
136    Message10(hwndList,hDlg,"Sobel optimal : Fait",8); 
137   
138    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)"Fin du traitement, temps (ms) "); 
139    t = GetTickCount() - t; 
140    char Buf[20]; 
141    strcpy(Buf,itoa(t,Buf,10)); 
142    SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)Buf); 
143   
144    EnableWindow(hOK,TRUE); 
145    return 1; 
146   
147  } 

lien1 lien2 lien3