From 2d6b3389979f25abbdaf80edbcdfdfeea4563006 Mon Sep 17 00:00:00 2001 From: lxowalle Date: Wed, 15 May 2024 10:33:15 +0800 Subject: [PATCH] * add api to set/get exp&wb mode --- .../maixcam_lib/include/sophgo_middleware.hpp | 3 +- .../vision/include/base/maix_camera_base.hpp | 16 +++++++++++ components/vision/include/maix_camera.hpp | 20 ++++++++++++- .../vision/port/linux/maix_camera_v4l2.hpp | 10 +++++++ .../vision/port/maixcam/maix_camera_mmf.hpp | 28 +++++++++++++++++++ components/vision/src/maix_camera.cpp | 22 +++++++++++++++ examples/camera_display/main/src/main.cpp | 22 +++++++++++++++ 7 files changed, 119 insertions(+), 2 deletions(-) diff --git a/components/maixcam_lib/include/sophgo_middleware.hpp b/components/maixcam_lib/include/sophgo_middleware.hpp index 55d1e23b..b2c91aab 100644 --- a/components/maixcam_lib/include/sophgo_middleware.hpp +++ b/components/maixcam_lib/include/sophgo_middleware.hpp @@ -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); diff --git a/components/vision/include/base/maix_camera_base.hpp b/components/vision/include/base/maix_camera_base.hpp index 8b8f35d1..5b793037 100644 --- a/components/vision/include/base/maix_camera_base.hpp +++ b/components/vision/include/base/maix_camera_base.hpp @@ -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; }; } diff --git a/components/vision/include/maix_camera.hpp b/components/vision/include/maix_camera.hpp index 3ad820b1..89fe8977 100644 --- a/components/vision/include/maix_camera.hpp +++ b/components/vision/include/maix_camera.hpp @@ -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 @@ -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; diff --git a/components/vision/port/linux/maix_camera_v4l2.hpp b/components/vision/port/linux/maix_camera_v4l2.hpp index 2e366ab0..9df62157 100644 --- a/components/vision/port/linux/maix_camera_v4l2.hpp +++ b/components/vision/port/linux/maix_camera_v4l2.hpp @@ -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; diff --git a/components/vision/port/maixcam/maix_camera_mmf.hpp b/components/vision/port/maixcam/maix_camera_mmf.hpp index 0a9fc139..cbc69fde 100644 --- a/components/vision/port/maixcam/maix_camera_mmf.hpp +++ b/components/vision/port/maixcam/maix_camera_mmf.hpp @@ -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; diff --git a/components/vision/src/maix_camera.cpp b/components/vision/src/maix_camera.cpp index 3d0c45df..1816564c 100644 --- a/components/vision/src/maix_camera.cpp +++ b/components/vision/src/maix_camera.cpp @@ -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); + } } diff --git a/examples/camera_display/main/src/main.cpp b/examples/camera_display/main/src/main.cpp index 284a19dd..e028e49f 100644 --- a/examples/camera_display/main/src/main.cpp +++ b/examples/camera_display/main/src/main.cpp @@ -90,6 +90,8 @@ static int cmd_init(void) "2 : set luma\r\n" "3 : set constrast\r\n" "4 : set saturation\r\n" + "5 : set white balance mode\r\n" + "6 : set exposure mode\r\n" "========================\r\n"); fflush(stdin); return 0; @@ -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);