Python Scripts Not Working
Published by david123718 on
New Home › Forums › 1. Cameras Modules for Raspberry Pi › 5MP OV5647 V1 Cameras › Python Scripts Not Working
- This topic has 20 replies, 5 voices, and was last updated 8 months ago by
wong.
- AuthorPosts
- November 12, 2019 at 2:42 pm #12531
david123718
ParticipantHi!
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]pi:~/RaspberryPi/Motorized_Focus_Camera $ import pygame
import-im6.q16: unable to open X server `’ @ error/import.c/ImportImageCommand/3 58.Any suggestions to fix?
- November 13, 2019 at 2:20 am #12537
bin
KeymasterHello,
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 enabledA1: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
- November 13, 2019 at 6:07 am #12558
david123718
ParticipantHi,
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 1 year, 2 months ago by
david123718.
- This reply was modified 1 year, 2 months ago by
- November 13, 2019 at 7:56 am #12585
Lee Jackson
KeymasterIt 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.
- November 13, 2019 at 12:27 pm #12624
david123718
ParticipantHi, @Lee Jackon
When I ran the vcgencmd get_camera command this is what I got:
supported=1 detected=1
The setup is pretty simple,
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.
- November 14, 2019 at 2:00 am #12652
david123718
ParticipantThis 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 - November 14, 2019 at 3:23 am #12657
bin
KeymasterWe 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.
- November 14, 2019 at 5:49 am #12664
david123718
ParticipantUh 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
- November 14, 2019 at 4:47 am #12658
david123718
ParticipantFixed!
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.
- November 14, 2019 at 5:49 am #12665
david123718
ParticipantUh 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
- November 16, 2019 at 1:14 pm #12750
Lee Jackson
KeymasterDoes it work or not, I saw you post the same error twice.
- November 17, 2019 at 12:09 am #12795
david123718
ParticipantI 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.
- November 21, 2019 at 2:05 pm #13069
Lee Jackson
Keymaster@david123718 I’m glad to hear that it works now.
- May 12, 2020 at 4:06 pm #22532
toppenhe
ParticipantHello,
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.calibrationI 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
- May 13, 2020 at 1:59 am #22557
- May 13, 2020 at 11:40 am #22597
toppenhe
ParticipantHi,
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 directoryThank you for help!
- May 13, 2020 at 6:39 pm #22599
toppenhe
Participant - May 13, 2020 at 6:39 pm #22598
toppenhe
ParticipantHere is one of my checkerboard images:
- May 13, 2020 at 7:04 pm #22608
wong
ModeratorHi @toppenhe ,
This is an opencv installation problem, you can do the following steps to solve this problem:
1. Install the necessary dependenciessudo 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.27Related Links:
https://github.com/amymcgovern/pyparrot/issues/34 - May 14, 2020 at 9:44 am #22629
toppenhe
ParticipantThank 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
- May 17, 2020 at 5:43 pm #22709
wong
ModeratorHello 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.
- AuthorPosts
- You must be logged in to reply to this topic.