acawley
Posts: 37
Joined: Sun Feb 24, 2013 8:22 pm

Rotating a photo only slightly

Sat Jun 23, 2018 11:26 am

Is it possible to rotate a photo on the shell of a Raspberry Pi but only slight measures or degrees? For example if I had this image which is taken by a remote camera:
voltage.jpg
voltage.jpg (212.16 KiB) Viewed 491 times
And I wanted the 12.8v value to be perfectly horizontal through rotating the image only slightly, I don't mind about cropping or trimming the image.

I have been looking at the command: raspistill -rot (rotate) although I'm a little confused by what I have read around and I don't know if it would be suitable for my needs. Any pointers from anyone who has done this?

User avatar
DougieLawson
Posts: 33626
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Rotating a photo only slightly

Sat Jun 23, 2018 11:46 am

voltageRot.jpg
voltageRot.jpg (35.01 KiB) Viewed 485 times
GIMP on Windows is able to do it. GIMP can be run on a Raspberry.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
DougieLawson
Posts: 33626
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Rotating a photo only slightly

Sat Jun 23, 2018 11:50 am

That was a -7.4° rotation.
I did that with GIMP on Windows.

You should be able to use PIL/Pillow in python to do the same.

raspistill only supports positive rotation between 0 and 360 (it appears to accept a decimal 352.6 value).
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

acawley
Posts: 37
Joined: Sun Feb 24, 2013 8:22 pm

Re: Rotating a photo only slightly

Sat Jun 23, 2018 12:22 pm

Thanks for the suggestion Dougie, but I'm looking to achieve this in an automated fashion on the shell of the Pi if possible, I'm comfortable creating a bash script for that providing I know the right tool to use - but this is where I am struggling.

I made this script: https://github.com/ashleycawley/voltage ... -upload.sh which is trigger by CRON every 15 minutes, it takes a photo and uploads it here: http://solar.ashleycawley.co.uk/

I am exploring the possibility of post-processing the image in an automated fashion (so rotating slightly, perhaps even cropping), once I have the voltage clear and level I may explore the possibility of using OCR technology to interpret and store the voltage value.

Thanks for your time and help.

User avatar
scruss
Posts: 1770
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Rotating a photo only slightly

Sat Jun 23, 2018 3:57 pm

  • is there any way you can manually straighten the rig?
  • there are many reflections on the display. OCR does not like that
  • ssocr, the Seven Segment Optical Character Recognition tool, has a rotate option. Note that it only take positive degrees, so to get your image roughly straight I specified rotate 354. ssocr also has a crop option to mask out the bits you want.
  • your image isn't very sharp or very big: the more pixels the better for OCR
  • please cap those battery terminals: they're a fire risk as they are.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

gordon77
Posts: 3343
Joined: Sun Aug 05, 2012 3:12 pm

Re: Rotating a photo only slightly

Sat Jun 23, 2018 4:22 pm

You could call a python script and use pygame.transform.rotate()

acawley
Posts: 37
Joined: Sun Feb 24, 2013 8:22 pm

Re: Rotating a photo only slightly

Sat Jun 23, 2018 6:10 pm

Thanks for the input gordon and scruss!

I could straighten the rig but not immediately (it is somewhat remote). I can also modify the casing to reduce reflections, so duly noted.

I purposely lowered the size of the image for automatic upload to my page to minimise on bandwidth and speed things up, but prior to that I could have the OCR software work on a full resolution copy of the image locally, then once done resize / lower the resolution and upload, sp thank you for the tip on higher-res, it makes sense that it would have better luck with more detail.

I'm looking forward to checking out ssocr.

Your absolutely right on the battery terminals - I will take action on those.

acawley
Posts: 37
Joined: Sun Feb 24, 2013 8:22 pm

Re: Rotating a photo only slightly

Sat Jun 23, 2018 6:37 pm

I have ssocr installed and working with its test example on the shell of the Pi which is great!

But could you help me out with the correct example usage? I'm trying to reference the manual but not sure if I should be using something like:

ssocr -T rotate 354 voltage.jpg

I have a suspicion that -T may be instructing it to look specifically for six numbers? I would love to see some example usage from someone who is used to this tool.

I'm looking at some example usage here: https://www.home-assistant.io/component ... _segments/ as I think it may be useful to make use of cropping as well, but I would love to understand how you could determine the positioning of the crop - if it outputted a sample image for you to look at what it is cropping I wouldn't mind doing many versions and going by trial and error.

PiGraham
Posts: 3394
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Rotating a photo only slightly

Sat Jun 23, 2018 6:48 pm

You can use Image Magick to rotate an image. mogrify or convert will take a rotation angle in degrees.

http://www.minihowtos.net/imagemagick-rotate-image

http://www.imagemagick.org/Usage/distor ... te_methods

acawley
Posts: 37
Joined: Sun Feb 24, 2013 8:22 pm

Re: Rotating a photo only slightly

Sat Jun 23, 2018 9:38 pm

PiGraham wrote:
Sat Jun 23, 2018 6:48 pm
You can use Image Magick to rotate an image. mogrify or convert will take a rotation angle in degrees.

http://www.minihowtos.net/imagemagick-rotate-image

http://www.imagemagick.org/Usage/distor ... te_methods
Great suggestion - thank you!

I already had Image Magick installed as I was using it to add a timestamp to the image, so after reading your comment I used this to rotate the image slightly, that worked a treat.

Thanks to scruss I'm now using ssocr to try and crop and interpret the image, I'm playing around and have this so far (this is an image from ssocr debug mode to "see" what it sees...)
testbild.png
testbild.png (2.94 KiB) Viewed 381 times
Unfortunately I don't have it outputting the correct values to the shell at the moment but it is work in progress cleaning it all up. I'm using this command at the moment:

Code: Select all

ssocr -D crop 585 150 225 125 -t 45 -d -1 1080.jpg
Tomorrow I think I will work on manually rearranging the frame, experiment with how close I can get the Pi camera to focus and defusing the ambient light that gets through the casing to reduce reflections etc. Any input gratefully received and thank you for your help so far everyone.

acawley
Posts: 37
Joined: Sun Feb 24, 2013 8:22 pm

Re: Rotating a photo only slightly

Sat Jun 23, 2018 9:51 pm

Just achieved it! ...
testbild-worked.png
testbild-worked.png (2.43 KiB) Viewed 372 times

Code: Select all

[email protected]:~ $ ssocr -D crop 585 155 225 115 -t 58 -d -1 1080.jpg
12.6
:D

User avatar
scruss
Posts: 1770
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Rotating a photo only slightly

Sun Jun 24, 2018 8:07 pm

Nice! I've never found a direct use for ssocr yet, so I'm glad it's proving useful.

As someone old enough to remember paying someone in the field to phone a reading to us from a remote meter, this is a huge improvement. While I'm sure the guy we used to use to call in the numbers appreciated the beer money, I'm sure he would have much more appreciated not having to trudge across a marsh to read the thing in the first place.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: No registered users and 8 guests