how to send image to server by post to http?

Discussion related to "under the hood" OpenMV topics.
librazxc
Posts: 5
Joined: Wed Jan 09, 2019 2:46 am

how to send image to server by post to http?

Postby librazxc » Wed Jan 09, 2019 7:19 pm

Dear,
I am so sorry to send this message to you.I want to ask for some advice.
I am working on a project related to gesture recognition. Currently, there are OpenMV3 and WIFI extensions. I want to capture images through OpenMV CAM, convert the images to binary data or base64 encoding, use wifi to access the server, and access the server through the browser. The stream post is sent to the server and the server returns the result. There are two problems here: The first one is how to get a frame of image obtained in sensor.snapshot() into binary data or base64 encoded data? The second problem is that the request format required by the server API is the POST request http method, and the OpenMV3 has no related requests module or urllib module. How to set the POST entity header in the OpenMV3?
This is the server API request:
1.HTTP method:POST
url :https://aip.baidubce.com/rest/2.0/image ... 5-15254242
2.Content-Type application/x-www-form-urlencoded
3.Header:Content-Type application/x-www-form-urlencoded
4.Body:image: base64 string

Thank you very much!
Looking forward to your reply!
User avatar
kwagyeman
Posts: 2797
Joined: Sun May 24, 2015 2:10 pm

Re: how to send image to server by post to http?

Postby kwagyeman » Thu Jan 10, 2019 12:03 pm

Hi, use this to encode:

http://docs.micropython.org/en/v1.9.3/p ... ascii.html

And call .compress() on the image to get a jpeg byte stream.

E.g.

Code: Select all

base63_data = ubinascii.b2a_base64(img.compress(quality=90))
Then transmit that data.
Nyamekye,
librazxc
Posts: 5
Joined: Wed Jan 09, 2019 2:46 am

Re: how to send image to server by post to http?

Postby librazxc » Thu Jan 10, 2019 7:19 pm

thanks so much. :D
Do you know how to post to http in the openmv ?just follow the request which i proposed.how to set the header about client.send()?
And,How to parse url?Is there a function in OpenMV just like Python function-urlopen() to parse urls?
User avatar
kwagyeman
Posts: 2797
Joined: Sun May 24, 2015 2:10 pm

Re: how to send image to server by post to http?

Postby kwagyeman » Thu Jan 10, 2019 11:07 pm

Ibrahim will have to answer this. The WiFi part I'm not strong with.
Nyamekye,
librazxc
Posts: 5
Joined: Wed Jan 09, 2019 2:46 am

Re: how to send image to server by post to http?

Postby librazxc » Fri Jan 11, 2019 3:53 am

I can't find him in the Members.Can you help me to invite him to see this question?
best wishes
User avatar
iabdalkader
Posts: 690
Joined: Sun May 24, 2015 3:53 pm

Re: how to send image to server by post to http?

Postby iabdalkader » Fri Jan 11, 2019 1:32 pm

You just send it with socket.send(). This is not a high level library, it's just plain sockets. See the MJPEG example.
librazxc
Posts: 5
Joined: Wed Jan 09, 2019 2:46 am

Re: how to send image to server by post to http?

Postby librazxc » Sun Jan 13, 2019 7:43 pm

Hi,the MJPEG example is based on http,but my server address is based on https.
when i use the function:usocket.getaddrinfo(),it can't parse url correctly,there was an error in the OpenMV IDE,Oserror -1.
My URL is https://aip.baidubce.com/rest/2.0/image ... 5-15254242
I thought it just related to Https ssl encryption. Can this socket module solve it? I just want to realize that send an image to my specified https server via wifi or lan.
Do you have any other ideas for my purpose?
User avatar
iabdalkader
Posts: 690
Joined: Sun May 24, 2015 3:53 pm

Re: how to send image to server by post to http?

Postby iabdalkader » Sun Jan 13, 2019 8:21 pm

librazxc wrote:
Sun Jan 13, 2019 7:43 pm
Hi,the MJPEG example is based on http,but my server address is based on https.
when i use the function:usocket.getaddrinfo(),it can't parse url correctly,there was an error in the OpenMV IDE,Oserror -1.
My URL is https://aip.baidubce.com/rest/2.0/image ... 5-15254242
I thought it just related to Https ssl encryption. Can this socket module solve it? I just want to realize that send an image to my specified https server via wifi or lan.
Do you have any other ideas for my purpose?
The socket module doesn't support SSL.
librazxc
Posts: 5
Joined: Wed Jan 09, 2019 2:46 am

Re: how to send image to server by post to http?

Postby librazxc » Mon Jan 14, 2019 2:44 am

Thanks.By the way,Is the ATwinC1500 hardware itself not supported SSL or just does not transplant the relevant ssl code in OpenMV3?
User avatar
iabdalkader
Posts: 690
Joined: Sun May 24, 2015 3:53 pm

Re: how to send image to server by post to http?

Postby iabdalkader » Mon Jan 14, 2019 10:08 am

librazxc wrote:
Mon Jan 14, 2019 2:44 am
Thanks.By the way,Is the ATwinC1500 hardware itself not supported SSL or just does not transplant the relevant ssl code in OpenMV3?
No the hardware supports it, but currently there's no way to download certificates to the module flash.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests