Page 1 of 1
corrupted output
Posted: 2016-11-12T08:02:12-07:00
by scr44tch
I have a webcam and a pi3
im running this script every 30 seconds via crontab
Code: Select all
#!/bin/bash
cd /srv/ftp/webcam
convert "$(ls -t *.jpg | head -1)" -crop 2560x1440+128+0 +repage /home/timelapse/webcam.png
convert /home/timelapse/webcam.png -chop 0x70 -background "#000000" -flatten -splice 0x70 -gravity NorthWest -fill white -font DejaVu-Sans -pointsize 35 -annotate +30+16 'www.gaestehaus-kleinwalsertal.de' -gravity NorthEast -fill white -font DejaVu-Sans -pointsize 35 -annotate +25+16 "$(date +"%d.%m.%y - %H:%M Uhr")" /home/timelapse/webcam1.png
composite -geometry +40+85 /home/logos/logo.png /home/timelapse/webcam1.png /home/timelapse/webcam2.png
composite -geometry +2460+85 /home/logos/kwt.png /home/timelapse/webcam2.png /home/timelapse/webcam3.png
composite -geometry +500+85 /home/logos/bbt.png /home/timelapse/webcam3.png /home/timelapse/$(date +%d.%m.%y_%H:%M:%S).jpg
rm /home/timelapse/*.png
every 30 seconds it grabs the latest webcam picture and adds some logos, url and the date, it works most of the time,
but sometimes the picture is cut in half like this one
the original photos from the webcam are 100% ok
i use the pictures to make a timelapse and the corrupted images are not looking good in the final video.
there are some days without any corruptions and there are days with dozens of them.
hope you can give me some advice
Re: corrupted output
Posted: 2016-11-12T09:14:26-07:00
by glennrp
There's probably a delay somewhere causing the image to be cut off by the next image arriving. ImageMagick itself is probably not the culprit; it should be able to do the convert and three composite operations in much less than 30 seconds. But, for efficiency, I'd combine the three overlay images into one wide strip, though, and do only one composite operation each time.
If it turns out to be a communication delay between the webcam and your computer, the easiest thing to do is update every minute or two instead of every 30 seconds. Years ago it annoyed me when colleagues would use a weather map for their screen background and update it every 10 seconds over a 9600-baud connection, and then wonder why real work got bogged down.
Re: corrupted output
Posted: 2016-11-12T09:14:49-07:00
by Bonzo
That is an incomplete image and could be caused by the temporary images being overwritten by the new versions.
Out of interest I would time how long it takes your Pi to complete the process.
You could either have dynamic names for the temporary images or combine your commands. I suppose this method could also cause more problems as it could end up freezing the Pi if it gets to far behind!
Another thing you could do is have your URL + 2 logo's and black background on a transparent canvas and put all the items on in one go. Then add the time. As glenrp said before I posted this.
Re: corrupted output
Posted: 2016-11-12T13:25:06-07:00
by scr44tch
thanks for your answers.
the pi usually took about 8 seconds to complete the script.
i made a transparent canvas with the 3 images + url
and only crop the image, add the canvas and add the date.
now it takes the pi about 3 seconds, much better, thanks for the advice.
i use png for the temporary files, because i read somewhere this would be better than use jpg.
is this true? when i use jpg the script completes even faster
Re: corrupted output
Posted: 2016-11-12T13:37:09-07:00
by Bonzo
With a jpg you get the jpg compression which may or not matter.
What is your exact code now as there might be room for further improvement. You might be able to get it all onto one convert command.
Re: corrupted output
Posted: 2016-11-12T14:42:08-07:00
by glennrp
Jpeg won't work for your transparent logos. I'd combine them into a raw RGBA (just once) and then use that as the source for compositing over the webcam photo. Just be aware that you have to keep track of the dimensions of the RGBA and pass them along separately via a "-size WxH" option, because RGBA has no image header.
Re: corrupted output
Posted: 2016-11-13T02:10:11-07:00
by scr44tch
this is my new script
Code: Select all
#!/bin/bash
cd /srv/ftp/webcam
convert "$(ls -t *.jpg | head -1)" -crop 2560x1440+128+0 +repage /home/timelapse/webcam.png
composite -geometry +0+0 /home/logos/template-small.png /home/timelapse/webcam.png /home/timelapse/webcam1.png
convert /home/timelapse/webcam1.png -gravity NorthEast -fill white -font DejaVu-Sans -pointsize 35 -annotate +25+16 "$(date +"%d.%m.%y - %H:%M Uhr")" /home/timelapse/$(date +%d.%m.%y_%H:%M:%S).jpg
rm /home/timelapse/*webcam*
this is my new template
do you have any other advise?
Re: corrupted output
Posted: 2016-11-13T03:01:33-07:00
by Bonzo
I do not use bash and hard coded the variables. I must either have missed out a resize of the original somewhere or the template you uploaded is smaller.
This worked but I am not sure if it is faster ( I used a version 7 of Imagemagick hence the magick rather than convert ):
Code: Select all
magick "background.jpg" -crop 2560x1440+128+0 +repage "template.png" -composite -geometry +0+0 -gravity NorthEast -fill white -pointsize 35 -annotate +25+16 "date 18:56" "result.jpg"
Re: corrupted output
Posted: 2016-11-13T07:26:30-07:00
by scr44tch
i edited my script to be a oneliner here it is
Code: Select all
convert "$(ls -t /srv/ftp/webcam/*.jpg | head -1)" -crop 2560x1440+128+0 +repage "/home/logos/template-small.png" -composite -geometry +0+0 -gravity NorthEast -fill white -font DejaVu-Sans -pointsize 35 -annotate +25+16 "$(date +"%d.%m.%y - %H:%M Uhr")" "/home/timelapse/$(date +%d.%m.%y_%H:%M:%S).jpg"
its finished in a blink of an eye,
i will test this for a while
thx