Library import doesn't work unless launched from IDE

Hello. I’m using OpenMV H7 Plus board with Arduino Mega 2560.
For my project I’m using library for OpenMV (openrv/homography/README.md at master · nickoala/openrv · GitHub). I put files on my camera’s SD-card like this:

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        23.05.2025     15:16                rv
d-----        23.05.2025     15:16                vec
-a----        01.01.2015      0:00              0 .openmv_disk
-a----        24.03.2025     11:49           1904 mtx.py
-a----        09.10.2025     14:30            171 main.py

My problem is that when I launch my script via OpenMV IDE - everything is great - I get messages with data on my mega and everything works. When I try to start this whole project automaticly - not via IDE but just with power source and UART connection between Mega and OpenMV - I dont get any data at all on my Arduino - unless I firstly start camera script via IDE - then unplug it cable from my computer and then it continues working and my Arduino gets data.

I probably should mention that other code like simple “Hello World!” passing from camera to arduino works perfectly, and the cable was tested - it’s not faulty. And the UART connection is correct. The problem is probably in libaries, it feels like my main.py file can’t open files in rv lib?

Can anyone help with this problem?

My code for OpenMV:

import sensor, utime
from pyb import UART
from rv.planar import Planar

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_auto_gain(False, gain_db=22.6067)
sensor.set_auto_whitebal(False, rgb_gain_db=(64.3917, 60.206, 62.8227))
sensor.set_auto_exposure(False, exposure_us=12000)
sensor.skip_frames(time=500)
thresholds = [(61, 94, -39, -9, -2, 39)]

uart = UART(1, 19200, timeout_char=200)
H = [[-3.53512728e-02, -1.71368433e+00,  3.98107181e+02],
[ 1.72228029e+00, -3.30469606e-02, -2.69140391e+02],
[ 1.20710983e-04, -1.79347218e-04,  1.00000000e+00]]

offset = [-100, 10]

while True:
    img = sensor.snapshot() .lens_corr(1.2) # .rotation_corr(x_rotation = -25)

    p = Planar(H, offset)

    blobs = img.find_blobs(thresholds, pixels_threshold=150, area_threshold=150)
    if len(blobs) > 0:
        blob = blobs[0]
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())

        coordinates = [[blob.cx(), blob.cy()]]
        result = p.project(coordinates)[0]
        print(f"x = {result[1]}, y = {result[0]}")

        uart.write("{} {}\n".format(result[1], result[0]))
        utime.sleep_ms(100)

Code for testing if Arduino gets any data:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(19200);
  Serial3.begin(19200);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial3.available()) {
    // Read the most recent byte
    byte byteRead = Serial3.read();
    // ECHO the value that was read
    Serial.write(byteRead);
  }
}

Did you save your script to main.py on the camera? From the listing you posted your main.py is 171 bytes which is a lot smaller than the one you have posted here on the forums.

Yes, I saved it via command in OpenMV IDE that reads something like “Save to OpenMV Cam as main.py script”. I tried running project on couple of H7 Plus cams, so I might have posted the listing for the one that I then tested simple UART-connection to check if UART is OK on.
Sorry if it was misleading

Is there any possibility that my cam isn’t reading library files when its not connected to the PC?

Hi, I’d check what is inside the main.py file on the camera. 171 bytes is a very small file with a very little amount of code. You can open the file via any standard text editor.