Giter Site home page Giter Site logo

Saving converted image about pypylon HOT 4 CLOSED

basler avatar basler commented on August 24, 2024 1
Saving converted image

from pypylon.

Comments (4)

HenningHolmDE avatar HenningHolmDE commented on August 24, 2024 2

This is how I managed to convert BayerBG8 to RGB and save images using Imageio (since I mostly work with NumPy arrays), maybe this helps you guys:

from pypylon import pylon
import imageio

# create InstantCamera and grab image
camera = pylon.InstantCamera(
    pylon.TlFactory.GetInstance().CreateFirstDevice())
grab_result = camera.GrabOne(1000)

# create NumPy array from BayerBG8 grab result
# and save Bayer raw image as grayscale BMP
image_bayer = grab_result.GetArray()
imageio.imsave('image_bayer.bmp', image_bayer)

# create and configure ImageFormatConverter
converter = pylon.ImageFormatConverter()
converter.OutputPixelFormat = pylon.PixelType_RGB8packed

# convert image to RGB, create NumPy array
# and save RGB image as color BMP
converted = converter.Convert(grab_result)
image_rgb = converted.GetArray()
imageio.imsave('image_rgb.bmp', image_rgb)

from pypylon.

asavpatel92 avatar asavpatel92 commented on August 24, 2024 1

ok so I got it to work using cv2. choose cv2 Bayer type based on your camera pixel format.
mine was PixelType_BayerGR12 so I am using COLOR_BayerGR2BGR.

import numpy as np
import cv2

raw_np = np.fromfile(img_path)
raw_img = np.ndarray((IMAGE_HEIGHT, IMAGE_WIDTH), dtype=np.uint16, buffer=raw_np)
debayered_img = cv2.cvtColor(raw_img, cv2.COLOR_BayerGR2BGR)

Now one thing to note here is. debayered image in my case is a 16 bit image. but pixel values are 12 bit.
so image would look really dark. if you choose to convert it to 16 bit just multiply it by 2**4

from pypylon.

asavpatel92 avatar asavpatel92 commented on August 24, 2024

I also have exact same question. I currently use

img_result.GetArray(raw=True).tofile('out_raw_img')

but I am afraid that I have lost all grab result attributes of the image for the images I have saved for quite sometime now. I now want to use image converter on those files but it doesn't work on raw files. 😞

from pypylon.

asavpatel92 avatar asavpatel92 commented on August 24, 2024

@derFRUST conversion is fine if you have access to GrabResult object.
in my case I don't have GrabResult object available. because I stored raw frame on the disk using img_result.GetArray(raw=True).tofile('out_raw_img').
now I want to debayer that raw frame from disk.

from pypylon.

Related Issues (20)

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.