微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

抓取超时 : pypylon usb 相机帧抓取中抛出的 TimeoutException文件“InstantCameraImpl.h”,第 1064 行

如何解决抓取超时 : pypylon usb 相机帧抓取中抛出的 TimeoutException文件“InstantCameraImpl.h”,第 1064 行

代码是简单的图像抓取 python 代码,来自 6 个不同的相机。 代码在开始时完美运行,但一段时间后在其中一个相机抓取时间中随机抛出异常。该错误与任何特定相机无关。

#MV record module
import cv2
import time
import os
import threading
from pypylon import pylon
#for recording time limit
import queue
import shutil
import datetime
            
class mvrecordingObj:
    def __init__(self,vid_save_loc,vid_fl_prefx,vid_duration):
        global grab_state,mv_logger
        grab_state=True
        self.clear_raw_frames()
        
    def init_cam(self):
        try:
            # Pypylon get camera by serial number
            top_cam_post = None
            bottom_cam_post = None
            top_cam_pre = None
            bottom_cam_pre = None
            left_cam_pre = None
            right_cam_pre = None
            for i in pylon.TlFactory.GetInstance().EnumerateDevices():
                if i.GetSerialNumber() == "23504114":
                    try:
                        top_cam_post = i
                    except Exception as e:
                        print("top post error i : "+str(e))
                        mv_logger.debug("top post error i : "+str(e))
                     ....
                     ....
            self.startframegrabing(top_cam_post,bottom_cam_post,top_cam_pre,bottom_cam_pre,left_cam_pre,right_cam_pre)
        except Exception as e:
            print("main() Exception : ",e)
    
    def startframegrabing(self,top_cam_post,right_cam_pre):
        global FRAME_LOCATION
        try:
            image_no_counter = 1
            # VERY IMPORTANT STEP! To use Basler PyPylon OpenCV viewer you have to call .open() method on you camera
            if top_cam_post is not None:
                try:
                    camera_top_cam_post = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateDevice(top_cam_post))
                    camera_top_cam_post.open()
                    camera_top_cam_post.StartGrabbing(pylon.GrabStrategy_LatestimageOnly)
                    camera_top_cam_post.AcquisitionFrameRateEnable=True
                    camera_top_cam_post.AcquisitionFrameRate=50
                    camera_top_cam_post.ExposureTime=500                
                except Exception as e:
                    print("top post error : "+str(e))
            
                    ....
                    ....
            converter = pylon.ImageFormatConverter()
            converter.OutputPixelFormat = pylon.PixelType_BGR8packed
            converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
            while True:
                ############# Top Post ###################
                try:
                    t1 = int(time.time()*1000) 
                    if camera_top_cam_post.IsGrabbing():
                        grabResult = camera_top_cam_post.RetrieveResult(5000,pylon.TimeoutHandling_ThrowException)
                    if grabResult.GrabSucceeded():
                        # Access the image data
                        image = converter.Convert(grabResult)
                        img = image.GetArray()
                        img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
                        #cv2.putText(img,str(time.time())[8:-5],(20,80),#cv2.FONT_HERShey_SIMPLEX,2,(0,255,0),cv2.LINE_AA)
                        cv2.imwrite("FRAMES_TOP_POST/IMG_"+str(image_no_counter)+".jpg",img)
                        if image_no_counter == 1:
                            shutil.move("FRAMES_TOP_POST/IMG_"+str(image_no_counter)+".jpg","FRAMES_TOP_POST/TMP/IMG_"+str(image_no_counter)+".jpg")                
                    if(top_cam_post is not None):
                        grabResult.Release()
                    print("time for camera_top_cam_post frame : ",int(time.time()*1000) - t1) 
                except Exception as e:
                    print("Exception in top post is ",e)
                    mv_logger.debug("Exception in top post is "+str(e))                    
                    ....
                    ....

            if(camera_top_cam_post is not None):
                camera_top_cam_post.StopGrabbing()
                camera_top_cam_post.close()            
            ....
            ....
        except Exception as e:
            print("after while  Exception : ",e)
            mv_logger.debug("after while  Exception : "+str(e))
            threading.Timer(10.0,self.init_cam()).start()
            
    def clear_raw_frames(self):
        pass
            
        
    def run_module(self):
        #mv_logger.debug("MV Record Process Started")
        self.init_cam()
        #mv_logger.debug("Process ended")      

if __name__=="__main__":
    obj1=mvrecordingObj(os.getcwd(),"FNL_TST",60)
    obj1.run_module()

预期输出 抓取并保存来自 6 个不同相机的图像

一段时间后随机出现以下错误 Grab timed out. : TimeoutException thrown (file 'InstantCameraimpl.h',line 1064)

谁能帮忙解决这个问题

解决方法

如果您按如下设置此参数会发生这种情况

camera.AcquisitionMode.SetValue('SingleFrame')

改成

camera.AcquisitionMode.SetValue('Continuous')

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?