Python Scripts Not Working

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?

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

  1. 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

 

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

 

@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.

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

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

@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.

 

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.

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

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

@david123718

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

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.

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

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

 

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”

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!

Here is one of my checkerboard images:

checkerboard

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

  1. 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

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