24#include <core/exception.h>
25#include <fvcams/leutron.h>
26#include <fvutils/color/colorspaces.h>
44 started = opened =
false;
47 cspace = YUV422_PACKED;
49 camera_name =
"PAL_S_CCIR";
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.");
193 throw Exception(
"LeutronCam: Trying to start closed cam!");
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;
244 return colorspace_buffer_size(YUV422_PACKED, 0, 0);
251 if ((scaled_width != width) || (scaled_height != height)) {
271 throw Exception(
"LeutronCam: Camera not opened");
279 return scaled_height;
281 throw Exception(
"LeutronCam: Camera not opened");
Base class for exceptions in Fawkes.
virtual void close()
Close camera.
virtual void print_info()
Print out camera information.
virtual void set_image_number(unsigned int n)
Set image number to retrieve.
virtual ~LeutronCamera()
Destructor.
virtual colorspace_t colorspace()
Colorspace of returned image.
virtual unsigned char * buffer()
Get access to current image buffer.
virtual bool ready()
Camera is ready for taking pictures.
virtual unsigned int buffer_size()
Size of buffer.
virtual void start()
Start image transfer from the camera.
virtual unsigned int pixel_width()
Width of image in pixels.
LeutronCamera()
Constructor.
virtual void dispose_buffer()
Dispose current buffer.
virtual void flush()
Flush image queue.
virtual void stop()
Stop image transfer from the camera.
virtual void capture()
Capture an image.
virtual void open()
Open the camera.
virtual unsigned int pixel_height()
Height of image in pixels.
Fawkes library namespace.