Bonjour, étant en stage, je me suis vu confier la création d'un programme de reconnaissance de formulaire. Pour cela j'ai utilisé OpenCV en C sous Code::Blocks. Ayant réussi le projet j'ai du en faire une dll pour l'intégrer dans leur projet qui lui est en Delphi. Mais voila pour la gestion d'erreur je dois faire appel à une variable globale que je déclare dans ma dll et rien n'y fait je n'arrive pas à l'utiliser.
Je vous montre grossièrement le code:
Donc voici la fonction main de la dll. et voici l'endroit ou j'appelle mes fonctions :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 #include "main.h" #include <stdio.h> #include <stdlib.h> #include "cv.h" #include "highgui.h" /*int DLL_EXPORT error;*/ char DLL_EXPORT *get_last_error() { if (error == 1) return ("Image introuvable ou corrompue\n"); if (error == 2) return ("Template introuvable ou corrompu\n"); } int DLL_EXPORT check_image(float seuil, LPCSTR templ, LPCSTR image) { float src_x; float src_y; double min_val = 0; double max_val = 0; int x; int y; IplImage *src; IplImage *logo; IplImage *result; CvPoint max_loc; CvPoint min_loc; src = cvLoadImage(image, CV_LOAD_IMAGE_GRAYSCALE); logo = cvLoadImage(templ, CV_LOAD_IMAGE_GRAYSCALE); if (src == NULL || logo == NULL) { if (src == NULL) error = 1; else error = 2; return (-1); } src_x = cvGetSize(src).width; src_y = cvGetSize(src).height; x = (int)src_x - cvGetSize(logo).width + 1; y = (int)src_y - cvGetSize(logo).height + 1; result = cvCreateImage(cvSize(x, y),IPL_DEPTH_32F, 1); cvMatchTemplate(src, logo, result, CV_TM_CCOEFF_NORMED); max_loc = cvPoint(0,0); min_loc = cvPoint(0,0); cvMinMaxLoc(result, &min_val, &max_val, &min_loc, &max_loc, 0); cvReleaseImage(&logo); cvReleaseImage(&src); cvReleaseImage(&result); if (max_val >= seuil) return(0); else return(1); } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } return TRUE; }
Les 2 ligne en commentaire sont les endroits ou j'essaie d'utiliser cette globale.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 #include <windows.h> #include <stdio.h> #include <stdlib.h> typedef int (__stdcall* check_image)(float seuil, LPCSTR templ, LPCSTR image); typedef char (__stdcall* get_last_error)(); /*typedef int (__stdcall* error);*/ int main() { int check = 0; int hnddll = 0; static int error = 0; check_image pSomeFunction; get_last_error pSomeError; if ((hnddll = (int)LoadLibrary("C:\\Documents and Settings\\ag\\Mes documents\\dll_formulaire\\bin\\release\\dll_formulaire.dll")) == NULL) { printf("dll not found\n"); return (-1); } pSomeFunction = (check_image) GetProcAddress((HINSTANCE)(hnddll), "check_image"); pSomeError = (get_last_error) GetProcAddress((HINSTANCE)(hnddll), "get_last_error"); if ((check = pSomeFunction(0.30000, "form1_vierges.JPG", "form1_rempli.JPG")) == 0) { printf("Formulaire 1\n"); return (0); } pSomeError(error); if ((check = pSomeFunction(0.30000, "form2_vierge.JPG", "form1_rempli.JPG")) == 0) { printf("Formulaire 2\n"); return (0); } if ((check = pSomeFunction(0.30000, "form3_vierge.JPG", "form1_rempli.JPG")) == 0) { printf("Formulaire 3\n"); return (0); } if ((check = pSomeFunction(0.30000, "form4_vierge.JPG", "form1_rempli.JPG")) == 0) { printf("Formulaire 4\n"); return (0); } if ((check = pSomeFunction(0.30000, "form5_vierge.JPG", "form1_rempli.JPG")) == 0) { printf("Formulaire 5\n"); return (0); } printf("Formulaire inexistant\n"); return (1); }
Je vous met le .h de la dll, on sait jamais :
Merci d'avance.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #ifndef __MAIN_H__ #define __MAIN_H__ #include <windows.h> #ifdef BUILD_DLL #define DLL_EXPORT __declspec(dllexport) #else #define DLL_EXPORT __declspec(dllimport) #endif #ifdef __cplusplus extern "C" { #endif int DLL_EXPORT check_image(float seuil, LPCSTR templ, LPCSTR image); char DLL_EXPORT *get_last_error(); #ifdef __cplusplus } #endif #endif // __MAIN_H__
Partager