roamingthings / spyglass Goto Github PK
View Code? Open in Web Editor NEWA simple mjpeg server for Picamera2
License: GNU General Public License v3.0
A simple mjpeg server for Picamera2
License: GNU General Public License v3.0
The use-case we are targeting with spyglass my include setups where Raspberry Pi cameras are used along with general USB cameras.
It's important to note that spyglass will only allow to use one camera at a time (e.g. if there is more than one camera you have to start spyglass multiple times).
Spyglass should be able to use USB cameras to capture images and videos.
Sometimes camera modules will be mounted at a rotated angle. To compensate for that it would be helpful to have an option that rotates the image so it will be displayed correctly.
We need to find a balance that provides enough information when spyglass is running in normal operation and the ability to have extended logging when it's neccessary to investigate some problem.
Spyglass should provide the following log levels:
quiet
- A minimum an logging information. Mostly warnings and errors will be displayed in this modeverbose
- More information what's going on without low level detailsdebug
- Log every detailSince spyglass is integrated into other applications like crowsnest we need a cli argument to set logging level.
At the moment spyglass does not have a release process. Changes/pull requests are directly merged into the main branch.
For the future it would be nice to have a release process with versioning.
As a versioning scheme like semver seems reasonable.
At the moment there are a lot of questions:
Spyglass doesn't seem to work well with Fluidd, as it (Fluidd) adds extra parameters to the URI which Spyglass does not recognize.
http://voron0.local/webcam/?action=snapshot&cacheBust=1683694863063
(or anything) returns a 404. Browsing to it shows the stream/snapshot as expected, but Fluidd seems to always add that cacheBust
parameter.
It would be a great feature to rotate the image, as many camera mounts for printers are upside down (for Ender 3 at least).
Trying this because Klipper's Crowsnest stopped working after a recent update. I'm running mailsailos on Raspberry Pi 4 with Raspberry Pi HQ camera connected via ribbon cable. Spyglass runs for a random amount of time (usually less than 5 minutes) and then image hangs. I check dmesg
log and see this:
[ +19.760237] bcm2835-codec bcm2835-codec: Failed setting ctrl 00990a67, ret -3
[Jul26 10:36] edt_ft5x06 10-0038: Unable to fetch data, error: -121
[ +1.050539] i2c-bcm2835 fe205000.i2c: i2c transfer timed out
[ +0.000028] edt_ft5x06 10-0038: Unable to fetch data, error: -110
Restarting Spyglass works... but only for a few minutes at most, then errors out again.
NOTE: The first message in the log there happens when it starts, the other two when it freezes.
I added Spyglass as a systemctl service, so it autostarts and is controllable like crowsnest. This could maybe be added to the Readme:
Step 1: Create and open a service description
sudo nano /etc/systemd/system/spyglass.service
Step 2: Insert the following text:
[Unit]
Description=Spyglass[Service]
Type=simple
ExecStart=/usr/bin/python3 /run.py[Install]
WantedBy=multi-user.target
Step 3: Reload systemcontrol
sudo systemctl daemon-reload
Step 4: Enable Autostart of Spyglass
sudo systemctl enable spyglass.service
Step 4.5: Maybe you have to disable crowsnest first, to prevent port collision:
sudo systemctl stop crowsnest.service && sudo systemctl disable crowsnest.service
Step 5: Start your new Spyglass Service:
sudo systemctl start spyglass.service
Note that as far as I know, this only works on debian-based systems like Raspberry Pi OS and MainsailOS
Very funny situation on my use case, when I use a resolution like "1920x1440", with "vr90" option, after restart spyglass and keep refreshing the snapshot endpoint till I get the very first image, the very first image is pretty good, but the second onward is VERY noisy ๐ญ
Images after first snapshot call:
Do you have any idea what can be causing this?
I'm using tunning file: https://github.com/raspberrypi/libcamera/blob/main/src/ipa/rpi/pisp/data/ov5647_noir.json
As mentioned in raspberrypi/picamera2#473 it's currently not possible to capture snapshots/streams with more than 1920x1920.
To prevent users from running into issues due to misconfigured resolution #31 will raise an error in this case.
I followed the instructions to install Spyglass as a service but when trying to start it I get the following
spyglass.service - spyglass - Picamera2 MJPG Streamer
Loaded: loaded (/etc/systemd/system/spyglass.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2023-02-15 22:40:49 GMT; 2s ago
Docs: https://github.com/roamingthings/spyglass
Process: 9073 ExecStart=/usr/local/bin/spyglass (code=exited, status=1/FAILURE)
Main PID: 9073 (code=exited, status=1/FAILURE)
Looking at journalctl I can see:
Feb 15 22:03:20 mainsailos systemd[1]: Started spyglass - Picamera2 MJPG Streamer.
Feb 15 22:03:20 mainsailos crowsnest[927]: Version Control: rtsp-simple-server new version available: v0.20.2 (v0.19.1).
Feb 15 22:03:20 mainsailos spyglass[920]: Python 2.7.16
Feb 15 22:03:20 mainsailos spyglass[920]: INFO: Configuration file found in /home/pi/printer_data/config/spyglass.conf
Feb 15 22:03:20 mainsailos spyglass[920]: INFO: Print Configfile: '/home/pi/printer_data/config/spyglass.conf'
Feb 15 22:03:20 mainsailos spyglass[920]: NO_PROXY="true"
Feb 15 22:03:20 mainsailos spyglass[920]: HTTP_PORT="8080"
Feb 15 22:03:20 mainsailos spyglass[920]: RESOLUTION="640x480"
Feb 15 22:03:20 mainsailos spyglass[920]: FPS="15"
Feb 15 22:03:20 mainsailos spyglass[920]: STREAM_URL="/stream"
Feb 15 22:03:20 mainsailos spyglass[920]: SNAPSHOT_URL="/snapshot"
Feb 15 22:03:20 mainsailos spyglass[920]: AUTO_FOCUS="continuous"
Feb 15 22:03:20 mainsailos spyglass[920]: FOCAL_DIST="0.0"
Feb 15 22:03:20 mainsailos spyglass[920]: AF_SPEED="normal"
Feb 15 22:03:20 mainsailos spyglass[920]: Traceback (most recent call last):
Feb 15 22:03:20 mainsailos spyglass[920]: File "/home/pi/spyglass/run.py", line 3, in <module>
Feb 15 22:03:20 mainsailos spyglass[920]: from spyglass.cli import main
Feb 15 22:03:20 mainsailos spyglass[920]: File "/home/pi/spyglass/spyglass/cli.py", line 121
Feb 15 22:03:20 mainsailos spyglass[920]: SyntaxError: Non-ASCII character '\xc2' in file /home/pi/spyglass/spyglass/cli.py on line 121, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Feb 15 22:03:20 mainsailos systemd[1]: spyglass.service: Main process exited, code=exited, status=1/FAILURE
Feb 15 22:03:20 mainsailos systemd[1]: spyglass.service: Failed with result 'exit-code'.
OS info
cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
Add the ability to update an installation of Spyglass using the Moonraker update manager
pi@VzBot:~ $ spyglass/run.py
INFO:root:Spyglass 0.13.0
[0:11:41.291767898] [1709] INFO Camera camera_manager.cpp:297 libcamera v0.0.5+83-bde9b04f
[0:11:41.321646339] [1710] INFO RPI vc4.cpp:437 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media0 and ISP device /dev/media2
[0:11:41.321728469] [1710] INFO RPI pipeline_base.cpp:1101 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
INFO:picamera2.picamera2:Initialization successful.
[0:11:41.324097467] [1709] INFO Camera camera.cpp:840 Pipeline handler in use by another process
ERROR:picamera2.picamera2:Camera __init__ sequence did not complete.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 242, in __init__
self._open_camera()
File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 446, in _open_camera
self.camera.acquire()
RuntimeError: Failed to acquire camera: Device or resource busy
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/spyglass/run.py", line 6, in <module>
raise SystemExit(main())
File "/home/pi/spyglass/spyglass/cli.py", line 44, in main
picam2 = init_camera(
File "/home/pi/spyglass/spyglass/camera.py", line 26, in init_camera
picam2 = Picamera2(tuning=tuning)
File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 254, in __init__
raise RuntimeError("Camera __init__ sequence did not complete.")
RuntimeError: Camera __init__ sequence did not complete.
I have just switched from crowsnest to spyglass and when I run the script I get the above. Help is much appreciated.
I'm trying to get my pi cam v3 wide to work on my printer
hi,
few hours ago i try to install spyglass for use a pi camerza module 3 with mainsail and crowsnest.
but when i launch command i have ab error and when i clone manually the repo impossible to launch install what s wrong?
can you tell me how install it on my pi 4 please?
i ve tried that:
cd ~
git clone https://github.com/roamingthings/spyglass
cd spyglass
./run.py
but no way i ve tried wit sudo too but same results. i ve tried to create folder manually with no results again
Picamera2 provides a rich set of camera controls that allow to adjust the camera operation.
Spyglass should allow the user to configure these controls to optimize image, stream and video quality.
The Raspberry Pi camera module v3 is able to capture images in HDR (high dynamic range).
Configuration of the feature is a bit more complex. In addition an Profile has to be enabled.
When installing you have the user CD to ~/spyglass.
That directory hasn't been made, as you failed to include the portion where we should clone the repository (including the sometimes tricky addresses git likes to make).
Add the clone portion to be more in line with the platform you are developing for.
I have been experiencing MCU 'mcu' shutdown: Timer too close
errors lately suggesting that my RPi is overloaded.
I noticed that spyglass service is running 8 processes and consuming over 30% cpu.
Is there any option to reduce this?
I have unsuccessfully tried:
In a resource constrained situation, I would rather have the camera server fail / be reduced to snapshots than the print shutting down.
previously it worked fine, but I did an "sudo apt update and upgrade" a few days ago and now I'm getting the following error:
Traceback (most recent call last):
File "/home/pi/spyglass/./run.py", line 3, in
from spyglass.cli import main
File "/home/pi/spyglass/spyglass/cli.py", line 10, in
import libcamera
File "/usr/lib/python3/dist-packages/libcamera/init.py", line 4, in
from ._libcamera import *
ImportError: /usr/lib/python3/dist-packages/libcamera/_libcamera.cpython-311-aarch64-linux-gnu.so: undefined symbol: _ZN9libcamera8controls3rpi15PispStatsOutputE
My OS:
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
Spyglass should use a Python virtual environment for development and runtime.
Hi,
I am not using this with any printer software. It seems spyglass was made for some software that uses the path ~/printer_data/config
I assume there is a missing mkdir ~/printer_data/config
somewhere. I might create a PR for this, but if I do I would also change the config dir to /etc/spyglass
.
How to reproduce on vanilla raspian OS:
root@hakkebo:~# git clone https://github.com/roamingthings/spyglass.git
Cloning into 'spyglass'...
remote: Enumerating objects: 443, done.
remote: Counting objects: 100% (208/208), done.
remote: Compressing objects: 100% (103/103), done.
remote: Total 443 (delta 134), reused 131 (delta 96), pack-reused 235
Receiving objects: 100% (443/443), 104.73 KiB | 674.00 KiB/s, done.
Resolving deltas: 100% (232/232), done.
root@hakkebo:~# cd spyglass/
root@hakkebo:~/spyglass# make install
Copying systemd service file ...
Copying Spyglass launch script ...
Copying basic configuration file ...
cp: cannot create regular file '/home/root/printer_data/config': No such file or directory
make: *** [Makefile:27: install] Error 1
Regards
Stian
Hey,
i am pretty sure that this is not a bug but a user error.
My pi cam is working fine but if the light situation changes a little the white balance fails.
Any recommendation how to fix this?
Any help is appreciated!
I've installed Spyglass following these steps:
git clone https://github.com/roamingthings/spyglass.git
make install
Recovery attempt failed, repo state not pristine
Repo has not been verified, clone aborted
How can I fix this?
EDIT:
I've tried running make upgrade-moonraker
, but still the same issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.