简体   繁体   English

无法使用 cam.StartGrabbing() 保存来自 Basler acA5472-17um 相机的图片

[英]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.

相关问题 使用basler相机和python时保存视频而不是保存图像 - Save video instead of saving images while using basler camera and python Basler Ace 相机与 Python 的集成 - Basler Ace Camera Integration with Python 使用带有 pylonsrc 的 Python3 gstreamer1.0 使用 basler 相机和 pylon5 在处理循环中给出错误 - Using Python3 gstreamer1.0 with pylonsrc using basler camera and pylon5 gives error in the processing loop Telegram Bot 可以要求用户从相机拍照吗? - Can Telegram Bot ask user to take picture from camera? 如何从客户端 web cam 捕获图像并将其保存到服务器? 我正在使用 Python 和 Flask,在 Heroku 实例上运行 - How can I capture an image from a client side web cam and save it to the server please? I am using Python with Flask, running on a Heroku instance Basler 相机的问题 - 低帧率和延迟 - ROS - Problem with Basler Camera - Low Frame Rate and Latency - ROS 无法将我的 JSON 保存到 Python 字典中。 有错误作为图片 - Can't save my JSON into a python dictionary. Have the errors as a picture 为什么我不能使用OPENCV VideoCapture从正面平板相机读取流? - Why can't I reading stream from frontal tablet camera using OPENCV VideoCapture? 无法使用 imageField 在我的 django 社交应用程序上显示图片? - Can't display picture on my django social app using imageField? Django 1.6:无法显示模板中模型的图片。 - Django 1.6: Can't display a picture from a model in template.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM