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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#include <stdlib.h>
#include <string.h>
#include <uca/uca-camera.h>
#include <uca/uca-plugin-manager.h>
UcaPluginManager *manager;
UcaCamera *camera;
static void
dispose (void)
{
g_object_unref (camera);
g_object_unref (manager);
}
static void
pass_or_die (GError *error)
{
if (error == NULL)
return;
g_print ("Error: %s\n", error->message);
dispose ();
exit (1);
}
static void
print_header (const gchar *header)
{
guint remaining;
remaining = 79 - strlen (header);
g_print ("%s ", header);
for (guint i = 0; i < remaining; i++)
g_print ("-");
g_print ("\n");
}
static void
check_roi_size (UcaCamera *camera, guint x, guint y, guint width, guint height, GError **error)
{
guint roi_height;
guint16 *frame;
g_object_set (camera, "roi-height", height, NULL);
g_object_get (camera, "roi-height", &roi_height, NULL);
if (height != roi_height) {
g_print (" Error: ROI is %u x %u pixels\n", width, roi_height);
return;
}
frame = g_malloc0 (2 * width * height);
uca_camera_start_recording (camera, error);
if (*error != NULL)
goto exit_check_roi_size;
for (guint i = 0; i < 30; i++) {
uca_camera_grab (camera, frame, error);
if (*error != NULL)
goto exit_check_roi_size;
}
uca_camera_stop_recording (camera, error);
if (*error != NULL)
goto exit_check_roi_size;
exit_check_roi_size:
g_free (frame);
}
static void
test_roi_change (UcaCamera *camera)
{
guint sensor_width;
guint sensor_height;
guint roi_width;
guint roi_height;
print_header ("Check different region-of-interest sizes");
g_object_get (camera,
"sensor-width", &sensor_width,
"sensor-height", &sensor_height,
"roi-width", &roi_width,
"roi-height", &roi_height,
NULL);
g_print (" Sensor size: %u x %u pixels\n", sensor_width, sensor_height);
for (roi_height = sensor_height; roi_height > 8; roi_height /= 2) {
GError *error = NULL;
g_print (" Test ROI %u x %u pixels: ", sensor_width, roi_height);
check_roi_size (camera, 0, 0, sensor_width, sensor_height, &error);
if (error == NULL) {
g_print ("PASS\n");
}
else {
g_print ("FAIL (%s)\n", error->message);
g_error_free (error);
}
}
}
int
main (int argc, char **argv)
{
GError *error = NULL;
manager = uca_plugin_manager_new ();
camera = uca_plugin_manager_get_camera (manager, "ufo", &error, NULL);
pass_or_die (error);
test_roi_change (camera);
dispose ();
}
|