Converting data received through serial back to image using python

I’m trying to send data to a pc using serial over long distance using rs232, then converting the received data back into an image using python, then saving it as a jpeg. I’ve managed to send data to my pc using https://forums.openmv.io/viewtopic.php?f=5&t=824&p=5283&hilit=image+to+nodemcu#p5283. But have been unable to convert the received data back into an image using python as, I’m rather new to it. Any help regarding the matter is most welcomed.

Please use our RPC library. We have an example for this. openmv/README.md at master · openmv/openmv · GitHub

Cool I’ll try it out tomorrow, one more thing how do I then save the images on to my desktop?

That’s up to you via programming in Python. You should look at the API for the pygame library.

The JPG image bytestream though can be directly saved to a file however. There’s no special library that you need. Just write the exact bytes received to a file called *.jpg and any application can open it.

Noted, with thanks

That is odd… I’ve tried to get the all of RPC examples to work but none of them seems to do anything. Correct me if I’m wrong but I’m suppose to run an application on the openmv camera then run another script on python on my desktop pc. What I don’t get is which serial port is being used on the openmv module and how do I go about setting the baudrate for the python scripts?

Hi, the baud rate over the VCP port is 12 Mb/s.

To be clear, run this script unmodified on the PC:

And then put this script on the OpenMV Cam:

Save the above script as main.py on the camera or an SD card inserted in the camera. Make sure the script was written. Then safety remove the camera and then reconnect it to the computer. If the script was written successfully then when you run the other python script on the desktop everything will work.

Sigh, I still can’t get it to work. Is there another way to go about it?

Can you verify the script was written to the camera as main.py and not corrupted? If so, then when you run the script on the PC and select the camera serial port it should just work.

Are you getting any error code? Or is it just not doing anything at all?

I can confirm that the file has been written correctly and is not corrupted. It just shows a blank window.

Hmm, it’s probably a USB timeout issue. The USB RPC master assumes a pretty tight timeout loop. I only have test data for this on my own PC.

Can you change the RPC master to the UART class in the script? The timeouts for that are a lot longer.

The RPC library works through a polling interface without timeouts. It was meant for SPI, I2C, UART Comms between microcontrollers. It does work on the PC, but, your computers ability to keep deadlines messes up the protocol.

May I know what baudrate to set it to? I’ve tried 115200, 9600, 230400 and 7500000, but none of them seem to do a thing. Is really there no way to just convert the raw image data back to a jpeg?

  1. It doesn’t matter. It will be 12Mb/s in reality. Do not set he baud rate to 12Mb/s as the rate however since the camera will think you are going to debug mode then.

Also, given you got a normal serial example to work… you can also just skip all this and just write the jpg data you receive to a file.

A jpg bytestream is literally the jpeg file. Most applications can read that byte stream.

Honestly I’ve tried but the image reader keeps insisting that the file is corrupt.

Anyways i’ll attach a single frame of data.
SingleFrame.txt (2.09 KB)

Okay, let me check on this.

Watch this:

Hmph… unfortunately, it still doesn’t work. Might be due to my aging work computer that is till running windows 7 on 2gb of ram. I’ve managed to solve my issue though, apparently my python code to read the data wasn’t reading all of the data received, thank you for your help and time.

The library does depend on the OS being real-time ish with the USB port. If you use the WiFi/Ethernet master then the timeouts are much more lax.