24 #include <core/exception.h>
25 #include <fvcams/leutron.h>
26 #include <fvutils/color/colorspaces.h>
35 namespace firevision {
42 LeutronCamera::LeutronCamera()
44 started = opened =
false;
47 cspace = YUV422_PACKED;
49 camera_name =
"PAL_S_CCIR";
53 LeutronCamera::~LeutronCamera()
61 camera_handle = HANDLE_INVALID;
67 if (DsyRecheckConnector() != I_NoError) {
68 throw Exception(
"LeutronCam: DsyRecheckConnector() failed");
71 LvCameraConnDlgInfo *info;
72 HANDLE conn_info_handle = NULL;
73 HGRABBER grabber_handle = HANDLE_INVALID;
75 if (DsyDetectCamera(&conn_info_handle) > 0) {
77 info = (LvCameraConnDlgInfo *)GlobalLock(conn_info_handle);
79 grabber = info[0].Grabber;
84 camera_id = info[0].CameraType;
87 LvCameraInfo cam_info;
88 for (
int i = 0; DsyEnumCameraType(i, &cam_info) == I_NoError; ++i) {
89 if (strcmp(camera_name, cam_info.Name) == 0) {
91 camera_id = cam_info.Id;
95 if (camera_id == -1) {
97 camera_id = info[0].CameraType;
101 if (grabber == NULL) {
102 throw Exception(
"LeutronCam: grabber == NULL");
104 grabber_handle = info[0].hGrabber;
105 if (grabber_handle == HANDLE_INVALID) {
106 throw Exception(
"LeutronCam: grabber handle is invalid.");
108 if (info[0].hConn == HANDLE_INVALID) {
109 throw Exception(
"LeutronCam: connection handle is invalid.");
111 camera_handle = grabber->ConnectCamera(camera_id, info[0].hConn, info[0].SyncNr);
112 if (camera_handle == HANDLE_INVALID) {
113 throw Exception(
"LeutronCam: Could not connect the camera");
117 camera = grabber->GetCameraPtr(camera_handle);
118 camera->GetDescription(tmp,
sizeof(tmp));
122 GlobalFree(conn_info_handle);
124 if (grabber->ActivateCamera(camera_handle) != DSY_I_NoError) {
125 throw Exception(
"LeutronCam: Could not activate camera");
128 LvSourceInfo src_info;
129 camera->GetSourceROI(&src_info);
133 if (camera->SetSourceROI(&src_info) != DSY_I_NoError) {
137 width = src_info.MaxWidth;
138 height = src_info.MaxHeight;
139 scaled_width = width;
140 scaled_height = height;
147 if ((scaled_width != width) || (scaled_height != height)) {
149 scaled_buffer = (
unsigned char *)malloc(
150 colorspace_buffer_size(YUV422_PACKED, scaled_width, scaled_height));
154 grabber->GetConnectionInfo(camera_handle, &roi);
155 roi.SetTargetBuffer(TgtBuffer_CPU);
156 roi.SetDIBMode(TRUE);
157 if (cspace != YUV422_PACKED) {
160 roi.SetColorFormat(ColF_YUV_422);
161 roi.SetStartPosition(0, 0);
162 roi.SetDimension(scaled_width, scaled_height);
163 roi.SetMemoryWidth(width);
172 if (grabber->ActivateROI(camera_handle, &roi) != DSY_I_NoError) {
173 throw Exception(
"LeutronCam: Cannot activate ROI");
176 camera->Live(SY_None);
179 throw Exception(
"LeutronCam: Could not get lock on connection info.");
183 throw Exception(
"LeutronCam: Could not find any camera.");
188 LeutronCamera::start()
193 throw Exception(
"LeutronCam: Trying to start closed cam!");
200 LeutronCamera::stop()
206 LeutronCamera::print_info()
211 LeutronCamera::capture()
216 LeutronCamera::flush()
221 LeutronCamera::buffer()
224 grabber->GetConnectionInfo(camera_handle, &roi);
226 if ((scaled_width != width) || (scaled_height != height)) {
227 unsigned char *r, *buf;
228 r = (
unsigned char *)roi.MemoryInfo.BaseAddress + roi.StartAddress;
230 for (
unsigned int i = 0; i < height; ++i) {
231 memcpy(buf, r, roi.GetPixelIncrement() * scaled_width);
232 buf += roi.GetPixelIncrement() * scaled_width;
233 r += roi.GetLineIncrement();
235 return scaled_buffer;
237 return (
unsigned char *)roi.MemoryInfo.BaseAddress + roi.StartAddress;
242 LeutronCamera::buffer_size()
244 return colorspace_buffer_size(YUV422_PACKED, 0, 0);
248 LeutronCamera::close()
251 if ((scaled_width != width) || (scaled_height != height)) {
261 LeutronCamera::dispose_buffer()
266 LeutronCamera::pixel_width()
271 throw Exception(
"LeutronCam: Camera not opened");
276 LeutronCamera::pixel_height()
279 return scaled_height;
281 throw Exception(
"LeutronCam: Camera not opened");
286 LeutronCamera::colorspace()
292 LeutronCamera::ready()
298 LeutronCamera::set_image_number(
unsigned int n)
Base class for exceptions in Fawkes.
Fawkes library namespace.