Page 1 of 1

how to send image to server by post to http?

Posted: Wed Jan 09, 2019 7:19 pm
by librazxc
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!

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

Posted: Thu Jan 10, 2019 12:03 pm
by kwagyeman
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.

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

Posted: Thu Jan 10, 2019 7:19 pm
by librazxc
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?

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

Posted: Thu Jan 10, 2019 11:07 pm
by kwagyeman
Ibrahim will have to answer this. The WiFi part I'm not strong with.

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

Posted: Fri Jan 11, 2019 3:53 am
by librazxc
I can't find him in the Members.Can you help me to invite him to see this question?
best wishes

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

Posted: Fri Jan 11, 2019 1:32 pm
by iabdalkader
You just send it with socket.send(). This is not a high level library, it's just plain sockets. See the MJPEG example.

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

Posted: Sun Jan 13, 2019 7:43 pm
by librazxc
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?

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

Posted: Sun Jan 13, 2019 8:21 pm
by iabdalkader
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.

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

Posted: Mon Jan 14, 2019 2:44 am
by librazxc
Thanks.By the way,Is the ATwinC1500 hardware itself not supported SSL or just does not transplant the relevant ssl code in OpenMV3?

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

Posted: Mon Jan 14, 2019 10:08 am
by iabdalkader
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.