Skip to content

Commit 22dd4a4

Browse files
committed
* 优化Ascend解码速度
1 parent 389190f commit 22dd4a4

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## OpencvToolsV1.2.2
1+
## OpencvToolsV1.2.3
22
Opencv相关操作
33

44
### 打包为wheel文件

opencv_tools/jade_opencv_process.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from opencv_tools import DIRECTORY_IMAGES,DIRECTORY_ANNOTATIONS,DIRECTORY_PREANNOTATIONS
1919
import base64
2020

21-
2221
## opencv读取中文路径图片
2322
def imread_chinese_path(image_path):
2423
image = cv2.imdecode(np.fromfile(image_path, dtype=np.uint8), -1)
@@ -770,6 +769,7 @@ def __init__(self,video_path,camera_type,use_gpu_decode,camera_reopen_times=30,J
770769
self.device = device
771770
self.JadeLog = JadeLog
772771
self.show_window = show_window
772+
self.capture = None
773773
super(VideoCaptureBaseProcess, self).__init__()
774774

775775
def download_frame(self,frame):
@@ -838,14 +838,29 @@ def open_gpu_capture(self):
838838
def opencv_cpu_capture(self):
839839
if self.device == "ascend":
840840
from acllite import videocapture
841-
import acl
842-
ret = acl.rt.set_device(0)
843-
self.capture = videocapture.VideoCapture(self.video_path)
844-
self.JadeLog.INFO("相机类型为:{},使用Ascend芯片解码,准备打开相机".format(self.camera_type))
841+
if self.capture is None:
842+
import acl
843+
from acllite import acllite_utils as utils
844+
self._context, ret = acl.rt.create_context(0)
845+
utils.check_ret("acl.rt.create_context", ret)
846+
else:
847+
self.JadeLog.DEBUG("相机类型为:{},释放相机资源".format(self.camera_type))
848+
try:
849+
self.capture = videocapture.VideoCapture(self.video_path)
850+
self.JadeLog.INFO("相机类型为:{},使用Ascend芯片解码,准备打开相机".format(self.camera_type))
851+
except Exception as e:
852+
self.JadeLog.ERROR("相机类型为:{},相机打开失败,失败原因为:{}".format(self.camera_type,e))
853+
self.capture = None
854+
self.capture = videocapture.VideoCapture(self.video_path)
845855
else:
856+
if self.capture is None:
857+
pass
858+
else:
859+
self.JadeLog.DEBUG("相机类型为:{},释放相机资源".format(self.camera_type))
860+
self.capture.release()
846861
self.capture = cv2.VideoCapture(self.video_path)
862+
self.capture.release()
847863
self.JadeLog.INFO("相机类型为:{},使用CPU解码,准备打开相机".format(self.camera_type))
848-
849864
if self.device == "ascend":
850865
ret,frame = self.capture.read()
851866
if ret == 0 and frame is not None:
@@ -895,7 +910,8 @@ def capture_reader(self):
895910
ret = True
896911
else:
897912
ret = False
898-
if ret is False or frame is None:
913+
914+
if ret is False:
899915
self.JadeLog.WARNING(
900916
"相机类型为:{},相机中途断开,等待{}s,尝试重连".format(self.camera_type, self.camera_reopen_times))
901917
time.sleep(self.camera_reopen_times)
@@ -905,7 +921,7 @@ def capture_reader(self):
905921
if self.history_status:
906922
time.sleep(0.04)
907923
except Exception as e:
908-
self.JadeLog.WARNING(
924+
self.JadeLog.ERROR(
909925
"相机类型为:{},相机解码失败,失败原因为:{},发生异常文件{},发生异常所在的行数{},等待{}s,尝试重连".format(self.camera_type,e ,
910926
e.__traceback__.tb_frame.f_globals["__file__"],e.__traceback__.tb_lineno,self.camera_reopen_times))
911927
time.sleep(self.camera_reopen_times)

opencv_tools/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# @Email : jadehh@1ive.com
77
# @Software : Samples
88
# @Desc :
9-
version = "1.2.1"
9+
version = "1.2.3"

0 commit comments

Comments
 (0)