|
【人工智能】
RK3399pro Rock-X python代码+USB摄像头目标检测报错
发表于 2023-4-25 09:20:31
浏览:12362
|
回复:13
打印
只看该作者
[复制链接]
楼主
问题描述及复现步骤:
本帖最后由 KevinWu 于 2023-4-25 09:20 编辑
平台:Ubuntu 20.04 + 2GB内存 +1GB NPU
问题1:按照Rockchip_Developer_Guide_RockX_SDK_CN 文档,接入USB摄像头后,运行以下命令- python3 -m rockx.test.camera.rockx_object_detection
复制代码- python3 -m rockx_object_detection.py
复制代码 报以下错误:内存不够
- Traceback (most recent call last):
- File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
- return _run_code(code, main_globals, None,
- File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
- exec(code, run_globals)
- File "/home/firefly/.local/lib/python3.8/site-packages/rockx/test/camera/rockx_object_detection.pine 12, in <module>
- object_det_handle = RockX(RockX.ROCKX_MODULE_OBJECT_DETECTION, target_device=args.device)
- File "/home/firefly/.local/lib/python3.8/site-packages/rockx/RockX.py", line 235, in __init__
- self.rockx_base = RockXBase()
- File "/home/firefly/.local/lib/python3.8/site-packages/rockx/RockXBase.py", line 218, in __init__
- RockXBase._load_library()
- File "/home/firefly/.local/lib/python3.8/site-packages/rockx/RockXBase.py", line 448, in _load_li
- RockXBase.lib = CDLL(os.path.join(lib_dir, 'librockx.so'))
- File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
- self._handle = _dlopen(self._name, mode)
- OSError: /home/firefly/.local/lib/python3.8/site-packages/rockx/sdk/rockx-rk3399pro-Linux/lib64/lib.so: cannot allocate memory in static TLS block
复制代码
问题2:通过chat-gpt搜索了解决答案,用sudo权限运行
- sudo python3 -m rockx.test.camera.rockx_object_detection
复制代码- sudo python3 -m rockx_object_detection.py
复制代码 报以下错误:
ModuleNotFoundError: No module named 'rockx'
3.参考文档和代码
- import argparse
- from rockx import RockX
- import cv2
- if __name__ == '__main__':
- parser = argparse.ArgumentParser(description="RockX Object Detection Demo")
- parser.add_argument('-c', '--camera', help="camera index", type=int, default=0)
- parser.add_argument('-d', '--device', help="target device id", type=str)
- args = parser.parse_args()
- object_det_handle = RockX(RockX.ROCKX_MODULE_OBJECT_DETECTION, target_device=args.device)
- cap = cv2.VideoCapture(args.camera)
- cap.set(3, 1280)
- cap.set(4, 720)
- last_face_feature = None
- while True:
- # Capture frame-by-frame
- ret, frame = cap.read()
- in_img_h, in_img_w = frame.shape[:2]
- ret, results = object_det_handle.rockx_face_detect(frame, in_img_w, in_img_h, RockX.ROCKX_PIXEL_FORMAT_BGR888)
- for result in results:
- cv2.rectangle(frame,
- (result.box.left, result.box.top),
- (result.box.right, result.box.bottom),
- (0, 255, 0), 2)
- cv2.putText(frame, "%s" % RockX.ROCKX_OBJECT_DETECTION_LABELS_91[result.cls_idx],
- (result.box.left, result.box.top - 10),
- cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0))
- # Display the resulting frame
- cv2.imshow('RockX Object Detection - ' + str(args.device), frame)
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- # When everything done, release the capture
- cap.release()
- cv2.destroyAllWindows()
- object_det_handle.release()
复制代码
|
|