1 | #include <cv.h>
|
2 | #include <highgui.h>
|
3 | #include <ctype.h>
|
4 | #include <stdio.h>
|
5 |
|
6 |
|
7 | // Pakete fuer debian/ubuntu etc.
|
8 | // libcv-dev + dependencies
|
9 | // libhighgui-dev + deps
|
10 | // libcvaux-dev + deps
|
11 |
|
12 | // compilieren mit
|
13 | //g++ -o bohrhilfe bohrhilfe.c `pkg-config --cflags --libs opencv`
|
14 |
|
15 |
|
16 | // entfernen fuer ein nicht gespiegeltes Bild:
|
17 | #define MIRROR_IMAGE
|
18 |
|
19 | #define CIRCLE_RADIUS 30
|
20 | #define CROSS_LENGTH 40
|
21 | #define CIRCLE_COLOR CV_RGB(0,0,250)
|
22 | #define CROSS_COLOR CV_RGB(250,100,100)
|
23 |
|
24 |
|
25 | //Koordinaten des Keuzes im Bild.
|
26 | CvPoint g_crosshair = {50,50};
|
27 |
|
28 | // callback-Funktion, die bei Maus-Events ueber dem Bild aufgerufen wird.
|
29 | void set_crosshair (int event, int x, int y, int flags, void *param)
|
30 | {
|
31 | if (event == CV_EVENT_LBUTTONDOWN)
|
32 | {
|
33 | g_crosshair.x = x;
|
34 | g_crosshair.y = y;
|
35 | }
|
36 | }
|
37 |
|
38 |
|
39 | int main (int argc, char **argv)
|
40 | {
|
41 | IplImage *img = NULL;
|
42 | CvCapture *capture = NULL;
|
43 |
|
44 | if (argc == 1 || (argc == 2 && strlen (argv[1]) == 1 && isdigit (argv[1][0])))
|
45 | capture = cvCaptureFromCAM (argc == 2 ? argv[1][0] - '0' : 0);
|
46 | else if (argc == 2)
|
47 | capture = cvCaptureFromAVI (argv[1]);
|
48 | if (!capture)
|
49 | {
|
50 | fprintf (stderr, "Could not initialize capturing...\n");
|
51 | return -1;
|
52 | }
|
53 |
|
54 | cvNamedWindow ("Bild", 0);
|
55 | cvSetMouseCallback ("Bild", set_crosshair, (void *) img);
|
56 |
|
57 | for (;;)
|
58 | {
|
59 | IplImage *frame = 0;
|
60 | frame = cvQueryFrame (capture);
|
61 | if (!frame)
|
62 | break;
|
63 | if (!img)
|
64 | img = cvCreateImage (cvSize(frame->width, frame->height), 8, 3);
|
65 |
|
66 | #ifdef MIRROR_IMAGE
|
67 | cvConvertImage (frame, img, CV_CVTIMG_FLIP);
|
68 | #else
|
69 | cvCopy (frame, img);
|
70 | #endif
|
71 |
|
72 | CvPoint a;
|
73 | a.x = g_crosshair.x - CROSS_LENGTH;
|
74 | a.y = g_crosshair.y;
|
75 |
|
76 | CvPoint b;
|
77 | b.x = g_crosshair.x + CROSS_LENGTH;
|
78 | b.y = g_crosshair.y;
|
79 |
|
80 | CvPoint c;
|
81 | c.x = g_crosshair.x;
|
82 | c.y = g_crosshair.y - CROSS_LENGTH;
|
83 |
|
84 | CvPoint d;
|
85 | d.x = g_crosshair.x;
|
86 | d.y = g_crosshair.y + CROSS_LENGTH;
|
87 |
|
88 | cvLine (img, a, b, CROSS_COLOR, 1);
|
89 | cvLine (img, c, d, CROSS_COLOR, 1);
|
90 | cvCircle (img, g_crosshair, CIRCLE_RADIUS, CIRCLE_COLOR, 1);
|
91 |
|
92 | cvShowImage ("Bild", img);
|
93 | if (cvWaitKey (10) >= 0)
|
94 | break;
|
95 | }
|
96 |
|
97 | cvReleaseCapture (&capture);
|
98 | cvDestroyWindow ("Bild");
|
99 | return 0;
|
100 | }
|