-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add examples: grab multiple image frames #802
Open
RealBrandonChen
wants to merge
1
commit into
basler:master
Choose a base branch
from
RealBrandonChen:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
''' | ||
Use pypylon to grab multiple image frames with hardware triggers. | ||
Test camera: acA640-750um | ||
Version: pypylon == 4.1.0 | ||
Maximum framerate: 1000fps | ||
''' | ||
from pypylon import pylon | ||
import traceback | ||
import numpy as np | ||
|
||
# your recording frames | ||
numFrames = 1000 | ||
# Initialize camera instance and open the camera | ||
cam = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice()) | ||
cam.Open() | ||
# Print the model name of the camera. | ||
print("Using camera device: ", cam.GetDeviceInfo().GetModelName()) | ||
|
||
# class of image handler | ||
class ImageHandler(pylon.ImageEventHandler): | ||
def __init__(self): | ||
super().__init__() | ||
self.count = 0 | ||
self.img_sum = [] | ||
|
||
def OnImagesSkipped(self, camera, countOfSkippedImages): | ||
print(countOfSkippedImages, " images have been skipped.") | ||
|
||
def OnImageGrabbed(self, camera, grabResult): | ||
""" we get called on every image | ||
!! this code is run in a pylon thread context | ||
always wrap your code in the try .. except to capture | ||
errors inside the grabbing as this can't be properly reported from | ||
the background thread to the foreground python code | ||
""" | ||
try: | ||
if grabResult.GrabSucceeded(): | ||
# check image contents | ||
img = grabResult.Array | ||
# Stack images to 3D array | ||
self.img_sum.append(img) | ||
self.count += 1 | ||
grabResult.Release() | ||
else: | ||
raise RuntimeError("Grab Failed") | ||
except Exception as e: | ||
traceback.print_exc() | ||
|
||
# Control the parameter of the Basler camera | ||
# Get clean powerup state | ||
cam.UserSetSelector.Value = "Default" | ||
cam.UserSetLoad.Execute() | ||
# Set the io section | ||
cam.LineSelector.Value = "Line1" | ||
cam.LineMode.Value = "Input" | ||
# Setup the trigger/ acquisition controls | ||
cam.TriggerSelector.Value = "FrameStart" | ||
cam.TriggerSource.Value = "Line1" | ||
cam.TriggerMode.Value = "On" | ||
cam.TriggerActivation.Value = "RisingEdge" | ||
print("The resulting Trigger Activation is: " + str(cam.TriggerActivation.Value)) | ||
|
||
# Instantiate callback handler of camera image | ||
handler = ImageHandler() | ||
# handler registration for camera | ||
cam.RegisterImageEventHandler(handler , pylon.RegistrationMode_ReplaceAll, pylon.Cleanup_None) | ||
# start capturing frames | ||
cam.StartGrabbingMax(numFrames + 1, pylon.GrabStrategy_LatestImages, pylon.GrabLoop_ProvidedByInstantCamera) | ||
# other hardware running time here... | ||
cam.StopGrabbing() | ||
cam.DeregisterImageEventHandler(handler) | ||
cam.TriggerMode.Value = "Off" | ||
cam.Close() | ||
print("Recorded frames in the camera is: ", str(handler.count)) | ||
cameraImages = np.array(handler.img_sum).transpose(1,2,0) | ||
# check if captured camera frames are the same with the patterns | ||
assert cameraImages.shape[2] == numFrames |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a quick test provide a dummy loop: