Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6403 Discussions

Python implementation of super-resolution sample

Madsen__Kasper
Beginner
874 Views

Hi there,

I have been working on converting the cpp super-resolution sample to Python. In order to make it work, it seems I need a function matU8ToBlob to convert the input images to a blob and then another function to convert the output blob to the final result (pixel values). This method is not really documented outside of the code and I am not a strong cpp programmer. Furthermore, I cannot find any python samples using the matU8ToBlob.

 

Can you confirm that I really need such a function and maybe point me in a right direction in terms of implementing the function in python3.

 

Thanks.

0 Kudos
4 Replies
Kenneth_C_Intel
Employee
874 Views

Hi i have written a small program with the python doing this. 

I did not use that function. 

I read the image in using openCV  (which for python stores it in a numpy array BGR format already) 

for example

image = cv2.imread("new_img.png")

 

(you may need to resize the image for it to fit into the model) 

After that you will need to create the bicupic version of the image 

bicupic = cv2.resize(image,(1920,1080), interpolation = cv2.INTER_CUBIC) 

Then you will need to reshape the array to fit into the openvino model 

image = image.transpose((2, 0, 1))
bicupic =  bicupic.transpose((2, 0, 1))

The last tricky part is you need to load the images into the plugin

exec_net.requests[0].inputs['0'][:] = image
exec_net.requests[0].inputs['1'][:] = bicupic
exec_net.requests[0].infer()

 

The infer command starts the inference. 

If you plan on saving the file you will need to normalize the floating point representation and then convert it to an integer (im sure there is a fancier way of doing this than the way i did)

I left out a bunch of code but i believe that the pieces that i provided are the things you could stumble on in getting everything started. 

I am submitting a request to the developers to port this sample to Python. 

Let me know if this helps you. 

Ken

 

0 Kudos
gustavobsch
Beginner
679 Views

Can you please describe how to save the image in python?

"normalize the floating point representation and then convert it to an integer"

0 Kudos
Madsen__Kasper
Beginner
874 Views

With the above pointers I managed to make it work in Python.

 

Thank you very much :)

0 Kudos
Shubha_R_Intel
Employee
874 Views

Dear Madsen, Kasper,

and thanks to my colleague Ken. thanks for reporting back and I'm glad you were successful !

Shubha

 

0 Kudos
Reply