4. Working with contours
Activity 4.01: Identifying a Character on a Mirrored Document
Solution:
- Open Jupyter Notebook. Go to
File
|New File
. A new file will open. Save it asActivity4.01.ipynb
. - Import the OpenCV library:
import cv2
- Read the image of the handwritten note as follows:
image = cv2.imread('phrase_handwritten.png')
- Save a copy of this image. You will mark the bounding box on this copy at the end of the activity:
imagecopy= image.copy()
- Convert the image to grayscale as follows:
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
- Now, convert the image into binary and display it as follows:
ret,binary_im = cv2.threshold(gray_image,0,255,\ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cv2.THRESH_OTSU) cv2.imshow('binary image', binary_im) cv2.waitKey(0) cv2.destroyAllWindows()
The preceding code...