Skip to content

Commit b06d4b1

Browse files
committed
update 支持华为昇腾芯片解码
1 parent 85708d8 commit b06d4b1

3 files changed

Lines changed: 42 additions & 43 deletions

File tree

README.md

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,6 @@
1-
## python tools V1.0.1
2-
* 不使用第三方wheel包
3-
4-
5-
## 1.编写python文件
6-
7-
## 2. 编写setup.py文件
8-
```Python
9-
from setuptools import setup, find_packages
10-
11-
setup(
12-
name="jade_tools",
13-
version="0.1",
14-
keywords=("pip", "jade_tools", ""),
15-
description="jade_tools",
16-
long_description="xxx",
17-
license="MIT Licence",
18-
19-
url="https://jadehh@live.com",
20-
author="opencv_tools",
21-
author_email="jadehh@live.com",
22-
23-
packages=find_packages(),
24-
include_package_data=True,
25-
platforms="any",
26-
install_requires=["numpy","pillow","imageio"] # 这个项目需要的第三方库
27-
)
28-
```
29-
## 3.打包为wheel文件
1+
## opencv_toolsV1.1.2
2+
* Opencv相关操作
3+
### 打包为wheel文件
304

315
安装wheel
326
```bash
@@ -37,3 +11,6 @@ pip install wheel
3711
pip wheel --wheel-dir=./wheel_dir ./
3812
```
3913
> wheel-dir 为wheel 输出文件夹,后面接项目文件夹(即包含setup.py的文件夹)
14+
15+
### 更新日志
16+
* 支持华为Ascned解码

opencv_tools/jade_opencv_process.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -748,13 +748,14 @@ 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):
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)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
find_packages("opencv_tools", pack_list)
1313
setup(
1414
name="opencv_tools",
15-
version="1.1.1",
15+
version="1.1.2",
1616
keywords=("pip", "opencv_tools", ""),
1717
description="opencv_tools",
1818
long_description="",

0 commit comments

Comments
 (0)