Lens correction on windowed image?

Hi, I am having trouble doing lens correction on a cropped image.

Because I need the camera quite close to my object, I am using a wide angle lens (160 deg HFOV according to the manufacturer) mounted on my OpenMV Cam H7 R2. I also need high resolution, so I’ve set my sensor frame size to sensor.WXGA, and I don’t need color so I’m using grayscale. When doing image.lens_corr(), I get the error “MemoryError: Out of fast Frame Buffer Stack Memory!”, so I am using sensor.set_windowing() per this thread, which resolved the error.

However, since the windowing I need is off-center, the image.lens_corr() function is wrong since it does the correction assuming I’m centered. I tried to use x_corr and y_corr, but it just turned the Frame Buffer all black. I also tried using sensor.set_lens_correction() thinking it could correct before windowing, but that function doesn’t seem to be doing anything. Thank you in advance for the help!

Here are some pictures showing what I mean:

import sensor, image

sensor.reset()                          # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE)  # Set pixel format to grayscale
sensor.set_windowing((200,350,300,300)) # window to bottom left corner due to memoryerror
sensor.set_contrast(3)                  # adjust contrast -3 to +3
sensor.set_vflip(True)                  # flip vertically
sensor.set_hmirror(True)                # mirror horizontally
#sensor.set_lens_correction(True, 200, 10) # doesn't do anything
sensor.skip_frames(time = 2000)         # Wait for settings take effect.

    img = sensor.snapshot()             # Take a picture and return the image.
    img.lens_corr(strength =2, zoom = 1) # exaggerated strength to show incorrect effect on windowed image

x_corr and y_corr should have worked. What did you pass?

Also, re-=writing that is on the todo list.

I tried both large and small values in a range of -500 to +500 for x_corr and y-corr and they all result in a blacked out Frame Buffer. Do you have an example of this function that I can look at? Thank you!

That’s a pixel level shift… So, it shouldn’t be that large.

Those values target where the transform is applied in the image.

Oh I see - I tried x_corr = 1 and I still get a black Frame Buffer - is there something I’m missing? Thanks.

Using values between 0-1 work now - I guess they’re not pixel values but normalized to something? Thanks for your help.