corrupted output

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
scr44tch
Posts: 4
Joined: 2016-11-12T07:46:06-07:00
Authentication code: 1151

corrupted output

Post 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,
Image
but sometimes the picture is cut in half like this one
Image

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
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: corrupted output

Post 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.
Last edited by glennrp on 2016-11-12T09:21:27-07:00, edited 2 times in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: corrupted output

Post 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.
scr44tch
Posts: 4
Joined: 2016-11-12T07:46:06-07:00
Authentication code: 1151

Re: corrupted output

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: corrupted output

Post 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.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: corrupted output

Post 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.
scr44tch
Posts: 4
Joined: 2016-11-12T07:46:06-07:00
Authentication code: 1151

Re: corrupted output

Post 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

Image

do you have any other advise?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: corrupted output

Post 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"
scr44tch
Posts: 4
Joined: 2016-11-12T07:46:06-07:00
Authentication code: 1151

Re: corrupted output

Post 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
Post Reply