コード例 #1
0
static int ids_core_Camera_setauto_speed(ids_core_Camera *self, PyObject *value, void *closure) {
    int ret;
    double val;
    PyObject *exception;

    if (value == NULL) {
        PyErr_SetString(PyExc_TypeError, "Cannot delete attribute 'auto_speed'");
        return -1;
    }

    val = PyFloat_AsDouble(value);
    exception = PyErr_Occurred();
    if (exception) {
        PyErr_SetString(exception, "Auto speed must be a number");
        return -1;
    }

    /* is_SetAutoParameter() returns IS_NO_SUCCESS for out-of-range values ... */
    if (val < 0 || val > 100) {
        PyErr_SetString(PyExc_ValueError, "Auto speed out of range (0...100)");
        return -1;
    }

    ret = is_SetAutoParameter(self->handle, IS_SET_AUTO_SPEED, &val, NULL);
    switch (ret) {
    case IS_SUCCESS:
        return 0;
    case IS_INVALID_PARAMETER:
        PyErr_SetString(PyExc_ValueError, "Auto speed out of range (0..100)");
        break;
    default:
        raise_general_error(self, ret);
        return -1;
    }

    return -1;
}
コード例 #2
0
ファイル: svs_core_Camera.c プロジェクト: ncsuarc/svs
static int svs_core_Camera_init(svs_core_Camera *self, PyObject *args, PyObject *kwds) {
    static char *kwlist[] = {
        "ip", "source_ip", "buffer_count", "packet_size", "queue_length", NULL
    };

    const char *ip = NULL;
    const char *source_ip = NULL;
    unsigned int buffer_count = 10;
    unsigned int packet_size = 9000;
    uint32_t ip_num, source_ip_num;
    char *manufacturer, *model;
    int ret;

    self->main_thread = PyGILState_GetThisThreadState();
    self->ready = NOT_READY;
    TAILQ_INIT(&self->images);
    self->images_length = 0;
    self->images_max = 50;

    /*
     * This means the definition is:
     * def __init__(self, ip, source_ip, buffer_count=10, packet_size=9000,
     *              queue_length=50):
     */
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|III", kwlist,
                &ip, &source_ip, &buffer_count, &packet_size,
                &self->images_max)) {
        return -1;
    }

    ip_num = ip_string_to_int(ip);
    source_ip_num = ip_string_to_int(source_ip);

    ret = openCamera(&self->handle, ip_num, source_ip_num, HEARTBEAT_TIMEOUT);
    if (ret != SVGigE_SUCCESS) {
        raise_general_error(ret);
        return -1;
    }

    self->ready = CONNECTED;

    manufacturer = strdup(Camera_getManufacturerName(self->handle));
    if (!manufacturer) {
        PyErr_SetString(PyExc_MemoryError, "Unable to allocate name");
        return -1;
    }

    model = strdup(Camera_getModelName(self->handle));
    if (!model) {
        free(manufacturer);
        PyErr_SetString(PyExc_MemoryError, "Unable to allocate name");
        return -1;
    }

    self->name = PyBytes_FromFormat("%s %s", manufacturer, model);
    free(manufacturer);
    free(model);
    if (!self->name) {
        return -1;
    }

    self->ready = NAME_ALLOCATED;

    ret = Camera_getTimestampTickFrequency(self->handle, &self->tick_frequency);
    if (ret != SVGigE_SUCCESS) {
        raise_general_error(ret);
        return -1;
    }

    ret = Camera_getImagerWidth(self->handle, &self->width);
    if (ret != SVGigE_SUCCESS) {
        raise_general_error(ret);
        return -1;
    }

    ret = Camera_getImagerHeight(self->handle, &self->height);
    if (ret != SVGigE_SUCCESS) {
        raise_general_error(ret);
        return -1;
    }

    /* 12-bit pixel depth */
    self->depth = 12;
    ret = Camera_setPixelDepth(self->handle, SVGIGE_PIXEL_DEPTH_12);
    if (ret != SVGigE_SUCCESS) {
        raise_general_error(ret);
        return -1;
    }

    /* Image buffer size in bytes */
    ret = Camera_getBufferSize(self->handle, &self->buffer_size);
    if (ret != SVGigE_SUCCESS) {
        raise_general_error(ret);
        return -1;
    }

    /* Open stream */
    ret = addStream(self->handle, &self->stream, &self->stream_ip,
                    &self->stream_port, self->buffer_size, buffer_count,
                    packet_size, PACKET_RESEND_TIMEOUT,
                    svs_core_Camera_stream_callback, self);
    if (ret != SVGigE_SUCCESS) {
        raise_general_error(ret);
        return -1;
    }

    ret = enableStream(self->stream, 1);
    if (ret != SVGigE_SUCCESS) {
        raise_general_error(ret);
        return -1;
    }

    self->ready = READY;

    return 0;
}
コード例 #3
0
static int ids_core_Camera_setauto_white_balance(ids_core_Camera *self, PyObject *value, void *closure) {
    int ret;
    double val;
    UINT val2;

    if (value == NULL) {
        PyErr_SetString(PyExc_TypeError, "Cannot delete attribute 'auto_white_balance'");
        return -1;
    }

    if (!PyBool_Check(value)) {
        PyErr_SetString(PyExc_TypeError, "Auto white balance must be a bool.");
        return -1;
    }

    val = (value == Py_True) ? 1 : 0;
    val2 = (UINT) val;

    ret = is_SetAutoParameter(self->handle, IS_SET_ENABLE_AUTO_WHITEBALANCE, &val, NULL);
    switch (ret) {
    case IS_SUCCESS:
        break;
    default:
        goto err;
    }

    ret = is_AutoParameter(self->handle, IS_AWB_CMD_SET_ENABLE, &val2, sizeof(val2));
    switch (ret) {
    case IS_SUCCESS:
        break;
    default:
        goto err_reset_set_auto_param;
    }

    if (val2) {
        UINT nType = IS_AWB_COLOR_TEMPERATURE;
        ret = is_AutoParameter(self->handle, IS_AWB_CMD_SET_TYPE, (void*)&nType, sizeof(nType));
        switch (ret) {
        case IS_SUCCESS:
            break;
        default:
            goto err_reset_auto_param;
        }
    }

    if (val > 0) {
        self->autofeatures++;
    }
    else {
        self->autofeatures--;
    }

    return 0;

err_reset_auto_param:
    val2 = 0;
    is_AutoParameter(self->handle, IS_AWB_CMD_SET_ENABLE, &val2, sizeof(val2));
err_reset_set_auto_param:
    val = 0;
    is_SetAutoParameter(self->handle, IS_SET_ENABLE_AUTO_WHITEBALANCE, &val, NULL);
err:
    raise_general_error(self, ret);
    return -1;
}
コード例 #4
0
PyObject *ids_core_Camera_getinfo(ids_core_Camera *self, void *closure) {
    CAMINFO cam_info;
    SENSORINFO sensor_info;

    int ret = is_GetCameraInfo(self->handle, &cam_info);
    if (ret != IS_SUCCESS) {
        raise_general_error(self, ret);
        return NULL;
    }

    ret = is_GetSensorInfo(self->handle, &sensor_info);
    if (ret != IS_SUCCESS) {
        raise_general_error(self, ret);
        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);
    }

    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;
}