Project - Yolov4 with OpenCV for Object Detection

5 / 7

Getting the image

  • We will read the image using an OpenCV method. We will resize it for making it easier to be viewed.

  • Then, we will make it into a blob which is a 4-dimensional array of images using cv2.dnn.blobFromImage.

  • We also do the following steps

    • Normalising pixel values by dividing by 255
    • Fixing the size to 608x608 required by Yolo
    • Swapping OpenCV's default BGR format to RGB
INSTRUCTIONS
  • Read the image using cv2.imread():

    img=<< your code comes here >>("/cxldata/projects/yolov4/soccer.jpg")
    
  • Resize the image using cv2.resize().

    img=<< your code comes here >>(img, (608, 608))
    
  • Print the image size and get H,W the height and width of the image:

    print (img.shape)
    (H, W) = img.shape[:2]
    
  • Show the image:

    plt.imshow(fixColor(img))
    
  • Use the cv2.dnn.blobFromImage to read the image as a blob, normalize it, fix the size of the image, and set the image channels as or OpenCV.

    blob = cv2.dnn.blobFromImage(img, 1 / 255.0, (608, 608), swapRB=True, crop=False)
    
  • Print the blob shape:

    print ("Shape of blob", blob.shape)
    
  • We can see the individual color streams of the image:

    split_blob=np.hstack([ blob[0, 0, :, :],blob[0, 1, :, :], blob[0, 2, :, :],])
    plt.imshow(fixColor(split_blob))
    
See Answer

No hints are availble for this assesment


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

Loading comments...