j ton
j ton

Reputation: 249

(raspberry pi 4 and Python) raspberry Camera mode raise picamera.exc.PiCameraMMALError and picamera.exc.PiCameraError

system: raspberry pi 4 model B, use external usb logitech camera

I'm follow the youtube tutorial but get picamera.exc.PiCameraMMALError andpicamera.exc.PiCameraError

relate discussion on other site 2021 (I didn't get their solution): "Camera issue, no idea what the problem is"
https://forums.raspberrypi.com/viewtopic.php?t=324702

- the python code:

from picamera import PiCamera
import time


print("= = = = = == = = = ")
camera = PiCamera()

camera.start_preview()
time.sleep(2)

camera.capture("test.jpg")

- the whole output:

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)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 456, in _init_camera
    self._camera = mo.MMALCamera()
  File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 2279, in __init__
    super(MMALCamera, self).__init__()
  File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 631, in __init__
    mmal_check(
  File "/usr/lib/python3/dist-packages/picamera/exc.py", line 184, in mmal_check
    raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Failed to create MMAL component b'vc.ril.camera': Out of memory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/joy/Desktop/camera.py", line 6, in <module>
    camera = PiCamera()
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 431, in __init__
    self._init_camera(camera_num, stereo_mode, stereo_decimate)
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 459, in _init_camera
    raise PiCameraError(
picamera.exc.PiCameraError: Camera is not enabled. Try running 'sudo raspi-config' and ensure that the camera has been enabled.

How to Take Photos and Videos with Raspberry Pi Camera Module
https://www.youtube.com/watch?v=nx8gDSS1vO4&list=PLnjnmu-sbNYMvMiXd-y5t7fYts1N0hmuI&index=3&t=331s&ab_channel=TechWithTim

https://ibb.co/Jyxtbfv
https://ibb.co/CHrWRH1

I'm the python beginner, and first day have raspberry pi, stocking on camera setup, how can I fix this, thanks

Upvotes: 0

Views: 1983

Answers (1)

Bhargav
Bhargav

Reputation: 4241

You need to enable Pi-camera in setting.That's what error is saying.

  1. Type sudo raspi-config in terminal & hit enter.
  2. Go to interface options
  3. Go to p1 Legacy camera and hit enetr After enable it.

4.Reboot

enter image description here

As you mentioned external camera What happens here I guess is raspberry Pi has onboard camera socket. WHen we conncet camera to it Raspberry pi assigns as device id =0 internally. When we connect second camera(which is through USB yourcase). It will be assigned witj device id =1 ...As you not mentioned which device Id it deafultly checking at devic id=0 which not exists. Let me check documention how to re assign Id. I Know how to do that opencv but, Never tried in this pi camera module. in meanwhile try opencv

pip install opencv-contrib-python 

After installation of library

import cv2
  
  
# define a video capture object
vid = cv2.VideoCapture(1) ########## 1- device id =1###if 1 deosn't work try 2
  
while(True):
      
    # Capture the video frame
    # by frame
    ret, frame = vid.read()
  
    # Display the resulting frame
    cv2.imshow('frame', frame)
      
    # the 'q' button is set as the
    # quitting button you may use any
    # desired button of your choice
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
  
# After the loop release the cap object
vid.release()
# Destroy all the windows
cv2.destroyAllWindows()

Upvotes: 2

Related Questions