【发布时间】:2019-06-03 19:41:36
【问题描述】:
将我的源代码构建到 Raspberry Pi 时遇到问题。
OpenCV 无法初始化新实例并停留在 step call cv2.VideoCapture。
这是我的源代码:
import threading
import time
import cv2
CAPTURE_HZ = 30.0
class Person(object):
def __init__(self, name, id):
self._camera = cv2.VideoCapture(id)
print("Debug")
self.name = name
self._capture_frame = None
# Use a lock to prevent access concurrent access to the camera.
self._capture_lock = threading.Lock()
self._capture_thread = threading.Thread(target=self._grab_frames)
self._capture_thread.daemon = True
self._capture_thread.start()
def _grab_frames(self):
while True:
with self._capture_lock:
self._capture_frame = self.name
time.sleep(1.0 / CAPTURE_HZ)
def speak(self):
print("Hi! My name is {self.name}.".format(self=self))
这是我正在测试的结果:
$ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import camera
>>> camera1 = camera.Camera("Cam1", 0)
Debug
>>> camera2 = camera.Camera("Cam2", 0) <<<<< It's stuck at here
而且这个过程占用了 Raspberry 的 100% CPU。我必须使用sudo kill
感谢您阅读我的问题!
【问题讨论】:
标签: python opencv raspberry-pi