Project - Mask R-CNN with OpenCV for Object Detection

5 / 8

Reading and Preprocessing the image

  • It's time for reading the image file and converting it to a blob.


  • In the context of deep learning, a blob is also the entire image pre-processed and prepared for classification/training. Such pre-processing usually entails mean subtraction and scaling.

  • cv2.dnn.blobFromImage : a deep learning method from OpenCV that creates 4-dimensional blob from image. Optionally resizes and crops the image from the center, subtract mean values, scales values by scale factor, swap Blue and Red channels.

    • image : input image (with 1-, 3- or 4-channels).
    • swapRB : flag which indicates that swap first and last channels in a 3-channel image is necessary.
    • crop : flag which indicates whether the image will be cropped after resize or not.
  • net.setInput(blob) : Sets the input value blob for the network net.

  • cv2.imread : Reads an image.

  • plt.imshow(image) : Displays data as an image.

  • Use cv2.imread to read the image we want to detect the objects in, into img at /cxldata/dlcourse/mask_rcnn_model_data/dining_table.jpg.

    img = << your code comes here >>('/cxldata/dlcourse/mask_rcnn_model_data/dining_table.jpg')
  • Visualize the image img we have read using fixColor, the function we defined previously, and plt.imshow. Make sure to write this in a separate code-cell to be able to see the image img.

  • Use cv2.dnn.blobFromImage to get the blob of the input image.

    blob = << your code comes here >>(img, swapRB=True, crop=False)
  • Set blob as input to the network net using setInput.

    net.<< your code comes here >>(blob)
Get Hint See Answer

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...