Skip to content

Commit

Permalink
scan orientation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bleucitron committed Oct 16, 2014
1 parent 69ba285 commit dcec9d0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
21 changes: 14 additions & 7 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,27 @@
images = glob.glob("*.jpg") + glob.glob("*.JPG") + glob.glob("*.png") + glob.glob("*.PNG")
# if image then process
if len(images) > 0:
cmd = "python scan.py --image " + images[0]
os.system(cmd)
# send back
cmd = "mutt -s 'Your scanned image' -i message_ok.txt " + sender + " -a *.pdf < /dev/null"
os.system(cmd)
returncode = call(["python", "scan.py", "--image", image[0]])
if returncode == 0:
# send back the ok message with the file attached
cmd = "mutt -s 'Voilà ton scan !' -i ok_msg.txt " + sender + " -a *.pdf < /dev/null"
os.system(cmd)
else:
# the image was not correctly processed
# send back the "file not processed" error message
cmd = "mutt -s 'Elle est moche ta photo' -i error_process_msg.txt " + sender + " < /dev/null"
os.system(cmd)
else:
# send back an error mail
cmd = "mutt -s 'No image to scan' -i message_error.txt " + sender + " < /dev/null"
# there is no image to process
# send back the "no image attached" error message
cmd = "mutt -s 'Euh, elle est où ton image ?' -i error_empty_msg.txt " + sender + " < /dev/null"
os.system(cmd)


# clean
os.remove(mail)
os.system("rm -f *.JPG *.jpg *.PNG *.png *.desc")
os.system("rm -f ~/scanMail/sent/cur/*")
#call(["rm part*"])
#call(["rm "+mail,])

Expand Down
1 change: 0 additions & 1 deletion message_error.txt

This file was deleted.

1 change: 0 additions & 1 deletion message_ok.txt

This file was deleted.

4 changes: 2 additions & 2 deletions pyimagesearch/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def four_point_transform(image, pts):
# in the top-left, top-right, bottom-right, and bottom-left
# order
dst = np.array([
[0, 0],
[maxWidth - 1, 0],
[maxWidth - 1, maxHeight - 1],
[0, maxHeight - 1]], dtype = "float32")
[0, maxHeight - 1],
[0, 0]], dtype = "float32")

# compute the perspective transform matrix and then apply it
M = cv2.getPerspectiveTransform(rect, dst)
Expand Down
10 changes: 7 additions & 3 deletions scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@
screenCnt = approx
break

file =open
file.write
file.close

# apply the four point transform to obtain a top-down
# view of the original image
warped = four_point_transform(orig, screenCnt.reshape(4, 2) * ratio)

# convert the warped image to grayscale, then threshold it
# to give it that 'black and white' paper effect
warped = cv2.cvtColor(warped, cv2.COLOR_BGR2GRAY)
warped = threshold_adaptive(warped, 250, offset = 10)
warped = warped.astype("uint8") * 255
# warped = cv2.cvtColor(warped, cv2.COLOR_BGR2GRAY)
# warped = threshold_adaptive(warped, 250, offset = 10)
# warped = warped.astype("uint8") * 255

final = imutils.resize(warped, height = 650)

Expand Down

0 comments on commit dcec9d0

Please sign in to comment.