Giter VIP home page Giter VIP logo

ximea's Introduction

ximea

A Bonsai library for interfacing with XIMEA cameras using the xiAPI

Application examples

How to create a custom operator

A custom operator can be useful to encapsulate custom initialization logic or to create a reusable component that can be shared with others. In this example, we will create a custom operator that initializes a XIMEA camera with a specific set of parameters and log them to disk. If using this script as an extension, remember to add the Ximea package to your Extensions.cproj file.

using System;
using System.ComponentModel;
using xiApi.NET;
using xiApi;
using System.Collections.Generic;
using System.Reactive;
using System.IO;
using System.Linq;

namespace Bonsai.Ximea
{
    [Description("Configures and initializes a custom instance of a XimeaCapture operator. It will set/get the specified settings and dump to a log file.")]
    public class CustomXimeaCapture : XimeaCapture
    {
        public string logFilePath = "log.txt";

        [Description("The name of the output log file.")]
        [Editor("Bonsai.Design.SaveFileNameEditor, Bonsai.Design", DesignTypes.UITypeEditor)]
        public string LogFilePath
        {
            get { return logFilePath; }
            set { logFilePath = value; }
        }

        protected override void Configure(xiCam camera)
        {
            //Set additional parameters
            try
            {
                camera.SetParam(PRM.SHUTTER_TYPE, SHUTTER_TYPE.SHUTTER_GLOBAL);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
            base.Configure(camera);

            //Query and export settings
            ExportSettings(camera, LogFilePath);
        }

        private static void ExportSettings(xiCam camera, string logFilePath)
        {
            var settings = new Dictionary<string, int>
            {
                {"Width", QueryParam(camera, PRM.WIDTH) },
                {"Height", QueryParam(camera, PRM.HEIGHT) },
                {"ShutterType", QueryParam(camera, PRM.SHUTTER_TYPE) },

            };
            File.WriteAllLines(logFilePath,
                settings.Select(x => x.Key + "," + x.Value).ToArray());
        }

        private static int QueryParam(xiCam camera, string prm)
        {
            camera.GetParam(prm, out int val);
            return val;
        }
    }
}

ximea's People

Contributors

bruno-f-cruz avatar glopesdev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.