0

I have a scanned file as a pdf and sometimes scanned documents may be upside down or flipped. I want to be able to rotate the document to proper reading format. Also the scanned document already had a QR code is there a way to detect where the QR code is at because the proper alignment would be that the QR code has to be on the top left corner. that way the text is proper as well.

Here is what i have - it works great rotating an upside down document but if the document was scanned in proper format it saves it upside down.

if(page.Rotate != 180)
    page.Rotate = (page.Rotate + 180)%360;
BB987
  • 181
  • 3
  • 14
  • How can you tell (programatically) that a document is upside down? – Daniel Kelley Feb 27 '13 at 14:30
  • Am I right when I say you've found out how many degrees the page has turned, and try to turn them all to proper format, but it doesn't work when it's already in proper format? – Joetjah Feb 27 '13 at 14:31
  • @DanielKelley well... i am trying to figure that out too. i wanted to find a way to detect where the QR code is located on the scanned pdf and that way i will be able to figure out the current position and then now how to rotate properly. – BB987 Feb 27 '13 at 14:32
  • @Joetjah with current page rotate it rotates to the right position if the doc is scanned upside down. But if the doc was scanned properly - these two lines of code flip what is already in correct format to be upside down. – BB987 Feb 27 '13 at 14:34
  • If you can only have two values (or 3), being (0, ) 180 and 360, then I'd say 180 is upside down. True? Then when you have 0 and 360, it's not upsidedown and therefore correct. So when `page.Rotate == 180)`, you rotate: `page.Rotate += 180;`. – Joetjah Feb 27 '13 at 14:37
  • Also, the Zxing library helps with detecting and decoding QR Codes. – Joetjah Feb 27 '13 at 14:44

1 Answers1

1

Just try all combinations of flipped and rotated, looking for the QR code being in the correct position and orientation. In pseudocode:

images = array()
images[0] = masterimage.flip(false).rotate(0)
images[1] = masterimage.flip(false).rotate(180)
images[2] = masterimage.flip(true).rotate(0)
images[3] = masterimage.flip(true).rotate(180)

for i = 0...3
    if qrCodePlacedCorrectly(images[i])
        output = images[i]
        quit

The hard part is detecting the QR code. It should be do-able, since they are a square shape, always with three guaranteed dots; Top right, top left, and bottom left corners. This S.O. question should help in detecting the QR code.

Community
  • 1
  • 1
E.T.
  • 598
  • 3
  • 21