[英]Can't save a picture from a Basler acA5472-17um Camera using cam.StartGrabbing()
Im having troubles with saving Images from a Basler camera.我无法从 Basler 相机中保存图像。 I wanted to write a code so that I can press the key "s" and save a picture.我想编写一个代码,以便我可以按“s”键并保存图片。 It seems like the code gets hung up on cam.RetrieveResult(2000).代码似乎挂在 cam.RetrieveResult(2000) 上。 Any Idea how I can fix this problem ?知道如何解决这个问题吗?
#Code inspiration from: https://github.com/basler/pypylon/blob/master/samples/save_image.py
from pypylon import pylon
import platform
import cv2
count = 0
#path_root = 'C:\\Users'
img = pylon.PylonImage()
tlf = pylon.TlFactory.GetInstance()
cam = pylon.InstantCamera(tlf.CreateFirstDevice())
cam.Open()
cam.StartGrabbing()
while True:
with cam.RetrieveResult(2000) as result:
# Calling AttachGrabResultBuffer creates another reference to the
# grab result buffer. This prevents the buffer's reuse for grabbing.
img.AttachGrabResultBuffer(result)
key = cv2.waitKey() & 0xFF
if platform.system() == 'Windows' and key == ord('s'): # press s to safe:
filename = "saved_pypylon_img_%d.png" % count
img.Save(pylon.ImageFileFormat_Png, filename)
print('png image saved')
count += 1
if key == ord('q'):
break
# In order to make it possible to reuse the grab result for grabbing
# again, we have to release the image (effectively emptying the
# image object).
img.Release()
cam.StopGrabbing()
cam.Close()
Your code looks OK and works for the camera on my desk.您的代码看起来不错,适用于我桌上的相机。 This might be some misconfiguration.这可能是一些错误配置。 For instance, if your camera's Trigger Mode is On then you'll always expire not providing pulses to cam's inputs.例如,如果您的相机的触发模式为开,那么您将永远不会向相机的输入提供脉冲。
go to pylon Viewer and reset camera to default settings (User Set Control > User Set Selector: Default User Set > User Set Load: Execute)转到 pylon Viewer 并将相机重置为默认设置(用户设置控制 > 用户设置选择器:默认用户设置 > 用户设置加载:执行)
put camera in Continuous Shot to make sure no errors are popping up in Messages pane and camera runs smoothly将相机置于连拍状态以确保消息窗格中不会弹出错误并且相机运行顺畅
close camera & close pylon Viewer & try your sample again关闭相机并关闭 pylon Viewer 并再次尝试您的样品
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.