how to send image to server by post to http?
how to send image to server by post to http?
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!
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?
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.
Then transmit that data.
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))
Nyamekye,
Re: how to send image to server by post to http?
thanks so much.
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?

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?
Ibrahim will have to answer this. The WiFi part I'm not strong with.
Nyamekye,
Re: how to send image to server by post to http?
I can't find him in the Members.Can you help me to invite him to see this question?
best wishes
best wishes
- iabdalkader
- Posts: 1299
- Joined: Sun May 24, 2015 3:53 pm
Re: how to send image to server by post to http?
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?
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?
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?
- iabdalkader
- Posts: 1299
- Joined: Sun May 24, 2015 3:53 pm
Re: how to send image to server by post to http?
The socket module doesn't support SSL.librazxc wrote: ↑Sun Jan 13, 2019 7:43 pmHi,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?
Thanks.By the way,Is the ATwinC1500 hardware itself not supported SSL or just does not transplant the relevant ssl code in OpenMV3?
- iabdalkader
- Posts: 1299
- Joined: Sun May 24, 2015 3:53 pm
Re: how to send image to server by post to http?
Sorry to resurrect an old post.iabdalkader wrote: ↑Mon Jan 14, 2019 10:08 amNo the hardware supports it, but currently there's no way to download certificates to the module flash.
Given the wifi shield uses the same atwinc1500 chip as both the Adafruit feather M0 and their standalone winc1500, couldn't this same concept here:
https://learn.adafruit.com/adafruit-fea ... rtificates
be used to flash the SSL certificates? or have there been sufficient modifications to the winc1500 firmware that would prevent this?
- iabdalkader
- Posts: 1299
- Joined: Sun May 24, 2015 3:53 pm
Re: how to send image to server by post to http?
You could try to update the certificates with that (all the pins are broken out, including the debugging uart), but you should Not update the firmware because it needs to match the host driver (the driver OpenMV uses), otherwise it won't work with OpenMV after a firmware update.Nezra wrote: Given the wifi shield uses the same atwinc1500 chip as both the Adafruit feather M0 and their standalone winc1500, couldn't this same concept here:
https://learn.adafruit.com/adafruit-fea ... rtificates
be used to flash the SSL certificates? or have there been sufficient modifications to the winc1500 firmware that would prevent this?
I'll work on a way to update the certificates, but this may take some time.
- iabdalkader
- Posts: 1299
- Joined: Sun May 24, 2015 3:53 pm
Re: how to send image to server by post to http?
Hi, just an update on this, we now support SSL with mod ussl (mbedtls) it's available in the latest beta release with mbedtls, additionally the WINC1500 host driver and firmware have been updated to the latest (v19.3.0/v19.6.1). I'm not sure if there's a way to add certificates, but the client seems to not validate them anyway.. Note if you want to use the the new release it requires a WINC1500 firmware update (included with the release).
Re: how to send image to server by post to http?
I'm trying to send images coninuously to a php by http POST and after two times, three four the camera reboot or disconnect. Not all the time in the same line nor in the same snapshot. I have tried many things. Here is the last code attached.
Could be a memory issue that I have to manage? It is a problem of the Openmv H7 that might be solved in the Plus version or it is the Wifi Shield or maybe the code?
Could be a memory issue that I have to manage? It is a problem of the Openmv H7 that might be solved in the Plus version or it is the Wifi Shield or maybe the code?
- Attachments
-
mainfull.py
- (2.96 KiB) Downloaded 41 times
- iabdalkader
- Posts: 1299
- Joined: Sun May 24, 2015 3:53 pm
Re: how to send image to server by post to http?
I can't say for sure without testing the code, and I can't test this code because I need a server to post the images. However, I noticed that there's a commented print line in the IRQ callback, you can't call any functions that allocate memory (including print statements) in an IRQ callback. Also, you use ping inside the callback it must be global...sonsetc wrote: ↑Fri Apr 24, 2020 6:48 pmI'm trying to send images coninuously to a php by http POST and after two times, three four the camera reboot or disconnect. Not all the time in the same line nor in the same snapshot. I have tried many things. Here is the last code attached.
Could be a memory issue that I have to manage? It is a problem of the Openmv H7 that might be solved in the Plus version or it is the Wifi Shield or maybe the code?
Code: Select all
def callback(line):
global ping
....
Re: how to send image to server by post to http?
Hi, we will have a rather robust demo for how to do good TCP/UDP connections soon in our upcoming RPC library.
Nyamekye,
Re: how to send image to server by post to http?
Alright, thanks, I understand, but it was added at the end. I was trying the post code for a few days without the callback. I tried also many other options. Also trying to send with PUT instead POST.iabdalkader wrote: ↑Fri Apr 24, 2020 7:14 pmI can't say for sure without testing the code, and I can't test this code because I need a server to post the images. However, I noticed that there's a commented print line in the IRQ callback, you can't call any functions that allocate memory (including print statements) in an IRQ callback. Also, you use ping inside the callback it must be global...sonsetc wrote: ↑Fri Apr 24, 2020 6:48 pmI'm trying to send images coninuously to a php by http POST and after two times, three four the camera reboot or disconnect. Not all the time in the same line nor in the same snapshot. I have tried many things. Here is the last code attached.
Could be a memory issue that I have to manage? It is a problem of the Openmv H7 that might be solved in the Plus version or it is the Wifi Shield or maybe the code?Code: Select all
def callback(line): global ping ....
The server and php is working right now for testing. You can use it. It is only for development. You only need to change the SSID and Pass in the py code.
I will try with the PUS version of the camera that we also bought and maybe we might try with a multipart POST method. I'm not sure but the last wifi shield is blue, not red that we also bought some month ago.
We are testing the camera for a wildlife conservation project (biodiversity monitoring). If we succedd we will buy 20-40 units in the first deployment and then 1000 units to cover the whole Amazon Rainforest.
Re: how to send image to server by post to http?
Next week. I'm finishing up the library right now. I just got TCP and UDP raw image transfer from one OpenMV Cam to another working. Wifi can nominally move between 1 to 2 Mbps. I am writing a script for the computer now and I'll have the ability to transfer images wirelessly to a desktop working soon.
Note, the library shows off a custom protocol I designed called RPC which let's you remote call a method on the OpenMV Cam. You are allowed to pass an arbitrary length bytearray to the procedure that can contain anything... and it will be delivered to that method on the OpenMV Cam. That method can then respond with an arbitrary length bytearray which will be delivered back to the caller. Both the argument bytearray and response can be variable length per call response.
Anyway, the code however shows off how to use sockets in a really robust way so if you don't like the protocol you can just lift code from it.
Finally, you can also just implement the protocol over another transport layer like http. However, it will work for raw sockets right out the box.
Note, the library shows off a custom protocol I designed called RPC which let's you remote call a method on the OpenMV Cam. You are allowed to pass an arbitrary length bytearray to the procedure that can contain anything... and it will be delivered to that method on the OpenMV Cam. That method can then respond with an arbitrary length bytearray which will be delivered back to the caller. Both the argument bytearray and response can be variable length per call response.
Anyway, the code however shows off how to use sockets in a really robust way so if you don't like the protocol you can just lift code from it.
Finally, you can also just implement the protocol over another transport layer like http. However, it will work for raw sockets right out the box.
Nyamekye,
Re: how to send image to server by post to http?
I was working on a similar project using raspberry pi. What I did was use ffmpeg to pipe an image stream over UDP to a netcat listener on a server. You can stream and save these UDP streams once they get to your server. Here was my example for the Pi, you could replace ffmpeg with usocket on the OpenMV cam.
This is how I did it on the PI,
On the Server
This example will just open up a live stream on your host server. If you want to say and stream you could do something like this:
You can get creative on the server end to make it more robust.
This is how I did it on the PI,
Code: Select all
ffmpeg -f v4l2 -video_size 1280x720 -re -i "0:0" -f mpegts -b:v 3M udp://YOURPUBLICIP:5555
Code: Select all
nc -l -p 5555 | mplayer - -benchmark
Code: Select all
nc -l -p 555 | tee file_containing_the_video.mp4 | mplayer - -benchmark
-Chief Tinkering Officer
Re: how to send image to server by post to http?
Good idea. I use the camera with a PIR sensor to be fully switched off to last for long time and when it is triggered it takes pictures, connect to the Wifi AP in a Raspberry PI 4 with Neural Nets to send the image for classification.CameraMan wrote: ↑Sat Apr 25, 2020 11:13 amI was working on a similar project using raspberry pi. What I did was use ffmpeg to pipe an image stream over UDP to a netcat listener on a server. You can stream and save these UDP streams once they get to your server. Here was my example for the Pi, you could replace ffmpeg with usocket on the OpenMV cam.
This is how I did it on the PI,On the ServerCode: Select all
ffmpeg -f v4l2 -video_size 1280x720 -re -i "0:0" -f mpegts -b:v 3M udp://YOURPUBLICIP:5555
This example will just open up a live stream on your host server. If you want to say and stream you could do something like this:Code: Select all
nc -l -p 5555 | mplayer - -benchmark
You can get creative on the server end to make it more robust.Code: Select all
nc -l -p 555 | tee file_containing_the_video.mp4 | mplayer - -benchmark
I was also considering also using the mpej_streamer.py example that works really fine and pick the pictures from the RPi. But it needs to run continuously in the other side (Rpi4) as the nc but seems to be a good solution. We might use php but better wget inside bash.Thanks
Re: how to send image to server by post to http?
Alright I will be checking. As I commented to CammeraMan, I will try with the example "mpeg_streamer.py" and run in the other side a wget or a php to read the images.kwagyeman wrote: ↑Sat Apr 25, 2020 10:51 amNext week. I'm finishing up the library right now. I just got TCP and UDP raw image transfer from one OpenMV Cam to another working. Wifi can nominally move between 1 to 2 Mbps. I am writing a script for the computer now and I'll have the ability to transfer images wirelessly to a desktop working soon.
Note, the library shows off a custom protocol I designed called RPC which let's you remote call a method on the OpenMV Cam. You are allowed to pass an arbitrary length bytearray to the procedure that can contain anything... and it will be delivered to that method on the OpenMV Cam. That method can then respond with an arbitrary length bytearray which will be delivered back to the caller. Both the argument bytearray and response can be variable length per call response.
Anyway, the code however shows off how to use sockets in a really robust way so if you don't like the protocol you can just lift code from it.
Finally, you can also just implement the protocol over another transport layer like http. However, it will work for raw sockets right out the box.
Re: how to send image to server by post to http?
My library will work fine for you then. You can choose the following interfaces:
WiFi - 1 to 2 Mbs in heavy wifi traffic area (using our WiFi shield)
UART - 7.5 Mbps
CAN - 1 Mbps
SPI - 20 to 80 Mbps
I2C - 1 Mbs
USB VCP - 12 Mbps
The library is self healing meaning that I designed it to be reliable if a part of the link dies. E.g. the library will timeout gracefully and then start working again once the link comes back - no lockups. We won't have an example script for the RaspberryPi right away... but, the general purpose PC control script should run on the Pi as it's just for sockets and USB. SPI/I2C/UART for the Pi will come later.
Um, so, to be honest, the lowest power thing to use for you would actually be the OpenMV Cam RPC via UART using a generic serial to RF adapter: https://www.amazon.com/Wireless-Modules ... B01L3N4RYW - https://www.dfrobot.com/product-57.html
These are much lower power than WiFi. You would give each camera one of them and then have my RPC code running on each camera. Then the RPi would use the RPC protocol over USB through the FTDI serial port. The range will be longer than WiFi too. However, I'm not sure how you handle multiple channels at once. Probably should research that.
Note: You might want to use better hardware than I linked to above. But, the idea is the same.
WiFi - 1 to 2 Mbs in heavy wifi traffic area (using our WiFi shield)
UART - 7.5 Mbps
CAN - 1 Mbps
SPI - 20 to 80 Mbps
I2C - 1 Mbs
USB VCP - 12 Mbps
The library is self healing meaning that I designed it to be reliable if a part of the link dies. E.g. the library will timeout gracefully and then start working again once the link comes back - no lockups. We won't have an example script for the RaspberryPi right away... but, the general purpose PC control script should run on the Pi as it's just for sockets and USB. SPI/I2C/UART for the Pi will come later.
Um, so, to be honest, the lowest power thing to use for you would actually be the OpenMV Cam RPC via UART using a generic serial to RF adapter: https://www.amazon.com/Wireless-Modules ... B01L3N4RYW - https://www.dfrobot.com/product-57.html
These are much lower power than WiFi. You would give each camera one of them and then have my RPC code running on each camera. Then the RPi would use the RPC protocol over USB through the FTDI serial port. The range will be longer than WiFi too. However, I'm not sure how you handle multiple channels at once. Probably should research that.
Note: You might want to use better hardware than I linked to above. But, the idea is the same.
Nyamekye,
Re: how to send image to server by post to http?
If I use a modem instead of a WiFi shield to upload images, do you suggest using POST to http or ftp, or something else? Given that you made the RPC tool, what is the easiest way to write something to get the image uploaded? I think you suggest using sockets but what are the basic steps between snapping an image and sending it? I presume I should use AT commands to open a socket, etc on the modem or is there a better way? How do I access the image to begin sending it in the first place?
Re: how to send image to server by post to http?
The tool I built works on the socket level layer. It's not FTP/HTTP/POST/etc.
If you want to use a higher level protocol you need to implement that on top of the sockets layer.
With the latest firmware various bugs with the WiFi shield have been fixed. So, you should find it very straight forward to use sockets to implement the above high level protocols. Standard Python code on how to use sockets to do the above protocols can be used.
...
Anyway, a thing to think about for your problem. So, If you just use the RPC library I made and put that on the remote server it's possible to get streaming working to the remote server. This is the easiest way. However, keep in mind that the RPC timeouts aren't very long so you might have to modify the library code.
Otherwise, if you want to implement a higher level protocol you just need to use python sockets to do it.
https://stackoverflow.com/questions/286 ... parameters
Not all the above is probably something you can do. But, most of it.
Anyway, as for sending image data... you should jpeg compress it and then append that to the end of the message.
https://stackoverflow.com/questions/150 ... pi-service
If you want to use a higher level protocol you need to implement that on top of the sockets layer.
With the latest firmware various bugs with the WiFi shield have been fixed. So, you should find it very straight forward to use sockets to implement the above high level protocols. Standard Python code on how to use sockets to do the above protocols can be used.
...
Anyway, a thing to think about for your problem. So, If you just use the RPC library I made and put that on the remote server it's possible to get streaming working to the remote server. This is the easiest way. However, keep in mind that the RPC timeouts aren't very long so you might have to modify the library code.
Otherwise, if you want to implement a higher level protocol you just need to use python sockets to do it.
https://stackoverflow.com/questions/286 ... parameters
Not all the above is probably something you can do. But, most of it.
Anyway, as for sending image data... you should jpeg compress it and then append that to the end of the message.
https://stackoverflow.com/questions/150 ... pi-service
Nyamekye,
Re: how to send image to server by post to http?
Yeah, we'll add urequests and mqtt. Mqtt is already onboard. But, will document it with this:
https://makeblock-micropython-api.readt ... uests.html
https://makeblock-micropython-api.readt ... /mqtt.html
https://makeblock-micropython-api.readt ... uests.html
https://makeblock-micropython-api.readt ... /mqtt.html
Nyamekye,
Return to “Technical Discussion”
Who is online
Users browsing this forum: No registered users and 2 guests