×

INDI Library v2.0.7 is Released (01 Apr 2024)

Bi-monthly release with minor bug fixes and improvements

Weather radio don`t want connect camera integration

  • Posts: 50
  • Thank you received: 1
Hello everyones,

I am trying to integrate a camera inside weatherradio like said this section:

github.com/indilib/indi-3rdparty/blob/ma...adme-WeatherRadio.md

I am using:

a Raspberry Zero with raspbian buster os
a Raspberry Camera OV5647

Raspistill is working because i capture images with this instruction:

raspistill -ISO 100 -ss 1000 -v -o /usr/share/weatherradio/html/media/current_weather.jpg

"raspistill" Camera App (commit bab9bf8790cd Tainted)

Camera Name ov5647
Width 2592, Height 1944, filename /usr/share/weatherradio/html/media/current_weather.jpg
Using camera 0, sensor mode 0

GPS output Disabled

Quality 85, Raw no
Thumbnail enabled Yes, width 64, height 48, quality 35
Time delay 5000, Timelapse 0
Link to latest frame enabled no
Full resolution preview No
Capture method : Single capture

Preview Yes, Full screen Yes
Preview window 0,0,1024,768
Opacity 255
Sharpness 0, Contrast 0, Brightness 50
Saturation 0, ISO 100, Video Stabilisation No, Exposure compensation 0
Exposure Mode 'auto', AWB Mode 'auto', Image Effect 'none'
Flicker Avoid Mode 'off'
Metering Mode 'average', Colour Effect Enabled No with U = 128, V = 128
Rotation 0, hflip No, vflip No
ROI x 0.000000, y 0.000000, w 1.000000 h 1.000000
Camera component done
Encoder component done
Starting component connection stage
Connecting camera preview port to video render.
Connecting camera stills port to encoder input port
Opening output file /usr/share/weatherradio/html/media/current_weather.jpg
Enabling encoder output port
Starting capture -1
Finished capture -1
Closing down
Close down completed, all components disconnected, disabled and destroyed


My problem its with script camery.py that is in

/usr/share/weatherradio/bin the script said this:

#!/usr/bin/python3

#
# Script for shooting single images with automatic exposure adaption
# day and night..
#
# Copyright (C) 2020 Wolfgang Reissenberger <This email address is being protected from spambots. You need JavaScript enabled to view it.>
#
# This application is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
#

import os, stat
from datetime import datetime
from pathlib import Path
from configparser import ConfigParser
from pid.decorator import pidfile
from pid import PidFileError
from autoexposure import *

def init_config(inifile_name):
config = ConfigParser(interpolation=None)
config.optionxform = str
# default values
config.add_section('Camera')
config.set('Camera', 'ExposureTime', '400') # 1/250 sec
config.set('Camera', 'BaseDirectory', ".")
config.set('Camera', 'ConverterFIFO', "/tmp/imageconverter.fifo")
config.set('Camera', 'ISOSpeedRatings', '50')
config.set('Camera', 'Contrast', '0')
config.set('Camera', 'Brightness', '50')
config.set('Camera', 'Saturation', '0')
config.set('Camera', 'Options', '-md 4 -ex fixedfps')
# night default settings
config.add_section('Night')
config.set('Night', 'Contrast', '100')
config.set('Night', 'Brightness', '20')
config.set('Night', 'Saturation', '-80')
config.set('Night', 'MaxExposure', '10000000')
config.set('Night', 'MaxISO', '800')

config.read(inifile_name)
return config

@pidfile()
def main():
inifile_name = os.path.dirname(os.path.realpath(__file__)) + '/camera.ini'

now = datetime.now()
config = init_config(inifile_name)

dir = config.get('Camera', 'BaseDirectory')

filename = now.strftime("%Y-%m-%d_%H%M%S") + ".jpg"
fullname = dir + '/' + filename
fifo = config.get('Camera', 'ConverterFIFO')
exptime = config.getint('Camera', 'ExposureTime')
iso = config.getint('Camera', 'ISOSpeedRatings')
brightness = config.getint('Camera', 'Brightness')
contrast = config.getint('Camera', 'Contrast')
saturation = config.getint('Camera', 'Saturation')
opts = config.get('Camera', 'Options')

# ensure that the image directory exists
if not Path(dir).exists():
Path(dir).mkdir(parents=True)

# change to auto exposure for short exposure times
expstr = "-ss %d" % (exptime) if exptime > 10000 else "-ex auto"

# shoot the image
os.system("raspistill %s -ISO %d -br %d -co %d -sa %d %s -o %s" % (opts, iso, brightness, contrast, saturation, expstr, fullname))

# calculate the optimal exposure time
(imgExpTime, imgBrightness) = calibrateExpTime(fullname, config)

# start converter process
if os.path.exists(fifo) and stat.S_ISFIFO(os.stat(fifo).st_mode):
with open(fifo, 'w') as pipeout:
pipeout.write("%s\n" % filename)
else:
targetdir = dir + '/' + now.strftime("%Y-%m-%d")
target = targetdir + '/' + filename
# ensure that the image directory exists
if not Path(targetdir).exists():
Path(targetdir).mkdir(parents=True)
# mv to target directory
os.rename(fullname, target)

configfile = open(inifile_name, 'w')
config.write(configfile)
configfile.close()

print("date=%s; time=%s; file=%s; ex=%d; iso=%d; br=%s; sat=%d; co=%d img brightness=%d" % (now.strftime("%Y-%m-%d"), now.strftime("%H:%M:%S"), filename, imgExpTime, iso, brightness, saturation, contrast, imgBrightness))

if __name__ == "__main__":
try:
main()
except PidFileError:
print ("Capture still running")


When i run this script i got an error:

javier@raspberrypi:/usr/share/weatherradio $ ./bin/camera.py
Traceback (most recent call last):
File "./bin/camera.py", line 101, in <module>
main()
File "/usr/local/lib/python3.7/dist-packages/pid/decorator.py", line 14, in decorator
return func(*func_args, **func_kwargs)
File "./bin/camera.py", line 78, in main
(imgExpTime, imgBrightness) = calibrateExpTime(fullname, config)
File "/usr/share/weatherradio/bin/autoexposure.py", line 107, in calibrateExpTime
realExpTime = 1000000 * exifexptime[0] / exifexptime[1]
TypeError: 'IFDRational' object is not subscriptable

Please, somebody can help me?
3 months 3 weeks ago #100948

Please Log in or Create an account to join the conversation.

  • Posts: 50
  • Thank you received: 1
Hi everybody,

i found my own solution to capture images and timelapse usin raspistill, ffmpeg and cron lets go to how i did it:

1 - Use the raspistill tool to capture a simpel image:
raspistill -v -o /usr/share/weatherradio/html/media/current_weather.jpg

If its works, then go to next step

2 - install ffmpeg and create directories:
sudo apt install ffmpeg
sudo mkdir /usr/share/weatherradio/html/media/timelapse/
sudo mkdir /usr/share/weatherradio/html/media/timelapse/backup

3 - Create a new crontab
sudo crontab -e

4 - Paste this code:

#
#
#
# WEBCAM FILES STORAGE PROCEDURE
#Each minute: Copy last capture from 'media' folder to timelapse directory and rename with yyyy-mm-dd_hh:mm
* * * * * cp /usr/share/weatherradio/html/media/current_weather.jpg /usr/share/weatherradio/html/media/timelapse/`date "+\%F"`_`date "+\%R"`.jpg

#Each hour: Move captured files to backup/date directory except last 60 captures
1 0 * * * mv /usr/share/weatherradio/html/media/timelapse/*_22:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 1 * * * mv /usr/share/weatherradio/html/media/timelapse/*_23:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 2 * * * mv /usr/share/weatherradio/html/media/timelapse/*_00:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 3 * * * mv /usr/share/weatherradio/html/media/timelapse/*_01:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 4 * * * mv /usr/share/weatherradio/html/media/timelapse/*_02:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 5 * * * mv /usr/share/weatherradio/html/media/timelapse/*_03:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 6 * * * mv /usr/share/weatherradio/html/media/timelapse/*_04:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 7 * * * mv /usr/share/weatherradio/html/media/timelapse/*_05:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 8 * * * mv /usr/share/weatherradio/html/media/timelapse/*_06:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 9 * * * mv /usr/share/weatherradio/html/media/timelapse/*_07:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 10 * * * mv /usr/share/weatherradio/html/media/timelapse/*_08:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 11 * * * mv /usr/share/weatherradio/html/media/timelapse/*_09:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 12 * * * mv /usr/share/weatherradio/html/media/timelapse/*_10:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 13 * * * mv /usr/share/weatherradio/html/media/timelapse/*_11:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 14 * * * mv /usr/share/weatherradio/html/media/timelapse/*_12:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 15 * * * mv /usr/share/weatherradio/html/media/timelapse/*_13:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 16 * * * mv /usr/share/weatherradio/html/media/timelapse/*_14:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 17 * * * mv /usr/share/weatherradio/html/media/timelapse/*_15:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 18 * * * mv /usr/share/weatherradio/html/media/timelapse/*_16:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 19 * * * mv /usr/share/weatherradio/html/media/timelapse/*_17:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 20 * * * mv /usr/share/weatherradio/html/media/timelapse/*_18:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 21 * * * mv /usr/share/weatherradio/html/media/timelapse/*_19:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 22 * * * mv /usr/share/weatherradio/html/media/timelapse/*_20:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`
1 23 * * * mv /usr/share/weatherradio/html/media/timelapse/*_21:*.jpg /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`

# Each day: make new date directory at 00:00 inside backup folder
0 0 * * * mkdir /usr/share/weatherradio/html/media/timelapse/backup/`date "+\%F"`

# Each 3 months: clean and erase all directories from backup folder
2 0 1 3 * rm -rf /usr/share/weatherradio/html/media/timelapes/backup/*
2 0 1 6 * rm -rf /usr/share/weatherradio/html/media/timelapes/backup/*
2 0 1 9 * rm -rf /usr/share/weatherradio/html/media/timelapes/backup/*
2 0 1 12 * rm -rf /usr/share/weatherradio/html/media/timelapes/backup/*

#WEBCAM CAPTURES PROCEDURE
#NIGHT EXPOSURE
30-59 21 * * * raspistill -w 640 -h 480 -th none -n -q 100 -o /usr/share/weatherradio/html/media/current_weather.jpg -awb greyworld -ISO 800 -ss 2000000
* 22-23 * * * raspistill -w 640 -h 480 -th none -n -q 100 -o /usr/share/weatherradio/html/media/current_weather.jpg -awb greyworld -ISO 800 -ss 3000000
* 0-5 * * * raspistill -w 640 -h 480 -th none -n -q 100 -o /usr/share/weatherradio/html/media/current_weather.jpg -awb greyworld -ISO 800 -ss 3000000
0-15 6 * * * raspistill -w 640 -h 480 -th none -n -q 100 -o /usr/share/weatherradio/html/media/current_weather.jpg -awb greyworld -ISO 800 -ss 3000000

#SUNRISE EXPOSURE
15-59 6 * * * raspistill -w 640 -h 480 -th none -n -q 100 -o /usr/share/weatherradio/html/media/current_weather.jpg -awb greyworld -co 50

#DAY EXPOSURE
* 7-20 * * * raspistill -w 640 -h 480 -th none -n -q 100 -o /usr/share/weatherradio/html/media/current_weather.jpg -awb greyworld -co 50
0-15 21 * * * raspistill -w 640 -h 480 -th none -n -q 100 -o /usr/share/weatherradio/html/media/current_weather.jpg -awb greyworld -co 50

#SUNSET EXPOSURE
15-30 21 * * * raspistill -w 640 -h 480 -th none -n -q 100 -o /usr/share/weatherradio/html/media/current_weather.jpg -awb greyworld -co 50 -ISO 800 -ss 1000000

#MP4 VIDEO TIMELAPSE CREATION
*/4 * * * * ffmpeg -r 4 -f image2 -pattern_type glob -i '/usr/share/weatherradio/html/media/timelapse/*.jpg' -s 640x480 -vcodec libx264 -y /usr/share/weatherradio/html/media/timelapse_current.mp4
#
#
#

5 - Finally save file and restart cron
sudo service cron restart

That's all folks!!!

NOTE: Raspistill only works upto buster raspbian OS.

For Bullseye raspbian OS or lastest Boookworm, use libcamera tool instead of raspistill, you can see kit instructions for libcamera here:
docs.arducam.com/Raspberry-Pi-Camera/Nat...ibcamera-User-Guide/
www.waveshare.com/wiki/Template:RPi_Camera_Libcamera_Guide
Last edit: 3 months 2 weeks ago by Javier Albella.
3 months 2 weeks ago #100982

Please Log in or Create an account to join the conversation.

Time to create page: 0.426 seconds