Added hmirror and vflip support to the MT9V034 and example scripts (#294)

* Added hmirror and vflip support to the MT9V034 and example scripts.

* Moved sensor example scripts to one place.

* Add delay to these script for register settling time.
This commit is contained in:
Kwabena W. Agyeman 2017-12-30 17:32:01 -05:00 committed by Ibrahim Abd Elkader
parent b906c5f192
commit aeb0238040
9 changed files with 81 additions and 36 deletions

View File

@ -272,12 +272,20 @@ static int set_auto_whitebal(sensor_t *sensor, int enable, int r_gain, int g_gai
static int set_hmirror(sensor_t *sensor, int enable)
{
return 0;
uint16_t read_mode;
int ret = cambus_readw(sensor->slv_addr, MT9V034_READ_MODE, &read_mode);
ret |= cambus_writew(sensor->slv_addr, MT9V034_ANALOG_GAIN_CONTROL, (read_mode & (~MT9V034_READ_MODE_COL_FLIP)) | ((enable != 0) ? MT9V034_READ_MODE_COL_FLIP : 0));
return ret;
}
static int set_vflip(sensor_t *sensor, int enable)
{
return 0;
uint16_t read_mode;
int ret = cambus_readw(sensor->slv_addr, MT9V034_READ_MODE, &read_mode);
ret |= cambus_writew(sensor->slv_addr, MT9V034_ANALOG_GAIN_CONTROL, (read_mode & (~MT9V034_READ_MODE_ROW_FLIP)) | ((enable != 0) ? MT9V034_READ_MODE_ROW_FLIP : 0));
return ret;
}
static int set_special_effect(sensor_t *sensor, sde_t sde)

View File

@ -761,14 +761,11 @@ static int set_auto_whitebal(sensor_t *sensor, int enable, int r_gain, int g_gai
return cambus_writeb(sensor->slv_addr, CTRL1, reg) | ret;
}
static int set_hmirror(sensor_t *sensor, int enable)
{
uint8_t reg;
/* Switch to SENSOR register bank */
int ret = cambus_writeb(sensor->slv_addr, BANK_SEL, BANK_SEL_SENSOR);
/* Update REG04 */
int ret = cambus_readb(sensor->slv_addr, BANK_SEL, &reg);
ret |= cambus_writeb(sensor->slv_addr, BANK_SEL, reg | BANK_SEL_SENSOR);
ret |= cambus_readb(sensor->slv_addr, REG04, &reg);
if (enable) {
@ -777,16 +774,16 @@ static int set_hmirror(sensor_t *sensor, int enable)
reg &= ~REG04_HFLIP_IMG;
}
return cambus_writeb(sensor->slv_addr, REG04, reg) | ret;
ret |= cambus_writeb(sensor->slv_addr, REG04, reg);
return ret;
}
static int set_vflip(sensor_t *sensor, int enable)
{
uint8_t reg;
/* Switch to SENSOR register bank */
int ret = cambus_writeb(sensor->slv_addr, BANK_SEL, BANK_SEL_SENSOR);
/* Update REG04 */
int ret = cambus_readb(sensor->slv_addr, BANK_SEL, &reg);
ret |= cambus_writeb(sensor->slv_addr, BANK_SEL, reg | BANK_SEL_SENSOR);
ret |= cambus_readb(sensor->slv_addr, REG04, &reg);
if (enable) {
@ -795,7 +792,9 @@ static int set_vflip(sensor_t *sensor, int enable)
reg &= ~REG04_VFLIP_IMG;
}
return cambus_writeb(sensor->slv_addr, REG04, reg) | ret;
ret |= cambus_writeb(sensor->slv_addr, REG04, reg);
return ret;
}
int ov2640_init(sensor_t *sensor)

View File

@ -500,22 +500,18 @@ static int set_hmirror(sensor_t *sensor, int enable)
{
uint8_t reg;
int ret = cambus_readb(sensor->slv_addr, COM3, &reg);
// Set mirror on/off
reg = COM3_SET_MIRROR(reg, enable);
ret |= cambus_writeb(sensor->slv_addr, COM3, COM3_SET_MIRROR(reg, enable)) ;
// Write back register COM3
return cambus_writeb(sensor->slv_addr, COM3, reg) | ret;
return ret;
}
static int set_vflip(sensor_t *sensor, int enable)
{
uint8_t reg;
int ret = cambus_readb(sensor->slv_addr, COM3, &reg);
// Set mirror on/off
reg = COM3_SET_FLIP(reg, enable);
ret |= cambus_writeb(sensor->slv_addr, COM3, COM3_SET_FLIP(reg, enable));
// Write back register COM3
return cambus_writeb(sensor->slv_addr, COM3, reg) | ret;
return ret;
}
static int set_special_effect(sensor_t *sensor, sde_t sde)

View File

@ -460,23 +460,19 @@ static int set_auto_whitebal(sensor_t *sensor, int enable, int r_gain, int g_gai
static int set_hmirror(sensor_t *sensor, int enable)
{
uint8_t val;
cambus_readb(sensor->slv_addr, REG_MVFP, &val);
int ret = cambus_readb(sensor->slv_addr, REG_MVFP, &val);
ret |= cambus_writeb(sensor->slv_addr, REG_MVFP, enable ? (val | REG_MVFP_HMIRROR) : (val & (~REG_MVFP_HMIRROR)));
cambus_writeb(sensor->slv_addr, REG_MVFP,
enable ? (val | REG_MVFP_HMIRROR) : (val & ~REG_MVFP_HMIRROR));
return 0;
return ret;
}
static int set_vflip(sensor_t *sensor, int enable)
{
uint8_t val;
cambus_readb(sensor->slv_addr, REG_MVFP, &val);
int ret = cambus_readb(sensor->slv_addr, REG_MVFP, &val);
ret |= cambus_writeb(sensor->slv_addr, REG_MVFP, enable ? (val | REG_MVFP_VFLIP) : (val & (~REG_MVFP_VFLIP)));
cambus_writeb(sensor->slv_addr, REG_MVFP,
enable ? (val | REG_MVFP_VFLIP) : (val & ~REG_MVFP_VFLIP));
return 0;
return ret;
}
int ov9650_init(sensor_t *sensor)

View File

@ -388,16 +388,16 @@ static mp_obj_t py_sensor_set_auto_whitebal(uint n_args, const mp_obj_t *args, m
static mp_obj_t py_sensor_set_hmirror(mp_obj_t enable) {
if (sensor_set_hmirror(mp_obj_is_true(enable)) != 0) {
return mp_const_false;
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
}
return mp_const_true;
return mp_const_none;
}
static mp_obj_t py_sensor_set_vflip(mp_obj_t enable) {
if (sensor_set_vflip(mp_obj_is_true(enable)) != 0) {
return mp_const_false;
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Sensor control failed!"));
}
return mp_const_true;
return mp_const_none;
}
static mp_obj_t py_sensor_set_special_effect(mp_obj_t sde) {

View File

@ -35,6 +35,8 @@ clock = time.clock() # Create a clock object to track the FPS.
# that you put in place...
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
# Need to let the above settings get in...
sensor.skip_frames(time = 500)
current_exposure_time_in_microseconds = sensor.get_exposure_us()
print("Current Exposure == %d" % current_exposure_time_in_microseconds)

View File

@ -0,0 +1,21 @@
# Sensor Horizontal Mirror Example
#
# This example shows off horizontally mirroring the image in hardware
# from the camera sensor.
import sensor, image, time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Change this to False to undo the mirror.
sensor.set_hmirror(True)
while(True):
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected
# to the IDE. The FPS should increase once disconnected.

View File

@ -0,0 +1,21 @@
# Sensor Vertical Flip Example
#
# This example shows off vertically flipping the image in hardware
# from the camera sensor.
import sensor, image, time
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
# Change this to False to undo the flip.
sensor.set_vflip(True)
while(True):
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected
# to the IDE. The FPS should increase once disconnected.

View File

@ -18,7 +18,7 @@
import sensor, image, time
# Change this value to adjust the gain. Try 10.0/0/0.1/etc.
GAIN_SCALE = 1.00
GAIN_SCALE = 1.0
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
@ -35,6 +35,8 @@ clock = time.clock() # Create a clock object to track the FPS.
# that you put in place...
sensor.set_auto_exposure(False)
sensor.set_auto_whitebal(False)
# Need to let the above settings get in...
sensor.skip_frames(time = 500)
current_gain_in_decibels = sensor.get_gain_db()
print("Current Gain == %f db" % current_gain_in_decibels)