Ask Your Question
1

Output of blobFromImage function

asked 2019-02-04 04:19:16 -0600

Vandana gravatar image

updated 2019-02-04 04:37:03 -0600

berak gravatar image

I am using cv2.blobFromImage function to pre-process the image before feeding to a dnn for face detection. I tried to display the output of this function. What I am getting is multiple images (9 images). My input image, code and output image are given below. Can anyone please tell me why 9 images are formed here?

Input image image description

Code

    import cv2
    import numpy as np

    img = cv2.imread('messi.jpeg')
    blob = cv2.dnn.blobFromImage(img,1.0,(300,300),[104,117,123],False,False)
    print(blob.shape)
    blobb = blob.reshape(blob.shape[2],blob.shape[3],blob.shape[1])
    cv2.imshow('Blob',blobb)
    cv2.waitKey(5000)
    cv2.destroyAllWindows()

Output image

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-02-04 04:35:36 -0600

berak gravatar image

updated 2019-02-04 04:37:39 -0600

your "blob" is a 4d tensor, containing 3 seperate grayscale channel images,

print(blob.shape)

(1, 3, 300, 300)

so you need to reshape it like this, for visualization:

# a horizontal strip with 3 one-channel images.
blobb = blob.reshape(blob.shape[2] * blob.shape[1], blob.shape[3], 1) 
print(blobb.shape)

(900, 300, 1)

image description

edit flag offensive delete link more

Comments

Thank you :)

Vandana gravatar imageVandana ( 2019-02-04 04:52:32 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-02-04 04:19:16 -0600

Seen: 8,890 times

Last updated: Feb 04 '19