I am writing a paperless transaction system, and I have pretty much everything to a beta stage. I have one issue, when a user faxes a document right side up, the fax server returns the faxed document upside down. Since I am using datamatrix 2 barcodes, the decoder can not read this barcode. So I have to rotate the image 90 degrees.
Now here is the pickle I am in. If the document was faxed the correct way, I do not want to rotate the document, but if it was faxed the incorrect way, I want to rotate the document.
Is there any tool within imagemagick that will let me determine the orientation of the document?
The only other solution I have is, to read the document, and if it does not return a var, then rotate the document. But I would like to avoid this if possible.
Rotating Tiff Files
ImageMagick has an autorotate option but only if the image includes an EXIF profile with the rotate flag set. We suspect your faxes do not have an EXIF profile but they might if they are delivered as TIFF images. Without a property indicating orientation, you will need to determine orientation yourself.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Without any form of meta data you need to figure out the orientation from the image itself.
That is hard.
With a Optical char reader, (OCR) you could tyr readin a small segment of text form the document and see if it is reconized, It only takes four goes!
Otherwsie you need to find and compare some identifying mark... like a special dot in one corner.
getting a computer to actually undersatnd anythiong about the actual content of an image is a difficult (near imposible) thing.. Thgis is why computer vision is such a big research area.
That is hard.
With a Optical char reader, (OCR) you could tyr readin a small segment of text form the document and see if it is reconized, It only takes four goes!
Otherwsie you need to find and compare some identifying mark... like a special dot in one corner.
getting a computer to actually undersatnd anythiong about the actual content of an image is a difficult (near imposible) thing.. Thgis is why computer vision is such a big research area.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Both of these are really good ideas. But this is what I have come up with so far. Not sure if it is the best way.
Right now, if the faxed documents orientation is incorrect, the barcode reader returns a false value. So what I have done is this, if the value is false, I use mogrify to rotate the document 180 degrees, then I attempt to re-read the barcode. If it returned value is not false it returns the value of the barcode.
To me this seems like a bandaid fix and is far from best practices. I will look into either meta data or EXIF and see what I can come up with.
Thank you for your help.
Right now, if the faxed documents orientation is incorrect, the barcode reader returns a false value. So what I have done is this, if the value is false, I use mogrify to rotate the document 180 degrees, then I attempt to re-read the barcode. If it returned value is not false it returns the value of the barcode.
To me this seems like a bandaid fix and is far from best practices. I will look into either meta data or EXIF and see what I can come up with.
Thank you for your help.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Barcodes are not a very doo way of orientation. It will get the vertical orientation correct, but will not tell you if it is upsidedown or rightwayup.
Barcodes were designed specifically so that can be read at any near constant speed, at any angle and in any direction. The only time they fail to be read is if the scan was sideways to the barcode. It will definateally not tell you if the fax was sent crooked, that is a with a slight missfeed so it is angled slightly.
However if your barcode scanner software is good, it should be able to tell you if it was scanned backwards or forwards. Most readers however do not inform you of this as it is typically not important. Its job after all is to extract a number from the barcode, not tell you if it was read fast or slow (depending on angle) or the direction it was read.
But rhalving your orientation posibilities is a good start.
However if you know if the barcode is in say the top left corner, then you can just divide the image into quaters and see which part has the barcode! That is one way to determine orientation!
Barcodes were designed specifically so that can be read at any near constant speed, at any angle and in any direction. The only time they fail to be read is if the scan was sideways to the barcode. It will definateally not tell you if the fax was sent crooked, that is a with a slight missfeed so it is angled slightly.
However if your barcode scanner software is good, it should be able to tell you if it was scanned backwards or forwards. Most readers however do not inform you of this as it is typically not important. Its job after all is to extract a number from the barcode, not tell you if it was read fast or slow (depending on angle) or the direction it was read.
But rhalving your orientation posibilities is a good start.
However if you know if the barcode is in say the top left corner, then you can just divide the image into quaters and see which part has the barcode! That is one way to determine orientation!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/