basler / pypylon-samples

BSD 3-Clause "New" or "Revised" License
42 stars 15 forks source link

Need help with Camera Configuration #6

Closed gitty889 closed 10 months ago

gitty889 commented 10 months ago

I am trying to save my images in 12bits but it saves in 8bit. Here's my code, please can you suggest what i am doing wrong?

from pypylon import pylon
import cv2
import numpy as np
import os
from datetime import datetime

camera = None

def initialize_camera():
    global camera
    camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
    camera.Open()
    # Set the pixel format to Mono 12
    camera.PixelFormat.Value = "Mono12"
    # Set the sensor bit depth mode to Manual
    camera.BslSensorBitDepthMode.Value = "Manual"
    # Set the sensor bit depth to 12 bit
    camera.BslSensorBitDepth.Value = "Bpp12"

I have the basler a2A1920-51gmPRO Operating System- Windows

thiesmoeller commented 10 months ago

Is the code, where you save the images missing?

gitty889 commented 10 months ago

Here is the function to capture and save image

def capture_and_save_image(base_folder):
    global camera
    date_folder = datetime.now().strftime("%Y-%m-%d")
    folder_path = os.path.join(base_folder, date_folder)
    os.makedirs(folder_path, exist_ok=True)
    file_path = os.path.join(folder_path, datetime.now().strftime("%Y%m%d_%H%M%S.bmp"))

    grab_result = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)
    if grab_result.GrabSucceeded():
        image = grab_result.Array
        cv2.imwrite(file_path, image)
    grab_result.Release()
    return file_path
thiesmoeller commented 10 months ago

I would use PNG to store 16bit images. Can you output

print(image.shape)

Before writing?