Skip to content

Commit

Permalink
* add api to set/get exp&wb mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lxowalle committed May 15, 2024
1 parent b12eb45 commit 2d6b338
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 2 deletions.
3 changes: 2 additions & 1 deletion components/maixcam_lib/include/sophgo_middleware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ void mmf_set_luma(int ch, uint32_t val);
int mmf_get_constrast(int ch, uint32_t *value);
int mmf_get_saturation(int ch, uint32_t *value);
int mmf_get_luma(int ch, uint32_t *value);

int mmf_set_wb_mode(int ch, int mode);
int mmf_get_wb_mode(int ch);
// sensor info
int mmf_get_sensor_id(void);

Expand Down
16 changes: 16 additions & 0 deletions components/vision/include/base/maix_camera_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ namespace maix::camera
* @param int saturation value
*/
virtual int gain(int gain) = 0;

/**
* Set/Get awb mode
* @attention This method will affect the isp and thus the image, so please be careful with it.
* @param value value = 0, means set awb to auto mode, value = 1, means set awb to manual mode, default is auto mode.
* @return returns awb mode
*/
virtual int awb_mode(int value = -1) = 0;

/**
* Set/Get exp mode
* @attention This method will affect the isp and thus the image, so please be careful with it.
* @param value value = 0, means set exposure to auto mode, value = 1, means set exposure to manual mode, default is auto mode.
* @return returns exposure mode
*/
virtual int exp_mode(int value = -1) = 0;
};

}
Expand Down
20 changes: 19 additions & 1 deletion components/vision/include/maix_camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ namespace maix::camera
* @return error code, err::ERR_NONE means success, others means failed
* @maixpy maix.camera.Camera.set_resolution
*/
err::Err set_resolution(int width, int height);
err::Err set_resolution(int width, int height);

/**
* Set/Get camera exposure
Expand Down Expand Up @@ -335,6 +335,24 @@ namespace maix::camera
* @maixpy maix.camera.Camera.saturation
*/
uint32_t saturation(uint32_t value = -1);

/**
* Set/Get white balance mode
* @attention This method will affect the isp and thus the image, so please be careful with it.
* @param value value = 0, means set white balance to auto mode, value = 1, means set white balance to manual mode, default is auto mode.
* @return returns awb mode
* @maixpy maix.camera.Camera.awb_mode
*/
uint32_t awb_mode(uint32_t value = -1);

/**
* Set/Get exposure mode
* @attention This method will affect the isp and thus the image, so please be careful with it.
* @param value value = 0, means set exposure to auto mode, value = 1, means set exposure to manual mode, default is auto mode.
* @return returns exposure mode
* @maixpy maix.camera.Camera.exp_mode
*/
uint32_t exp_mode(uint32_t value = -1);
private:
std::string _device;
int _ch;
Expand Down
10 changes: 10 additions & 0 deletions components/vision/port/linux/maix_camera_v4l2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,16 @@ namespace maix::camera
{
return -1;
}

int awb_mode(int value)
{
return -1;
}

int exp_mode(int value)
{
return -1;
}
private:
std::string device;
image::Format format;
Expand Down
28 changes: 28 additions & 0 deletions components/vision/port/maixcam/maix_camera_mmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,34 @@ namespace maix::camera
}
return out;
}

int awb_mode(int value)
{
uint32_t out;
if (value == -1) {
out = mmf_get_wb_mode(this->ch);
} else {
mmf_set_wb_mode(this->ch, value);
out = value;
}

err::check_bool_raise(out >= 0, "set white balance failed");
return out;
}

int exp_mode(int value)
{
uint32_t out;
if (value == -1) {
out = mmf_get_exp_mode(this->ch);
} else {
mmf_set_exp_mode(this->ch, value);
out = value;
}

err::check_bool_raise(out >= 0, "set exposure failed");
return out;
}
private:
std::string device;
image::Format format;
Expand Down
22 changes: 22 additions & 0 deletions components/vision/src/maix_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,27 @@ namespace maix::camera

return _impl->saturation(value);
}

uint32_t Camera::awb_mode(uint32_t value) {
if (_impl == NULL)
return err::ERR_NOT_INIT;

if (!this->is_opened()) {
return err::ERR_NOT_OPEN;
}

return _impl->awb_mode(value);
}

uint32_t Camera::exp_mode(uint32_t value) {
if (_impl == NULL)
return err::ERR_NOT_INIT;

if (!this->is_opened()) {
return err::ERR_NOT_OPEN;
}

return _impl->exp_mode(value);
}
}

22 changes: 22 additions & 0 deletions examples/camera_display/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ static int cmd_init(void)
"2 <value> : set luma\r\n"
"3 <value> : set constrast\r\n"
"4 <value> : set saturation\r\n"
"5 <value> : set white balance mode\r\n"
"6 <value> : set exposure mode\r\n"
"========================\r\n");
fflush(stdin);
return 0;
Expand Down Expand Up @@ -160,6 +162,26 @@ static int cmd_loop(camera::Camera *cam)
log::info("get saturation: %d\r\n", out);
}
break;
case 5:
{
uint32_t out = 0;
out = cam->awb_mode(value);
err::check_bool_raise(out == value, "set error");
log::info("set white balance mode: %ld\r\n", value);
out = cam->awb_mode();
log::info("get white balance mode: %d\r\n", out);
}
break;
case 6:
{
uint32_t out = 0;
out = cam->exp_mode(value);
err::check_bool_raise(out == value, "set error");
log::info("set exposure mode: %ld\r\n", value);
out = cam->exp_mode();
log::info("get exposure mode: %d\r\n", out);
}
break;
default:printf("Find not cmd!\r\n"); break;
}
log::info("cmd use %ld ms\r\n", time::time_ms() - t1);
Expand Down

0 comments on commit 2d6b338

Please sign in to comment.