-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdist_at_focal_length.c
49 lines (35 loc) · 1022 Bytes
/
dist_at_focal_length.c
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
#include <stdio.h>
#include <glib.h>
#include <cv.h>
#include <highgui.h>
#include "koki.h"
int main(int argc, char** argv)
{
if (argc != 4){
printf("USAGE: %s <filename> <focal_length> <marker_width>\n", argv[0]);
return 1;
}
const char *filename = argv[1];
float focal_length = atof(argv[2]);
float marker_width = atof(argv[3]);
IplImage *frame = cvLoadImage(filename, CV_LOAD_IMAGE_GRAYSCALE);
assert(frame != NULL);
koki_t *koki = koki_new();
koki_camera_params_t params;
params.size.x = frame->width;
params.size.y = frame->height;
params.principal_point.x = params.size.x / 2;
params.principal_point.y = params.size.y / 2;
params.focal_length.x = focal_length;
params.focal_length.y = focal_length;
GPtrArray *markers = koki_find_markers(koki, frame, marker_width, ¶ms);
if (markers->len != 1){
return 1;
}
koki_marker_t *marker;
marker = g_ptr_array_index(markers, 0);
printf("%f\n", marker->distance);
koki_markers_free(markers);
cvReleaseImage(&frame);
return 0;
}