I'm facing problem when build my source code to Raspberry Pi.
OpenCV can't init new instance and stuck at step call cv2.VideoCapture
.
Here is my source code:
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))
Here is result I'm testing:
$ 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
And this process take 100% CPU of Raspberry. I must using sudo kill
Thank you because read my issue!