Giter VIP home page Giter VIP logo

jitesh7 / pypylon-opencv-viewer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mbalatsko/pypylon-opencv-viewer

0.0 2.0 1.0 955 KB

Easy to use Jupyter notebook viewer connecting Basler Pylon images grabbing with OpenCV image processing. Allows to specify interactive Jupyter widgets to manipulate Basler camera features values, grab camera image and at once get an OpenCV window on which raw camera output is displayed or you can specify an image processing function, which takes on the input raw camera output image and display your own output.

License: MIT License

Python 100.00%

pypylon-opencv-viewer's Introduction

Basler PyPylon OpenCV viewer for Jupyter Notebook

PyPI version Downloads License: MIT

Easy to use Jupyter notebook viewer connecting Basler Pylon images grabbing with OpenCV image processing. Allows to specify interactive Jupyter widgets to manipulate Basler camera features values, grab camera image and at once get an OpenCV window on which raw camera output is displayed or you can specify an image processing function, which takes on the input raw camera output image and display your own output.

Installation

pip install pypylon-opencv-viewer

Usage

To start working, launch Jupyter notebook and connect to Basler camera. Here is an example how you can do it:

from pypylon import pylon 

# Pypylon get camera by serial number
serial_number = '22716154'
info = None
for i in pylon.TlFactory.GetInstance().EnumerateDevices():
    if i.GetSerialNumber() == serial_number:
        info = i
        break
else:
    print('Camera with {} serial number not found'.format(serial_number))

# VERY IMPORTANT STEP! To use Basler PyPylon OpenCV viewer you have to call .Open() method on you camera
if info is not None:
    camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateDevice(info))
    camera.Open()

Now we can start working with our viewer. Basically we need 3 things: connected camera, features we want to work with (you can find them in official Basler documentation, for now this library supports only boolean and numeric features) and image processing function we want to apply on grabbing images. Image processing function is not a requirement, you don't have to specify one, in this case you'll get raw camera output.

List of features

Features - list of dicts.

Dict structure:

  1. name - camera pylon feature name, example: "GainRaw" (required)
  2. type - widget input type, allowed values int, float, bool, int_text, float_text (optional, default: "int")
  3. value - widget input value (optional, default: current camera feature value)
  4. max - maximum widget input value, only numeric widget types (optional, default: camera feature max value)
  5. min - minimum widget input value, only numeric widget types (optional, default: camera feature min value)
  6. step - step of allowed input value (optional, default: camera feature increment, if not exist =1)

Example configuration you can see below:

# List of features to create wigets
features = [
    {
        "name": "GainRaw",
        "type": "int"
    },
    {
        "name": "Height",
        "type": "int_text",
        "max": 1000,
        "min": 100,
        "step": "5"
    },
    {
        "name": "Width",
        "type": "int_text",
        "max": 1000,
        "min": 100,
        "step": "5"
    },
    {
        "name": "AcquisitionFrameRateEnable",
        "type": "bool"
    },
    {
        "name": "AcquisitionFrameRateAbs",
        "type": "int",
        "max": 60,
        "min": 10
    }
]

Example image processing function

Just example image processing function, which negatives the image. Image has to be the only argument in it. If you want some image to be shown, you have to do it yourself inside the function. DON'T DESTROY ALL OpenCV windows or wait for key pressed in it.

import numpy as np
import cv2

def impro(img):
    cv2.namedWindow('1', cv2.WINDOW_NORMAL | cv2.WINDOW_GUI_NORMAL)
    cv2.resizeWindow('1', 1080, 720)
    cv2.imshow("1", np.hstack([img, (255-img)]))

Viewer

We have prepared all required parts. Now we just set them to the viewer object and launch image grabbing: run_interaction_continuous_shot for continuous or run_interaction_single_shot for single shot. Also you can press 'S' button to save raw camera image to image_folder.

from pypylon_opencv_viewer import BaslerOpenCVViewer
    
viewer = BaslerOpenCVViewer(camera)
viewer.set_features(features)
viewer.set_impro_function(impro)
viewer.run_interaction_continuous_shot(image_folder='~/Documents/images')

Now we see some similar image, we can setup camera features values. Push Run interaction to let it go. To close OpenCV windows just push 'Q' on your keyboard. You don't have to launch this cell once more to try the same procedure with the image, just change wanted values and push the button. That's it! Basler OpenCV viewer Basler OpenCV viewer

Save or get image from camera

In previous steps we set up camera features parameters using widgets. Now we can save camera image on disc or get raw openCV image.

# Save image
viewer.save_image('~/Documents/images/grabbed.png')

# Get grabbed image
img = viewer.get_image()

pypylon-opencv-viewer's People

Contributors

mbalatsko avatar

Watchers

 avatar  avatar

Forkers

geomags3

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.