![]() |
In this article, we’ll try to understand how the blobfromImage function from the dnn module in the OpenCV library works and when should you use it. blobfromImage() functionIt returns a 4-dimensional array/blob for the input image. You can additionally use it to preprocess your image to match your input requirements. You can use its different parameters to transform your image, so let’s discuss all its parameters:
Example 1: Scaling and Matching the Target sizeMost of the time you’re model input you have to scale down your image pixel values between 0-1 instead of 0-255, i.e where you can use the scalefactor argument- And also change the Target size of the Image: Python3
Output: [[[255 255 255] [255 255 255] [255 255 255] ... ... [255 255 255] [255 255 255] [255 255 255]]] Image Shape : (817, 861, 3) [[[[1. 1. 1. ... 1. 1. 1.] [1. 1. 1. ... 1. 1. 1.] [1. 1. 1. ... 1. 1. 1.] ... ... [1. 1. 1. ... 1. 1. 1.] [1. 1. 1. ... 1. 1. 1.] [1. 1. 1. ... 1. 1. 1.]]]] Blob Shape : (1, 3, 720, 640) As you can see all the values which were 255 at the start got converted into 1, this is because our scale factor was 1/255. And also our final blob has the size of 720,640, which is what we wanted. Example 2: Using it with a model to create the input imageWhat scalefactor you use or what target size you use or what mean values you normalize with, this all depends on the model that’s used. And if you’re using a pre-trained model from a framework read their documentation for all the requirements for the input image. For eg: If I was creating a gender classifier program and I decided to use the caffe model for it then,
These are all the required values or data for using that model to create our blog, so:
This blob now is transformed to directly pass as input to our model. And this is the basic process if you’re using a pre-trained model and want to transform your image to fit the model requirements. What next?Try to use pre-trained models from frameworks like TensorFlow and PyTorch to create computer vision programs. |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |