@@ -748,13 +748,14 @@ def PadImage(image,width=10):
748748
749749
750750class VideoCaptureBaseProcess (threading .Thread ):
751- def __init__ (self ,video_path ,camera_type ,use_gpu_decode ,camera_reopen_times = 30 ,JadeLog = None ):
751+ def __init__ (self ,video_path ,camera_type ,use_gpu_decode ,camera_reopen_times = 30 ,JadeLog = None , device = None ):
752752 self .video_path = video_path
753753 self .history_status = self .check_video_path ()
754754 self .camera_type = camera_type
755755 self .use_gpu_decode = use_gpu_decode
756756 self .camera_reopen_times = camera_reopen_times
757757 self .reopen_times = 0
758+ self .device = device
758759 self .JadeLog = JadeLog
759760 super (VideoCaptureBaseProcess , self ).__init__ ()
760761
@@ -819,18 +820,39 @@ def open_gpu_capture(self):
819820
820821 def opencv_cpu_capture (self ):
821822 self .JadeLog .INFO ("相机类型为:{},使用CPU解码,准备打开相机" .format (self .camera_type ))
822- self .capture = cv2 .VideoCapture (self .video_path )
823- if self .capture .isOpened ():
824- self .reopen_times = 0
825- self .JadeLog .INFO (
826- "相机类型为:{},相机打开成功,使用CPU对视频解码,相机地址为:{}" .format (self .camera_type , self .video_path ))
827- return True
823+ if self .device == "Ascend" :
824+ from acllite import videocapture
825+ self .capture = videocapture .VideoCapture (self .video_path )
828826 else :
829- self .reopen_times = self .reopen_times + 1
830- self .capture = None
831- self .JadeLog .ERROR ("相机类型为:{},相机第{}次打开失败,相机地址为:{}" .format (self .camera_type , self .reopen_times , self .video_path ))
832- self .camera_abnormal (None )
833- return False
827+ self .capture = cv2 .VideoCapture (self .video_path )
828+ if self .device == "Ascned" :
829+ ret ,frame = self .capture .read ()
830+ if ret :
831+ self .reopen_times = 0
832+ self .JadeLog .INFO (
833+ "相机类型为:{},相机打开成功,使用CPU对视频解码,相机地址为:{}" .format (self .camera_type , self .video_path ))
834+ return True
835+ else :
836+ self .reopen_times = self .reopen_times + 1
837+ self .capture = None
838+ self .JadeLog .ERROR (
839+ "相机类型为:{},相机第{}次打开失败,相机地址为:{}" .format (self .camera_type , self .reopen_times , self .video_path ))
840+ self .camera_abnormal (None )
841+ return False
842+ else :
843+ if self .capture .isOpened ():
844+ self .reopen_times = 0
845+ self .JadeLog .INFO (
846+ "相机类型为:{},相机打开成功,使用CPU对视频解码,相机地址为:{}" .format (self .camera_type , self .video_path ))
847+ return True
848+ else :
849+ self .reopen_times = self .reopen_times + 1
850+ self .capture = None
851+ self .JadeLog .ERROR (
852+ "相机类型为:{},相机第{}次打开失败,相机地址为:{}" .format (self .camera_type , self .reopen_times , self .video_path ))
853+ self .camera_abnormal (None )
854+ return False
855+
834856
835857 def judge_capture_reader (self ):
836858 if self .use_gpu_decode :
@@ -848,7 +870,7 @@ def capture_reader(self):
848870 else :
849871 ret , frame = self .capture .read ()
850872 self .package_data (ret , frame )
851- if ret is False :
873+ if ret is False or ret == 0 or frame is None :
852874 self .JadeLog .WARNING (
853875 "相机类型为:{},相机中途断开,等待{}s,尝试重连" .format (self .camera_type , self .camera_reopen_times ))
854876 time .sleep (self .camera_reopen_times )
0 commit comments