question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't set exposure time

See original GitHub issue

Hello, I installed pypylon using pypylon-1.6.0-cp37-cp37m-linux_armv7l.whl I tested it with the code below but I get an error related to the exposure time

from pypylon import pylon
import time
import cv2

# conecting to the first available camera
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
camera.Open()
camera.Gain = camera.Gain.Max
camera.ExposureTime.setValue(camera.ExposureTime.Min)
# Grabing Continusely (video) with minimal delay
camera.StartGrabbing(pylon.GrabStrategy_LatestImageOnly)
converter = pylon.ImageFormatConverter()
# converting to opencv bgr format
converter.OutputPixelFormat = pylon.PixelType_BGR8packed
converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
start = time.time()
counter = 0
while camera.IsGrabbing():
    grabResult: pylon.GrabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)

    if grabResult.GrabSucceeded():
        # Access the image data
        image = converter.Convert(grabResult)
        img = image.GetArray()
        counter += 1
        elapsed = time.time() - start
        cv2.putText(img, "{} FPS".format(int(counter / elapsed)), (200, 20),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
        cv2.imshow('title', img)
        k = cv2.waitKey(1)
        if k == 27:
            break
    grabResult.Release()

# Releasing the resource
camera.StopGrabbing()
camera.close()

cv2.destroyAllWindows()

the error:

camera.ExposureTime.setValue(camera.ExposureTime.Min)
AttributeError: 'IFloat' object has no attribute 'setValue'

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
thiesmoellercommented, Nov 4, 2020
from pypylon import pylon
import time
import cv2
import queue

# connecting to the first available camera
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
camera.Open()


# if available choose a format that is
# computationally inexpensive to convert to your desired output format
camera.PixelFormat = "BGR8"
# or the YUV formats

class CaptureConvert(pylon.ImageEventHandler):
    def __init__(self):
        super().__init__()
        # converting to opencv bgr format
        self.converter = pylon.ImageFormatConverter()
        self.converter.OutputPixelFormat = pylon.PixelType_BGR8packed
        self.converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned

        self.video_queue = queue.Queue(maxsize=2)

    def OnImageGrabbed(self, cam, grab_result):
        if grab_result.GrabSucceeded():
            image = self.converter.Convert(grab_result)
            try:
                self.video_queue.put_nowait(image.GetArray())
            except queue.Full:
                # if queue depth > 2 your display thread is too slow
                # try limiting the camera framerate or use faster display framework
                print("consumer thread too slow frame:", grab_result.FrameNumber)


# register the background handler
capture = CaptureConvert()

camera.RegisterImageEventHandler(capture, pylon.RegistrationMode_ReplaceAll, pylon.Cleanup_None)

# start grabbing using background pylon thread
camera.StartGrabbing(pylon.GrabStrategy_LatestImageOnly, pylon.GrabLoop_ProvidedByInstantCamera)

start_time = time.time()
counter = 0
fps_real = camera.ResultingFrameRate.Value
fps_measured = 0

while camera.IsGrabbing():
    # Access the image data
    img = capture.video_queue.get(timeout=5000)

    # fps display measured over 1s run
    counter += 1
    if (time.time() - start_time) > 1:
        elapsed = time.time() - start_time
        fps_measured = int(counter / elapsed)
        counter = 0
        start_time = time.time()

    cv2.putText(img, "{} FPS of {} FPS camera".format(fps_measured, fps_real), (200, 20),
                cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)

    # image display
    cv2.imshow('title', img)

    # keep gui running
    k = cv2.waitKey(1)
    if k == 27:
        break

# Releasing the resource
camera.StopGrabbing()
camera.Close()

cv2.destroyAllWindows()

0reactions
felixmaldonadooscommented, Feb 2, 2021

When i test this code the prompt runs without error codes but there seems to be no output. is there something I overlooked? thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can't I adjust Exposure, ISO and Shutter speed at the ...
The app's Exposure settings combines both ISO and Shutter speed settings, that is why when you choose Exposure adjustment - it switches off...
Read more >
help, can't change exposure time on XT1 - DPReview
It stays at 1 second for both T and B. If I set the wheel to any other time, say 1/4 seconds, the...
Read more >
Cannot Change Exposure Time - BackyardNIKON - O'Telescope
Yes, that is correct. Unless you want to take sub-second exposures. The minimum duration for BULB exposures is 1 second. In that case,...
Read more >
Basics - Manual Controls (exposure, ISO, shutter speed)
This is because the aperture value on your phone is fixed and cannot be adjusted. That leaves us with the ability to adjust...
Read more >
capture: can't change exposure time after first ... - INDI Library
So the driver, depending on the requested exposure time, either requests an exposure time from pre-defined value (Go to Main Control --> Presets)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found