Flipping the camera up-side-down

Due to limited space inside my robot I decided to mount the OpenMV board inside it up-side-down. I figured it will not matter much, as I can simply just flip the y coordinate of whatever results of image processing I get, and it will amount to the same thing. However, I didn’t think about things like face detection, which will not work with up-side-down faces.

I’m now thinking about what I could do. I could flip the image after taking the snapshot and before processing it – it would take some more time, but could work. I looked at the Image class, but didn’t find a way to flip or rotate the image, though.

Next thought, I could probably configure the camera sensor to flip the image – some cameras do have such a function. But again, nothing like that in the Sensor class, except maybe for the raw access to the registers. So I started to look for the datasheet for the camera sensor, thinking that if such an option exists there, it would be explained. But the datasheet is not linked from https://openmv.io/docs/openmv/hardware/index.html and a quick Google search doesn’t seem to yield anything more than a few promotional pamphlets.

FInally, I could probably use a flipped cascade for the face detection, instead of the default one. However, looking at the XML files of the OpenCV examples, it doesn’t seem like it’s a trivial operation to do.

I guess I will simply figure out how to mount the camera right side up, unless someone has any more ideas or hints?

We should be able to add vertical flip and horizontal mirror output to the sensor class. OmniVision sensors support this. The OV7725 does I know. For the OV2640 you can find the data sheet by googling for it here: http://www.uctronics.com/download/cam_module/OV2640DS.pdf

See Page 22. There’s a vertical flip and horizontal mirror register. So, use the register read and register write stuff for now. Its reg 04, bits 6 and 7.

I’m going to implement those, for now you could use __write_reg/__read_reg to do the flipping:

sensor.__write_reg(0xFF, 0x01)
sensor.__write_reg(0x04, 0x28)

(Note: Those registers are for the OV2640)

I found the datasheet for OV7725, I will look for the corresponding registers. Thanks!

I guess I can’t read this datasheet, or I’m missing something obvious. The docs say:

Address: 0C, Name: COM3, Bit[3]: Vertical flip image ON/OFF selection

So I added this code just before the loop in the helloworld example:

sensor.__write_reg(0x0C, sensor.__read_reg(0x0C) | (1 << 7))

But it doesn’t seem to be doing anything…
Do I need to call something more to “commit” those values?

This works on OV7725, you need to call it after all the sensor settings. I think you have an OV2640 though, or did you get one of the new cameras ?

Ah, silly me, I thought OV7725 is the old one. Sorry, your code works perfectly, thank you!

You’re welcome! I think we have a couple of extra OV7725 cams for development (freebies!), mail us at openmv@openmv.io if you want one.

did the image rotation/ flip ever get implemented?

See sensor.hmirror and sensor.vflip. Rotation has not been implemented yet though it would be easy to do.

Hello kwagyeman! How to used the sensor.hmirror and sensor.vflip. Rotation function when by define the ROI field. I Need compared one image the diffenece between the up side down or left side right which by define the ROI fields.Thank you for your kindly support!

sensor.set_vflip(True)
sensor.set_hmirror(True)

?

Hello kwagyeman ,how to define the ROI used sensor.set_vflip or sensor.set_hmirror?

Those commands flip the whole image. That’s what you want right?

Hi,kwagyeman . I need only ROI field in one Image.Thanks!

You can’t flip just an ROI. It’s the whole.image since that command is editing what’s generated from the camera.

You could flip and then crop the output (set_windowing), it should have the same effect.

Thank you iabdalkader, I will be try!