Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Compile IDS Python wrapper under Windows #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions ids_core/ids_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ static void timestamp_to_utc(UEYETIME *timestamp, struct tm *dest) {
PyObject *image_info(ids_core_Camera *self, int image_id) {
UEYEIMAGEINFO image_info;
struct tm utc_timestamp;
PyObject *info, *device_timestamp, *timestamp, *digital_input;
PyObject *gpio1, *gpio2;
PyObject *frame_number, *camera_buffers, *used_camera_buffers;
PyObject *height, *width;

int ret = is_GetImageInfo(self->handle, image_id, &image_info, sizeof(image_info));
switch (ret) {
Expand All @@ -183,27 +187,27 @@ PyObject *image_info(ids_core_Camera *self, int image_id) {

timestamp_to_utc(&image_info.TimestampSystem, &utc_timestamp);

PyObject *info = PyDict_New();
info = PyDict_New();

PyObject *device_timestamp =
device_timestamp =
Py_BuildValue("K", image_info.u64TimestampDevice);
PyObject *timestamp = /* Assume milliseconds don't change across timezone */
timestamp = /* Assume milliseconds don't change across timezone */
PyDateTime_FromDateAndTime(utc_timestamp.tm_year + 1900,
utc_timestamp.tm_mon + 1,
utc_timestamp.tm_mday,
utc_timestamp.tm_hour,
utc_timestamp.tm_min,
utc_timestamp.tm_sec,
1000*image_info.TimestampSystem.wMilliseconds);
PyObject *digital_input = Py_BuildValue("I", image_info.dwIoStatus&4);
PyObject *gpio1 = Py_BuildValue("I", image_info.dwIoStatus&2);
PyObject *gpio2 = Py_BuildValue("I", image_info.dwIoStatus&1);
PyObject *frame_number = Py_BuildValue("K", image_info.u64FrameNumber);
PyObject *camera_buffers = Py_BuildValue("I", image_info.dwImageBuffers);
PyObject *used_camera_buffers =
digital_input = Py_BuildValue("I", image_info.dwIoStatus&4);
gpio1 = Py_BuildValue("I", image_info.dwIoStatus&2);
gpio2 = Py_BuildValue("I", image_info.dwIoStatus&1);
frame_number = Py_BuildValue("K", image_info.u64FrameNumber);
camera_buffers = Py_BuildValue("I", image_info.dwImageBuffers);
used_camera_buffers =
Py_BuildValue("I", image_info.dwImageBuffersInUse);
PyObject *height = Py_BuildValue("I", image_info.dwImageHeight);
PyObject *width = Py_BuildValue("I", image_info.dwImageWidth);
height = Py_BuildValue("I", image_info.dwImageHeight);
width = Py_BuildValue("I", image_info.dwImageWidth);

PyDict_SetItemString(info, "device_timestamp", device_timestamp);
PyDict_SetItemString(info, "timestamp", timestamp);
Expand Down
3 changes: 2 additions & 1 deletion ids_core/ids_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define IDS_H_INCLUDED

#include <sys/queue.h>
#include <stdint.h>

/* Module methods */
extern PyMethodDef ids_coreMethods[];
Expand All @@ -15,7 +16,7 @@ struct allocated_mem {

/* Camera class */
typedef struct {
PyObject_HEAD;
PyObject_HEAD
/* Externally available elements (in Python) */
HIDS handle;
uint32_t width;
Expand Down
3 changes: 2 additions & 1 deletion ids_core/ids_core_Camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ static int init_cam_info(ids_core_Camera *self) {

static int ids_core_Camera_init(ids_core_Camera *self, PyObject *args, PyObject *kwds) {
static char *kwlist[] = {"handle", "color", NULL};
int ret;
self->handle = 0;
self->bitdepth = 0;
self->color = IS_CM_RGB8_PACKED;
Expand All @@ -168,7 +169,7 @@ static int ids_core_Camera_init(ids_core_Camera *self, PyObject *args, PyObject
return -1;
}

int ret = is_InitCamera(&self->handle, NULL);
ret = is_InitCamera(&self->handle, NULL);
switch (ret) {
case IS_SUCCESS:
break;
Expand Down
247 changes: 126 additions & 121 deletions ids_core/ids_core_Camera_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
PyObject *ids_core_Camera_getinfo(ids_core_Camera *self, void *closure) {
CAMINFO cam_info;
SENSORINFO sensor_info;
PyObject *dict;

int ret = is_GetCameraInfo(self->handle, &cam_info);
if (ret != IS_SUCCESS) {
Expand All @@ -47,127 +48,128 @@ PyObject *ids_core_Camera_getinfo(ids_core_Camera *self, void *closure) {
return NULL;
}

PyObject *dict = PyDict_New();

PyObject *serial_num = PyBytes_FromString(cam_info.SerNo);
PyObject *manufacturer = PyBytes_FromString(cam_info.ID);
PyObject *hw_version = PyBytes_FromString(cam_info.Version);
PyObject *manufacture_date = PyBytes_FromString(cam_info.Date);
PyObject *id = Py_BuildValue("B", cam_info.Select);
PyObject *sensor_id = Py_BuildValue("H", sensor_info.SensorID);
PyObject *sensor_name = PyBytes_FromString(sensor_info.strSensorName);
PyObject *max_width = Py_BuildValue("I", sensor_info.nMaxWidth);
PyObject *max_height = Py_BuildValue("I", sensor_info.nMaxHeight);
PyObject *pixel_size = Py_BuildValue("d", sensor_info.wPixelSize/100.0);

PyObject *type;
switch (cam_info.Type) {
case IS_CAMERA_TYPE_UEYE_USB_SE:
type = PyBytes_FromString("USB uEye SE or RE");
break;
case IS_CAMERA_TYPE_UEYE_USB_ME:
type = PyBytes_FromString("USB uEye ME");
break;
case IS_CAMERA_TYPE_UEYE_USB_LE:
type = PyBytes_FromString("USB uEye LE");
break;
case IS_CAMERA_TYPE_UEYE_USB3_CP:
type = PyBytes_FromString("USB 3 uEye CP");
break;
case IS_CAMERA_TYPE_UEYE_ETH_HE:
type = PyBytes_FromString("GigE uEye HE");
break;
case IS_CAMERA_TYPE_UEYE_ETH_SE:
type = PyBytes_FromString("GigE uEye SE or RE");
break;
case IS_CAMERA_TYPE_UEYE_ETH_LE:
type = PyBytes_FromString("GigE uEye LE");
break;
case IS_CAMERA_TYPE_UEYE_ETH_CP:
type = PyBytes_FromString("GigE uEye CP");
break;
default:
type = PyBytes_FromString("Unknown");
}

PyObject *color_mode;
switch (sensor_info.nColorMode) {
case IS_COLORMODE_BAYER:
color_mode = PyBytes_FromString("Bayer");
break;
case IS_COLORMODE_MONOCHROME:
color_mode = PyBytes_FromString("Monochrome");
break;
case IS_COLORMODE_CBYCRY:
color_mode = PyBytes_FromString("CBYCRY");
break;
default:
color_mode = PyBytes_FromString("Unknown");
}

PyDict_SetItemString(dict, "serial_num", serial_num);
PyDict_SetItemString(dict, "manufacturer", manufacturer);
PyDict_SetItemString(dict, "hw_version", hw_version);
PyDict_SetItemString(dict, "manufacture_date", manufacture_date);
PyDict_SetItemString(dict, "id", id);
PyDict_SetItemString(dict, "sensor_id", sensor_id);
PyDict_SetItemString(dict, "sensor_name", sensor_name);
PyDict_SetItemString(dict, "max_width", max_width);
PyDict_SetItemString(dict, "max_height", max_height);
PyDict_SetItemString(dict, "type", type);
PyDict_SetItemString(dict, "color_mode", color_mode);
PyDict_SetItemString(dict, "pixel_size", pixel_size); /* in um */

/* Gains */
if (sensor_info.bMasterGain) {
PyDict_SetItemString(dict, "master_gain", Py_True);
}
else {
PyDict_SetItemString(dict, "master_gain", Py_False);
dict = PyDict_New();
{
PyObject *serial_num = PyBytes_FromString(cam_info.SerNo);
PyObject *manufacturer = PyBytes_FromString(cam_info.ID);
PyObject *hw_version = PyBytes_FromString(cam_info.Version);
PyObject *manufacture_date = PyBytes_FromString(cam_info.Date);
PyObject *id = Py_BuildValue("B", cam_info.Select);
PyObject *sensor_id = Py_BuildValue("H", sensor_info.SensorID);
PyObject *sensor_name = PyBytes_FromString(sensor_info.strSensorName);
PyObject *max_width = Py_BuildValue("I", sensor_info.nMaxWidth);
PyObject *max_height = Py_BuildValue("I", sensor_info.nMaxHeight);
PyObject *pixel_size = Py_BuildValue("d", sensor_info.wPixelSize/100.0);
PyObject *type;
PyObject *color_mode;

switch (cam_info.Type) {
case IS_CAMERA_TYPE_UEYE_USB_SE:
type = PyBytes_FromString("USB uEye SE or RE");
break;
case IS_CAMERA_TYPE_UEYE_USB_ME:
type = PyBytes_FromString("USB uEye ME");
break;
case IS_CAMERA_TYPE_UEYE_USB_LE:
type = PyBytes_FromString("USB uEye LE");
break;
case IS_CAMERA_TYPE_UEYE_USB3_CP:
type = PyBytes_FromString("USB 3 uEye CP");
break;
case IS_CAMERA_TYPE_UEYE_ETH_HE:
type = PyBytes_FromString("GigE uEye HE");
break;
case IS_CAMERA_TYPE_UEYE_ETH_SE:
type = PyBytes_FromString("GigE uEye SE or RE");
break;
case IS_CAMERA_TYPE_UEYE_ETH_LE:
type = PyBytes_FromString("GigE uEye LE");
break;
case IS_CAMERA_TYPE_UEYE_ETH_CP:
type = PyBytes_FromString("GigE uEye CP");
break;
default:
type = PyBytes_FromString("Unknown");
}

switch (sensor_info.nColorMode) {
case IS_COLORMODE_BAYER:
color_mode = PyBytes_FromString("Bayer");
break;
case IS_COLORMODE_MONOCHROME:
color_mode = PyBytes_FromString("Monochrome");
break;
case IS_COLORMODE_CBYCRY:
color_mode = PyBytes_FromString("CBYCRY");
break;
default:
color_mode = PyBytes_FromString("Unknown");
}

PyDict_SetItemString(dict, "serial_num", serial_num);
PyDict_SetItemString(dict, "manufacturer", manufacturer);
PyDict_SetItemString(dict, "hw_version", hw_version);
PyDict_SetItemString(dict, "manufacture_date", manufacture_date);
PyDict_SetItemString(dict, "id", id);
PyDict_SetItemString(dict, "sensor_id", sensor_id);
PyDict_SetItemString(dict, "sensor_name", sensor_name);
PyDict_SetItemString(dict, "max_width", max_width);
PyDict_SetItemString(dict, "max_height", max_height);
PyDict_SetItemString(dict, "type", type);
PyDict_SetItemString(dict, "color_mode", color_mode);
PyDict_SetItemString(dict, "pixel_size", pixel_size); /* in um */

/* Gains */
if (sensor_info.bMasterGain) {
PyDict_SetItemString(dict, "master_gain", Py_True);
}
else {
PyDict_SetItemString(dict, "master_gain", Py_False);
}

if (sensor_info.bRGain) {
PyDict_SetItemString(dict, "red_gain", Py_True);
}
else {
PyDict_SetItemString(dict, "red_gain", Py_False);
}

if (sensor_info.bGGain) {
PyDict_SetItemString(dict, "green_gain", Py_True);
}
else {
PyDict_SetItemString(dict, "green_gain", Py_False);
}

if (sensor_info.bBGain) {
PyDict_SetItemString(dict, "blue_gain", Py_True);
}
else {
PyDict_SetItemString(dict, "blue_gain", Py_False);
}

/* Global shutter, rolling if false */
if (sensor_info.bGlobShutter) {
PyDict_SetItemString(dict, "global_shutter", Py_True);
}
else {
PyDict_SetItemString(dict, "global_shutter", Py_False);
}

Py_DECREF(serial_num);
Py_DECREF(manufacturer);
Py_DECREF(hw_version);
Py_DECREF(manufacture_date);
Py_DECREF(id);
Py_DECREF(sensor_id);
Py_DECREF(sensor_name);
Py_DECREF(max_width);
Py_DECREF(max_height);
Py_DECREF(type);
Py_DECREF(color_mode);
Py_DECREF(pixel_size);
}

if (sensor_info.bRGain) {
PyDict_SetItemString(dict, "red_gain", Py_True);
}
else {
PyDict_SetItemString(dict, "red_gain", Py_False);
}

if (sensor_info.bGGain) {
PyDict_SetItemString(dict, "green_gain", Py_True);
}
else {
PyDict_SetItemString(dict, "green_gain", Py_False);
}

if (sensor_info.bBGain) {
PyDict_SetItemString(dict, "blue_gain", Py_True);
}
else {
PyDict_SetItemString(dict, "blue_gain", Py_False);
}

/* Global shutter, rolling if false */
if (sensor_info.bGlobShutter) {
PyDict_SetItemString(dict, "global_shutter", Py_True);
}
else {
PyDict_SetItemString(dict, "global_shutter", Py_False);
}

Py_DECREF(serial_num);
Py_DECREF(manufacturer);
Py_DECREF(hw_version);
Py_DECREF(manufacture_date);
Py_DECREF(id);
Py_DECREF(sensor_id);
Py_DECREF(sensor_name);
Py_DECREF(max_width);
Py_DECREF(max_height);
Py_DECREF(type);
Py_DECREF(color_mode);
Py_DECREF(pixel_size);

return dict;
}

Expand Down Expand Up @@ -395,6 +397,9 @@ static PyObject *ids_core_Camera_getauto_exposure(ids_core_Camera *self, void *c
}

static int ids_core_Camera_setauto_exposure(ids_core_Camera *self, PyObject *value, void *closure) {
double val;
int ret;

if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "Cannot delete attribute 'auto_exposure'");
return -1;
Expand All @@ -405,9 +410,9 @@ static int ids_core_Camera_setauto_exposure(ids_core_Camera *self, PyObject *val
return -1;
}

double val = (value == Py_True) ? 1 : 0;
val = (value == Py_True) ? 1 : 0;

int ret = is_SetAutoParameter(self->handle, IS_SET_ENABLE_AUTO_SHUTTER, &val, NULL);
ret = is_SetAutoParameter(self->handle, IS_SET_ENABLE_AUTO_SHUTTER, &val, NULL);
switch (ret) {
case IS_SUCCESS:
if (val > 0) {
Expand Down
Loading