Python Scripts Not Working

Published by david123718 on

Home Forums Cameras Modules for Raspberry Pi 5MP OV5647 V1 Cameras Python Scripts Not Working

Viewing 18 reply threads
  • Author
    Posts
    • #12531
      david123718
      Participant

      Hi!

      I recently purchased and easily installed the camera to my Raspberry Pi. I updated everything and did “sudo apt-get update”

      When I try to run the command I get the following error.

      [email protected]:~ $ cd RaspberryPi/Motorized_Focus_Camera
      [email protected]:~/RaspberryPi/Motorized_Focus_Camera $ sudo python Autofocus.py [sudo] password for pi:
      mmal: mmal_vc_port_enable: failed to enable port vc.null_sink:in:0(OPQV): ENOSPC
      mmal: mmal_port_enable: failed to enable connected port (vc.null_sink:in:0(OPQV) )0x15cad80 (ENOSPC)
      mmal: mmal_connection_enable: output port couldn’t be enabled
      Traceback (most recent call last):
      File “Autofocus.py”, line 39, in <module>
      camera = picamera.PiCamera()
      File “/usr/lib/python2.7/dist-packages/picamera/camera.py”, line 433, in __ini t__
      self._init_preview()
      File “/usr/lib/python2.7/dist-packages/picamera/camera.py”, line 513, in _init _preview
      self, self._camera.outputs[self.CAMERA_PREVIEW_PORT])
      File “/usr/lib/python2.7/dist-packages/picamera/renderers.py”, line 558, in __ init__
      self.renderer.inputs[0].connect(source).enable()
      File “/usr/lib/python2.7/dist-packages/picamera/mmalobj.py”, line 2212, in ena ble
      prefix=”Failed to enable connection”)
      File “/usr/lib/python2.7/dist-packages/picamera/exc.py”, line 184, in mmal_che ck
      raise PiCameraMMALError(status, prefix)
      picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources
      [email protected]:~/RaspberryPi/Motorized_Focus_Camera $ ^C
      [email protected]:~/RaspberryPi/Motorized_Focus_Camera $ sudo python Motorized_Focus_Cam era_snapshot.py
      python: can’t open file ‘Motorized_Focus_Camera_snapshot.py’: [Errno 2] No such file or directory
      [email protected]:~/RaspberryPi/Motorized_Focus_Camera $ Ls
      -bash: Ls: command not found
      [email protected]:~/RaspberryPi/Motorized_Focus_Camera $ ls
      Autofocus.py Motorized_Focus_Camera_Preview.py README.md
      enable_i2c_vc.sh Motorized_Focus_Camera_Snapshot.py
      [email protected]:~/RaspberryPi/Motorized_Focus_Camera $ sudo python Motorized_Focus_Cam era_Snapshot.py
      Traceback (most recent call last):
      File “Motorized_Focus_Camera_Snapshot.py”, line 6, in <module>
      import pygame,sys
      ImportError: No module named pygame
      [email protected]:~/RaspberryPi/Motorized_Focus_Camera $ sudo python Motorized_Focus_Cam era_Preview.py
      Traceback (most recent call last):
      File “Motorized_Focus_Camera_Preview.py”, line 6, in <module>
      import pygame,sys
      ImportError: No module named pygame
      [email protected]:~/RaspberryPi/Motorized_Focus_Camera $ sudo apt-get install pygame
      Reading package lists… Done
      Building dependency tree
      Reading state information… Done
      E: Unable to locate package pygame
      [email protected]:~/RaspberryPi/Motorized_Focus_Camera $ ^C
      [email protected]:~/RaspberryPi/Motorized_Focus_Camera $ import pygame
      import-im6.q16: unable to open X server `’ @ error/import.c/ImportImageCommand/3 58.

       

      Any suggestions to fix?

    • #12537
      bin
      Keymaster

      Hello,

      Q1:mmal: mmal_vc_port_enable: failed to enable port vc.null_sink:in:0(OPQV): ENOSPC
      mmal: mmal_port_enable: failed to enable connected port (vc.null_sink:in:0(OPQV) )0x15cad80 (ENOSPC)
      mmal: mmal_connection_enable: output port couldn’t be enabled

      A1:The raspberypi mmal failed to enable port, It seems the FPC cable is defective. I give you some suggestions:

      1.Please check if you have enable the camera and i2c0

      2. Please reconnect the FPC cable and use the official raspistill command to test the camera firstly. Just run   [email protected]:~ $ raspistill -t 0 . If normal, you will see the preview on the hdmi screen.

       

      Q2: E: Unable to locate package pygame

      A2: Please try to use pip install pygame

       

    • #12558
      david123718
      Participant

      Hi,

      I did what you did and enabled the camera and i2c0, and installed pygame successfully. I am getting this error when running  [email protected]:~ $ raspistill -t 0

      [email protected]:~ $ raspistill -t 0
      mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
      mmal: camera component couldn’t be enabled
      mmal: main: Failed to create camera component
      mmal: Failed to run camera app. Please check for firmware updates

       

      • This reply was modified 7 months, 3 weeks ago by david123718.
    • #12585
      Lee Jackson
      Keymaster

      @david123718

      It looks like the camera doesn’t even be recognized. Please make sure if the camera can be detected by the pi board first with vcgencmd get_camera command.

      Also please upload the hardware setup photos for diagnose.

    • #12624
      david123718
      Participant

      Hi, @Lee Jackon

      When I ran the vcgencmd get_camera command this is what I got:

      supported=1 detected=1

      The setup is pretty simple,

      setup

      The Blue usb cable is connected to my 3D printer and is running OctoPrint. The Octoprint software can see the camera, however it is fairly unfocused.

      octorpint

    • #12652
      david123718
      Participant

      This is the error I still get running the [email protected]:~ $ raspistill -t 0 command.

      mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
      mmal: camera component couldn’t be enabled
      mmal: main: Failed to create camera component
      mmal: Failed to run camera app. Please check for firmware updates

    • #12657
      bin
      Keymaster

      @david123718

      We have updated our auto driver and you don’t need to connect the i2c1 signal.

      I advise you disconnect your Octoprint device, run the camera using our python script firstly, then connect your print device to try.

       

      • #12664
        david123718
        Participant

        Uh oh,

        Getting another error. When running the preview script, it is giving me a black screen. I already ran the command sudo apt-get install python-opencv

        black screen

    • #12658
      david123718
      Participant

      Fixed!

      For some reason the camera doesn’t clear its resources when I do “sudo service octoprint stop” Since the camera is only able to handle one program at a time, it wasn’t letting me run the script. There was an unknown application or program taking up that one resource. Even after I stopped octoprint.

    • #12665
      david123718
      Participant

      Uh oh,

      Getting another error. When running the preview script, it is giving me a black screen. I already ran the command sudo apt-get install python-opencv
      Black Screen

    • #12750
      Lee Jackson
      Keymaster

      @david123718

      Does it work or not, I saw you post the same error twice.

      • #12795
        david123718
        Participant

        I thought it worked, because I was in SSH but I noticed it didn’t actually change the focus. So I plugged it in HDMI and I noticed that it black screened and not focusing the camera.

    • #13069
      Lee Jackson
      Keymaster

      @david123718 I’m glad to hear that it works now.

    • #22532
      toppenhe
      Participant

      Hello,

      I am trying to run:

      Step 4: Calibration
      4_calibration.py loads all previously saved pairs and figures out the correction matrices. It searches for the chessboard on the photo, and move on if the chessboard is not found. Therefore, the bad photos in the series won’t break the script. After the calculation is finished, it will rectify the last image and show the resulting “fixed” images. You can check the quality of the calibration in this step, which might take 1-2 minutes.

      But I am getting the following error:

      Traceback (most recent call last):
      File “4_calibration.py”, line 29, in <module>
      from stereovision.calibration import StereoCalibrator
      ImportError: No module named stereovision.calibration

       

      I found the source code and saved it as a .py file in the stereo_depth_demo folder but it still gives the same error.  Any suggestions?

      Best,

      Tom

       

    • #22557
      wong
      Moderator

      Hi @toppenhe ,

      You are missing the stereovision dependency, use the “sudo pip3 install stereovision” command to install.
      Note: Please use python3 to run the sample program “python3 4_calibration.py”

    • #22597
      toppenhe
      Participant

      Hi,

      I installed stereovision and then ran:

      python3 4_calibration.py
      Traceback (most recent call last):
      File “4_calibration.py”, line 26, in <module>
      import cv2
      File “/usr/local/lib/python3.7/dist-packages/cv2/__init__.py”, line 3, in <module>
      from .cv2 import *
      ImportError: libjasper.so.1: cannot open shared object file: No such file or directory

       

      Thank you for help!

    • #22599
      toppenhe
      Participant

      checkerboard

    • #22598
      toppenhe
      Participant

      Here is one of my checkerboard images:

    • #22608
      wong
      Moderator

      Hi @toppenhe ,

      This is an opencv installation problem, you can do the following steps to solve this problem:
      1. Install the necessary dependencies

      sudo apt-get update && sudo apt-get install -y libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev libqtgui4 libqt4-test

      2. Reinstall opencv-python

      sudo pip3 uninstall opencv-python
      sudo pip3 install opencv-python==3.4.6.27

      Related Links:
      https://github.com/amymcgovern/pyparrot/issues/34

    • #22629
      toppenhe
      Participant

      Thank you, Wong!  That worked.  However, the 4_calibration.py ignored all my pairs.  My pairs looked like the image above.  Do I need to use an exact chessboard color and sequence?  What exactly is 4_calibration checking for?

       

      Thanks,

      Tom

    • #22709
      wong
      Moderator

      Hello Tom ,

      Have you tried to modify the parameters of the chessboard?

      They are in the script 4_calibration.py, you need to modify them according to your chessboard.

Viewing 18 reply threads
  • You must be logged in to reply to this topic.