Hello, I am new to coding. I wrote this code in IDE to get the temperature from Lepton in a matrix format along the vision image. I want to write a similar code using rpc to transfer my data to the pc. I appreciate any feedback on it.
Hi, please avoid using the RPC library for transfer to the PC. It’s far easier just to print(“”) the data and open a serial port to receive the info on the PC: openmv/openmv: OpenMV Camera Module
As controlling the camera via the PC, please use the micropython pyboard.py script: micropython/tools/pyboard.py at a971731624f0d447dfb6f67cd84d187b60626849 · openmv/micropython
The script lets you send a script to the camera from the PC, execute that script, and get results back. It can also stop any previously running script.
thank you! how about if I want to use the openMV RPC library to transfer the thermal camera images from openMV pure thermal to pc. Similar to what you have shown in your tutorial video on https://www.youtube.com/watch?v=WRHrqlKBZ3s
I want to use stream lit after it for my custom web app.
Use this: openmv/tools/pyopenmv_fb.py at master · openmv/openmv
It can stream image to a python GUI and then you can edit the code to do more.
I do not recommend using the RPC library to talk to the PC. It was meant for talking to another Microcontroller like the Arduino. It’s good at that. The PC is not real-time enough, which breaks the comms protocol.
Thank you so much Kwabena for your quick reply! That’s awesome!
I have a follow up question. I am having this code in IDE that works
import sensor
import fir
import time
import os
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
fir.init(fir.FIR_LEPTON)
THERMAL_WIDTH = 160
THERMAL_HEIGHT = 120
print("Starting thermal sensor output...")
os.sync() # Ensure output is flushed
while True:
try:
ta, ir, to_min, to_max = fir.read_ir()
print("Ambient Temp (Ta): {:.2f}°C".format(ta))
os.sync() # Flush output after every print
print("Min Temp (To_min): {:.2f}°C, Max Temp (To_max): {:.2f}°C".format(to_min, to_max))
os.sync()
time.sleep(1)
except Exception as e:
print(f"Error: {e}")
os.sync()
I have it as main.py on the openmv purethermal flashdrive. I disconnect it from IDE. Then, I try to have the below script on my client:
import serial
import time
DEVICE = "COM5"
BAUDRATE = 115200
def read_serial_output(device, baudrate):
"""
Reads serial output from the OpenMV device and prints it.
"""
try:
with serial.Serial(device, baudrate, timeout=1) as ser:
print(f"Connected to {device} at {baudrate} baud.")
# ser.reset_input_buffer() # Clear any previous data in the buffer
while True:
if ser.in_waiting > 0: # Check if data is available
line = ser.readline().decode("utf-8").strip() # Read and decode
print(f"Received: {line}")
else:
time.sleep(0.1) # Prevent busy-waiting
except Exception as e:
print(f"Error: {e}")
#Test the serial communication
read_serial_output(DEVICE, BAUDRATE)
but, I do not get anything in the terminal. Do you have any feedback on it?
You need to make DTR false: openmv/openmv: OpenMV Camera Module
I did it and ran it. It did not work.
I expected to get image and the read out of temperature. As, my main.py code shows.
The only thing I got in the terminal was “Connected to COM5 at 115200 baud.”.
What do I am missing here?
Hi, I ran your script in the IDE. It had an indentation issue. I fixed that:
import sensor
import fir
import time
import os
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
fir.init(fir.FIR_LEPTON)
THERMAL_WIDTH = 160
THERMAL_HEIGHT = 120
print("Starting thermal sensor output...")
os.sync() # Ensure output is flushed
while True:
try:
ta, ir, to_min, to_max = fir.read_ir()
print("Ambient Temp (Ta): {:.2f}°C".format(ta))
os.sync() # Flush output after every print
print("Min Temp (To_min): {:.2f}°C, Max Temp (To_max): {:.2f}°C".format(to_min, to_max))
os.sync()
time.sleep(1)
except Exception as e:
print(f"Error: {e}")
os.sync()
Then I can this script on the terminal:
import serial
ser = serial.Serial("COM19", timeout=1, dsrdtr=False)
while True:
line = ser.readline().strip()
if line: print(line)
You need to run the script with command line args: python -u script.py
. You need the u so that python doesn’t buffer the text.
I tried this approach, but it is kinda slow,
Each time you print IR data it takes time,
So I have two questions
1- is there a way to get both visual and thermal images at the same time?
2- is there any other faster way to take snapshots and read IR data to a pc with USB other than print?
Hi, yes, use this tool: openmv/tools/pyopenmv_fb.py at master · openmv/openmv
It talks to the camera using our debug protocol. You can send scripts to the camera, start, stop it, and pull the frame buffer and text buffer.
As for the printing script being slow, this is because there’s a 1 second sleep in it. Otherwise it will generate data as fast as the system can do so. Note that the FLIR sensor doesn’t go above 9 Hz.