/
cam.c
161 lines (127 loc) · 4.65 KB
/
cam.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* A collection of example applications for the LeanXcam platform.
Copyright (C) 2008 Supercomputing Systems AG
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*!@file cam.c
* @brief Camera module example.
* Demonstrates how to capture pictures using multiple buffers.
*/
#include "oscar/staging/inc/oscar.h"
#include <stdio.h>
/*********************************************************************//*!
* @brief Program entry.
*
* @param argc Command line argument count.
* @param argv Command line argument string.
* @return 0 on success
*//*********************************************************************/
int main(const int argc, const char * argv[])
{
/* Handle to framework instance. */
void *hFramework;
#if defined(OSC_HOST) || defined(OSC_SIM)
/* Handle to file name reader, if compiled for host platform. */
void *hFileNameReader;
#endif
/* Camera parameters */
uint32 shutterWidth;
uint16 x, y, width, height;
uint16 blackOffset;
uint8 bufferIDs[2];
/* Frame buffers. */
uint8 frameBuffer0[OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT];
uint8 frameBuffer1[OSC_CAM_MAX_IMAGE_WIDTH * OSC_CAM_MAX_IMAGE_HEIGHT];
/* Pointer to captured picture */
void *pic;
struct OSC_PICTURE p;
OSC_ERR err = SUCCESS;
/* Create framework */
OscCreate(&hFramework);
/* Load camera module */
OscCamCreate(hFramework);
/* Load GPIO module */
OscGpioCreate(hFramework);
p.width = OSC_CAM_MAX_IMAGE_WIDTH;
p.height = OSC_CAM_MAX_IMAGE_HEIGHT;
p.type = OSC_PICTURE_GREYSCALE;
/* Get camera settings */
OscCamGetShutterWidth(&shutterWidth);
OscCamGetAreaOfInterest(&x, &y, &width, &height);
OscCamGetBlackLevelOffset(&blackOffset);
printf("ShutterWidth=%lu\n",shutterWidth);
printf("AreaOfInterest: x=%u y=%u width=%u height=%u\n", x, y, width, height);
printf("BlackLevelOffset=%u\n",blackOffset);
/* Process settings */
/* ---------------- */
/* Set new camera settings */
shutterWidth = 50000; /* set shutter to 50ms, 0 => automatic */
OscCamSetShutterWidth(shutterWidth);
OscCamSetAreaOfInterest(0,0,OSC_CAM_MAX_IMAGE_WIDTH, OSC_CAM_MAX_IMAGE_HEIGHT);
OscCamSetBlackLevelOffset(blackOffset);
OscCamSetupPerspective(OSC_CAM_PERSPECTIVE_VERTICAL_MIRROR);
#if defined(OSC_HOST) || defined(OSC_SIM)
/* Setup file name reader if compiled for host platform */
OscFrdCreateConstantReader(&hFileNameReader, "imgCapture.bmp");
OscCamSetFileNameReader(hFileNameReader);
#endif
/* Setup framebuffers - double buffering */
OscCamSetFrameBuffer(0, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, frameBuffer0, TRUE);
OscCamSetFrameBuffer(1, OSC_CAM_MAX_IMAGE_WIDTH*OSC_CAM_MAX_IMAGE_HEIGHT, frameBuffer1, TRUE);
bufferIDs[0] = 0;
bufferIDs[1] = 1;
OscCamCreateMultiBuffer(2, bufferIDs);
/* Setup capture to first frame buffer */
err = OscCamSetupCapture(OSC_CAM_MULTI_BUFFER);
if(err != SUCCESS){
printf("%s: Unable to setup initial capture (%d)!\n", __func__, err);
return err;
}
/* Trigger image capturing */
err = OscGpioTriggerImage();
if(err != SUCCESS){
printf("%s: Unable to trigger capture (%d)!\n", __func__, err);
return err;
}
/* Do something ... */
/* ---------------- */
/* Read Picture */
err = OscCamReadPicture(OSC_CAM_MULTI_BUFFER, (void *) &pic, 0, 0);
if(err != SUCCESS){
printf("%s: Unable to read picture (%d)!\n", __func__, err);
return err;
}
/* Process picture */
/* --------------- */
/* Capture picture to second frame buffer */
err = OscCamSetupCapture(OSC_CAM_MULTI_BUFFER);
if(err != SUCCESS){
printf("%s: Unable to setup initial capture (%d)!\n", __func__, err);
return err;
}
/* Do something ... */
/* ---------------- */
err = OscCamReadPicture(OSC_CAM_MULTI_BUFFER, (void *) &pic, 0, 0);
if(err != SUCCESS){
printf("%s: Unable to read picture (%d)!\n", __func__, err);
return err;
}
/* Process picture */
/* --------------- */
/* Unload camera module */
OscCamDestroy(hFramework);
/* Unload GPIO module */
OscGpioDestroy(hFramework);
/* Destroy framework */
OscDestroy(hFramework);
return 0;
}