-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
93 lines (74 loc) · 1.57 KB
/
main.c
File metadata and controls
93 lines (74 loc) · 1.57 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "defines.h"
CvCapture* initCV();
void go();
int main()
{
CvCapture *capture = initCV();
if(!capture){
return -1;
}
// cvNamedWindow("ANAGRAMME",0);
Position hand, oldhand, temphand;
char c;
SDL_Surface *ecran = init_sdl(LARGEUR/COMPRESSION, HAUTEUR/COMPRESSION);
SDL_ShowCursor(0);
// Clear surface
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
go();
SDL_Event event;
while (c != 'q')
{
SDL_PollEvent(&event);
if(event.type == SDL_KEYDOWN){
switch(event.key.keysym.sym){
case SDLK_c:
c = 'c';
break;
case SDLK_q:
c = 'q';
break;
default:
c = 0;
break;
}
}
if(c == 'c'){
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
c = 0;
}
// Swap main surface buffers
SDL_Flip(ecran);
temphand = findGreenDot(capture);
if(temphand.x + temphand.y < 0){
oldhand = temphand;
//printf("%d,%d\n", oldhand.x, oldhand.y);
continue;
}
if(oldhand.x + oldhand.y < 0){
oldhand = temphand;
}
else{
oldhand = hand;
}
hand = temphand;
drawTrace(oldhand, hand, ecran);
}
exit_sdl(ecran);
cvReleaseCapture(&capture);
return 0;
}
CvCapture* initCV(){
CvCapture *capture = cvCreateCameraCapture(0);
if(!capture){
return NULL;
}
cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_WIDTH,LARGEUR);
cvSetCaptureProperty(capture,CV_CAP_PROP_FRAME_HEIGHT,HAUTEUR);
return capture;
}
void go(){
SDL_Event event;
do{
SDL_PollEvent(&event);
}while(!(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_SPACE));
}