Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Computer Vision Workshop

You're reading from   The Computer Vision Workshop Develop the skills you need to use computer vision algorithms in your own artificial intelligence projects

Arrow left icon
Product type Paperback
Published in Jul 2020
Publisher Packt
ISBN-13 9781800201774
Length 568 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Nikhil Singh Nikhil Singh
Author Profile Icon Nikhil Singh
Nikhil Singh
Hafsa Asad Hafsa Asad
Author Profile Icon Hafsa Asad
Hafsa Asad
Vishwesh Ravi Shrimali Vishwesh Ravi Shrimali
Author Profile Icon Vishwesh Ravi Shrimali
Vishwesh Ravi Shrimali
Arrow right icon
View More author details
Toc

4. Working with contours

Activity 4.01: Identifying a Character on a Mirrored Document

Solution:

  1. Open Jupyter Notebook. Go to File | New File. A new file will open. Save it as Activity4.01.ipynb.
  2. Import the OpenCV library:
    import cv2
  3. Read the image of the handwritten note as follows:
    image = cv2.imread('phrase_handwritten.png')
  4. Save a copy of this image. You will mark the bounding box on this copy at the end of the activity:
    imagecopy= image.copy()
  5. Convert the image to grayscale as follows:
    gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  6. 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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime