Open jimjay203 opened 6 years ago
Hi No clue. Are you sure webcam is enable and working for your raspi?
Hi,
i have the same prob:
`pi@magicmirror:~/MagicMirror/modules/MMM-Facial-Recognition-OCV3 $ python tools.facerecognition.py Remember to set the name list environment variable FACE_USERS Loading PiCamera PiCamera loaded Loading training data... mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM) mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1) Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/home/pi/MagicMirror/modules/MMM-Facial-Recognition-OCV3/lib/common/picam.py", line 25, in run with picamera.PiCamera() as camera: File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 431, in init self._init_camera(camera_num, stereo_mode, stereo_decimate) File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 460, in _init_camera "Camera is not enabled. Try running 'sudo raspi-config' " PiCameraError: Camera is not enabled. Try running 'sudo raspi-config' and ensure that the camera has been enabled.
Training data loaded!
OpenCV Error: Assertion failed (!buf.empty() && buf.isContinuous()) in imdecode, file /home/pi/opencv/modules/imgcodecs/src/loadsave.cpp, line 637
Traceback (most recent call last):
File "tools.facerecognition.py", line 45, in
how to setup the webcam?
i tired this script and it works with it... no idea why there is a prob with MMM-Facial-Recognition-OCV3
import cv2
cam = cv2.VideoCapture(0)
cv2.namedWindow("test")
img_counter = 0
while True: ret, frame = cam.read() cv2.imshow("test", frame) if not ret: break k = cv2.waitKey(1)
if k%256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
elif k%256 == 32:
# SPACE pressed
img_name = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_name, frame)
print("{} written!".format(img_name))
img_counter += 1
cam.release()
cv2.destroyAllWindows()
so when i remove picam.py it uses webcam.py put the i get the error corrupt jpeg data...
Anybody with an idea about this...
so when i remove picam.py it uses webcam.py put the i get the error corrupt jpeg data...
Anybody with an idea about this...
Its ok nothing to worry about, i m having same thing
I fixed this problem by editing the picam file located at:
/MMM-Facial-Recognition-OCV3/lib/common/picam.py
Definitely a quick hack, but works quite OK.
class OpenCVCapture(Thread):
def __init__(self, preview=False):
Thread.__init__(self)
self.buffer = io.BytesIO()
self.lock = threading.Lock()
self.running = True
self.preview = preview
self.cap = None
def run(self):
self.cap = cv2.VideoCapture(0)
if (self.cap.isOpened()== False):
print("Error opening video stream or file")
self.lock.release()
def read(self):
"""Read a single frame from the camera and return the data as an OpenCV
image (which is a numpy array).
"""
self.lock.acquire()
try:
ret, frame = self.cap.read()
print("Took image")
finally:
self.lock.release()
return frame
def stop(self):
self.running = False
self.join()
Please higlight what you changed. And please make a fix dev. This worked with the original Face rec. And now All I get is corrupted.
I edited the lib/common/config.js and changed picam to webcam. My usb cam now lights up. This is the fix I used on the old FR. But it still comes with corrupt error.. And it never stops....
I didn't have any luck with the fixes mentioned previously, but I found that replacing the picam.py file with webcam.py did allow me to run the capture and training tools.
Hello fellas. Im using a USB Webcam aswell and Ive the same problem like @diverdennis and @jimjay203. The module always wants to use the PiCam to capture the pictures. i tried to delete the picam.py, it works then and the usbcamera is active but its capturing a loop of corrupt pictures. in the config.js i changed the useUSBCam part to true too. do you know any fixes?
Hi, all, I also had the same problem. Both tools.capture.py and tools.facerecognition.py returned the following error on attempt to access the USB camera: "Camera is not enabled. Try running 'sudo raspi-config' "
And the config changes did not help in any way. Then I found the problematic place in ToolsConfig (/lib/tools/config.py). As I understand the following logic, it supposes to switch to USB Cam if PI Cam returns an error, however it does not happen for some reason.
I am not an expert in Python, so I do not quite sure how to fix it properly. As a workaround I just replaced import picam
with import webcam
in the try section and it helped:
diff --git a/lib/tools/config.py b/lib/tools/config.py
index 6087482..078b6df 100755
--- a/lib/tools/config.py
+++ b/lib/tools/config.py
@@ -83,16 +83,19 @@ class ToolsConfig (CommonConfig):
@classmethod
def getCamera(cls):
try:
- import picam
- print("Loading PiCamera")
- capture = picam.OpenCVCapture(True)
- print("PiCamera loaded")
- capture.start()
- return capture
- except Exception as e:
- print(e)
+ #import picam
+ #print("Loading PiCamera")
+ #capture = picam.OpenCVCapture(True)
+ #print("PiCamera loaded")
+ #capture.start()
+ #return capture
+ print("!!! Loading WebCamera")
import webcam
return webcam.OpenCVCapture(device_id=0)
+ except Exception as e:
+ print(e)
+ #import webcam
+ #return webcam.OpenCVCapture(device_id=0)
@classmethod
def model(cls):
I guess it requires a change request for the future..
i run the facerecognition.py. it will work but. i doesnt recognize me. it return none. i didnt find to solve this problem. What can i do?
I have a ps3 eye usb cam installed. When starting "python tools.capture.py" for capture training i get:
Loading PiCamera PiCamera loaded Capturing positive training images. Press enter to capture an image. Press Ctrl-C to quit. mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM) mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1) Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/home/pi/MagicMirror/modules/MMM-Facial-Recognition-OCV3/lib/common/picam.py", line 25, in run with picamera.PiCamera() as camera: File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 431, in init self._init_camera(camera_num, stereo_mode, stereo_decimate) File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 460, in _init_camera "Camera is not enabled. Try running 'sudo raspi-config' " PiCameraError: Camera is not enabled. Try running 'sudo raspi-config' and ensure that the camera has been enabled.
What do I have to configure, to get it working with an usb webcam?