Skip to content

Commit 7545b4c

Browse files
committed
update 优化华为Ascend芯片解码
1 parent 46712c9 commit 7545b4c

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

opencv_tools/jade_opencv_process.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def PadImage(image,width=10):
748748

749749

750750
class VideoCaptureBaseProcess(threading.Thread):
751-
def __init__(self,video_path,camera_type,use_gpu_decode,camera_reopen_times=30,JadeLog=None,device=None):
751+
def __init__(self,video_path,camera_type,use_gpu_decode,camera_reopen_times=30,JadeLog=None,device=None,acl_resource=None):
752752
self.video_path = video_path
753753
self.history_status = self.check_video_path()
754754
self.camera_type = camera_type
@@ -763,7 +763,11 @@ def download_frame(self,frame):
763763
if self.use_gpu_decode:
764764
frame = frame.download()
765765
frame = cv2.cvtColor(frame, cv2.COLOR_BGRA2BGR)
766+
if self.device == "Ascend":
767+
frame = self._dvpp.jpege(frame)
768+
frame = frame.jpeg_to_cv2()
766769
return frame
770+
767771
def package_data(self,ret,frame):
768772
frame = self.download_frame(frame)
769773
cv2.namedWindow("result",0)
@@ -821,18 +825,20 @@ def open_gpu_capture(self):
821825
def opencv_cpu_capture(self):
822826
if self.device == "Ascend":
823827
from acllite import videocapture
828+
import acl
829+
ret = acl.rt.set_device(0)
824830
self.capture = videocapture.VideoCapture(self.video_path)
825831
self.JadeLog.INFO("相机类型为:{},使用Ascend芯片解码,准备打开相机".format(self.camera_type))
826832
else:
827833
self.capture = cv2.VideoCapture(self.video_path)
828834
self.JadeLog.INFO("相机类型为:{},使用CPU解码,准备打开相机".format(self.camera_type))
829835

830-
if self.device == "Ascned":
836+
if self.device == "Ascend":
831837
ret,frame = self.capture.read()
832-
if ret:
838+
if ret == 0 and frame is not None:
833839
self.reopen_times = 0
834840
self.JadeLog.INFO(
835-
"相机类型为:{},相机打开成功,使用CPU对视频解码,相机地址为:{}".format(self.camera_type, self.video_path))
841+
"相机类型为:{},相机打开成功,使用Ascend芯片解码,相机地址为:{}".format(self.camera_type, self.video_path))
836842
return True
837843
else:
838844
self.reopen_times = self.reopen_times + 1
@@ -871,12 +877,18 @@ def capture_reader(self):
871877
ret, frame = self.capture.nextFrame()
872878
else:
873879
ret, frame = self.capture.read()
874-
self.package_data(ret, frame)
875-
if ret is False or ret == 0 or frame is None:
880+
if self.device == "Ascend":
881+
if ret == 0:
882+
ret = True
883+
else:
884+
ret = False
885+
if ret is False or frame is None:
876886
self.JadeLog.WARNING(
877887
"相机类型为:{},相机中途断开,等待{}s,尝试重连".format(self.camera_type, self.camera_reopen_times))
878888
time.sleep(self.camera_reopen_times)
879889
self.judge_capture_reader()
890+
else:
891+
self.package_data(ret, frame)
880892
if self.history_status:
881893
time.sleep(0.04)
882894
except Exception as e:
@@ -890,6 +902,11 @@ def capture_reader(self):
890902
time.sleep(self.camera_reopen_times)
891903

892904
def run(self):
905+
if self.device == "Ascend":
906+
import acl
907+
from acllite.acllite_imageproc import AclLiteImageProc
908+
ret = acl.rt.set_device(0)
909+
self._dvpp = AclLiteImageProc()
893910
self.capture_reader()
894911

895912

0 commit comments

Comments
 (0)