mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Add set_quality for JPEG mode
This commit is contained in:
parent
366171b042
commit
78ad46dd34
@ -1 +1 @@
|
||||
Subproject commit c09c79a6284f8b9bb84bbacac9a2b0d7b7c9dd9b
|
||||
Subproject commit 0cd550e41331e9be8a4c126a8b8ee2066f267bf5
|
||||
@ -545,6 +545,19 @@ static int set_gainceiling(enum sensor_gainceiling gainceiling)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int set_quality(int qs)
|
||||
{
|
||||
int ret=0;
|
||||
|
||||
/* Switch to DSP register bank */
|
||||
ret |= SCCB_Write(BANK_SEL, BANK_SEL_DSP);
|
||||
|
||||
/* Write QS register */
|
||||
ret |= SCCB_Write(QS, qs);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ov2640_init(struct sensor_dev *sensor)
|
||||
{
|
||||
/* set HSYNC/VSYNC/PCLK polarity */
|
||||
@ -562,5 +575,6 @@ int ov2640_init(struct sensor_dev *sensor)
|
||||
sensor->set_saturation= set_saturation;
|
||||
sensor->set_exposure = set_exposure;
|
||||
sensor->set_gainceiling = set_gainceiling;
|
||||
sensor->set_quality = set_quality;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#include "mp.h"
|
||||
#include "sccb.h"
|
||||
#include "sensor.h"
|
||||
#include "py_assert.h"
|
||||
#include "py_image.h"
|
||||
#include "py_sensor.h"
|
||||
|
||||
@ -113,6 +114,18 @@ static mp_obj_t py_sensor_set_contrast(mp_obj_t contrast) {
|
||||
return mp_const_true;
|
||||
}
|
||||
|
||||
static mp_obj_t py_sensor_set_quality(mp_obj_t qs) {
|
||||
int q = mp_obj_get_int(qs);
|
||||
PY_ASSERT_TRUE((q >= 0 && q <= 100));
|
||||
|
||||
q = 100-q; //invert quality
|
||||
q = 255*q/100; //map to 0->255
|
||||
if (sensor_set_quality(q) != 0) {
|
||||
return mp_const_false;
|
||||
}
|
||||
return mp_const_true;
|
||||
}
|
||||
|
||||
static mp_obj_t py_sensor_write_reg(mp_obj_t addr, mp_obj_t val) {
|
||||
SCCB_Write(mp_obj_get_int(addr), mp_obj_get_int(val));
|
||||
return mp_const_none;
|
||||
@ -138,6 +151,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_framesize_obj, py_sensor_set_fr
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_gainceiling_obj, py_sensor_set_gainceiling);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_contrast_obj, py_sensor_set_contrast);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_brightness_obj, py_sensor_set_brightness);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_quality_obj, py_sensor_set_quality);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(py_sensor_write_reg_obj, py_sensor_write_reg);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_read_reg_obj, py_sensor_read_reg);
|
||||
|
||||
@ -167,6 +181,7 @@ STATIC const mp_map_elem_t globals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_gainceiling), (mp_obj_t)&py_sensor_set_gainceiling_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_contrast), (mp_obj_t)&py_sensor_set_contrast_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_brightness), (mp_obj_t)&py_sensor_set_brightness_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_quality), (mp_obj_t)&py_sensor_set_quality_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___write_reg), (mp_obj_t)&py_sensor_write_reg_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___read_reg), (mp_obj_t)&py_sensor_read_reg_obj },
|
||||
};
|
||||
|
||||
@ -474,3 +474,14 @@ int sensor_set_gainceiling(enum sensor_gainceiling gainceiling)
|
||||
sensor.gainceiling = gainceiling;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sensor_set_quality(int qs)
|
||||
{
|
||||
/* call the sensor specific function */
|
||||
if (sensor.set_quality == NULL
|
||||
|| sensor.set_quality(qs) != 0) {
|
||||
/* operation not supported */
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -72,15 +72,16 @@ struct sensor_dev {
|
||||
enum sensor_framerate framerate;
|
||||
enum sensor_gainceiling gainceiling;
|
||||
/* Sensor function pointers */
|
||||
int (*reset) ();
|
||||
int (*set_pixformat) (enum sensor_pixformat pixformat);
|
||||
int (*set_framesize) (enum sensor_framesize framesize);
|
||||
int (*set_framerate) (enum sensor_framerate framerate);
|
||||
int (*set_contrast) (int level);
|
||||
int (*set_brightness) (int level);
|
||||
int (*set_saturation) (int level);
|
||||
int (*set_exposure) (int exposure);
|
||||
int (*reset) ();
|
||||
int (*set_pixformat) (enum sensor_pixformat pixformat);
|
||||
int (*set_framesize) (enum sensor_framesize framesize);
|
||||
int (*set_framerate) (enum sensor_framerate framerate);
|
||||
int (*set_contrast) (int level);
|
||||
int (*set_brightness) (int level);
|
||||
int (*set_saturation) (int level);
|
||||
int (*set_exposure) (int exposure);
|
||||
int (*set_gainceiling) (enum sensor_gainceiling gainceiling);
|
||||
int (*set_quality) (int quality);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -191,4 +192,12 @@ int sensor_set_exposure(int exposure);
|
||||
* @return On success, 0 is returned. If the operation not supported by the sensor, -1 is returned.
|
||||
*/
|
||||
int sensor_set_gainceiling(enum sensor_gainceiling gainceiling);
|
||||
/**
|
||||
* Set the quantization scale factor, controls JPEG quality.
|
||||
*
|
||||
* @param sensor A pointer to the sensor device handle.
|
||||
* @param quality 0-255.
|
||||
* @return On success, 0 is returned. If the operation not supported by the sensor, -1 is returned.
|
||||
*/
|
||||
int sensor_set_quality(int qs);
|
||||
#endif /* __SENSOR_H__ */
|
||||
|
||||
@ -10,6 +10,7 @@ sensor.set_contrast(1)
|
||||
# Set sensor pixel format
|
||||
sensor.set_framesize(sensor.QVGA)
|
||||
sensor.set_pixformat(sensor.JPEG)
|
||||
sensor.set_quality(98)
|
||||
|
||||
clock = time.clock()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user