Reputation: 181
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;
Upvotes: 0
Views: 4549
Reputation: 618
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.
Upvotes: 1