Skip to content

Commit

Permalink
* Add the raw parameter to control capturing raw images.
Browse files Browse the repository at this point in the history
  • Loading branch information
lxowalle committed Sep 11, 2024
1 parent 59b6614 commit 7fa844f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
3 changes: 2 additions & 1 deletion components/vision/include/maix_camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ namespace maix::camera
* @param buff_num camera buffer number, default is 3, means 3 buffer, one used by user, one used for cache the next frame,
* more than one buffer will accelerate image read speed, but will cost more memory.
* @param open If true, camera will automatically call open() after creation. default is true.
* @param raw If true, you can use read_raw() to capture the raw image output from the sensor.
* @maixpy maix.camera.Camera.__init__
* @maixcdk maix.camera.Camera.Camera
*/
Camera(int width = -1, int height = -1, image::Format format = image::FMT_RGB888, const char *device = nullptr, int fps = -1, int buff_num = 3, bool open = true);
Camera(int width = -1, int height = -1, image::Format format = image::FMT_RGB888, const char *device = nullptr, int fps = -1, int buff_num = 3, bool open = true, bool raw = false);
~Camera();

/**
Expand Down
2 changes: 1 addition & 1 deletion components/vision/port/linux/maix_camera_v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ namespace maix::camera
}

static CameraV4L2 *_impl;
Camera::Camera(int width, int height, image::Format format, const char *device, int fps, int buff_num, bool open)
Camera::Camera(int width, int height, image::Format format, const char *device, int fps, int buff_num, bool open, bool raw)
{
err::Err e;
err::check_bool_raise(_check_format(format), "Format not support");
Expand Down
28 changes: 21 additions & 7 deletions components/vision/port/maixcam/maix_camera_mmf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ namespace maix::camera
int dev;
SAMPLE_SNS_TYPE_E sns_type;
ISP_BAYER_FORMAT_E bayer_fmt;
} mmf_camera_priv_t;
bool raw;
} camera_priv_t;

Camera::Camera(int width, int height, image::Format format, const char *device, int fps, int buff_num, bool open)
Camera::Camera(int width, int height, image::Format format, const char *device, int fps, int buff_num, bool open, bool raw)
{
err::Err e;
err::check_bool_raise(_check_format(format), "Format not support");
Expand All @@ -86,9 +87,11 @@ namespace maix::camera
_invert_mirror = false;
_is_opened = false;

mmf_camera_priv_t *priv = (mmf_camera_priv_t *)malloc(sizeof(mmf_camera_priv_t));
err::check_null_raise(priv, "mmf_camera_priv_t malloc error");
camera_priv_t *priv = (camera_priv_t *)malloc(sizeof(camera_priv_t));
err::check_null_raise(priv, "camera_priv_t malloc error");
memset(priv, 0, sizeof(camera_priv_t));
priv->dev = 0;
priv->raw = raw;
_param = priv;


Expand Down Expand Up @@ -128,6 +131,10 @@ namespace maix::camera
if (this->is_opened()) {
this->close();
}

if (_param) {
free(_param);
}
}

int Camera::get_ch_nums()
Expand Down Expand Up @@ -302,7 +309,7 @@ namespace maix::camera
return poolIdCount;
}

static int _mmf_vi_init(char *board_name, int width, int height, int fps, mmf_camera_priv_t *priv)
static int _mmf_vi_init(char *board_name, int width, int height, int fps, camera_priv_t *priv)
{
SIZE_S stSize;
PIC_SIZE_E enPicSize;
Expand Down Expand Up @@ -439,7 +446,9 @@ namespace maix::camera

err::check_bool_raise(!mmf_init_v2(false), "mmf init failed");
err::check_bool_raise(!SAMPLE_COMM_VI_IniToViCfg(&stIniCfg, &stViConfig), "IniToViCfg failed!");
stViConfig.astViInfo[0].stChnInfo.enCompressMode = COMPRESS_MODE_NONE;
if (priv->raw) {
stViConfig.astViInfo[0].stChnInfo.enCompressMode = COMPRESS_MODE_NONE;
}
err::check_bool_raise(!SAMPLE_COMM_VI_GetSizeBySensor(stIniCfg.enSnsType[0], &enPicSize), "GetSizeBySensor failed!");
err::check_bool_raise(!SAMPLE_COMM_SYS_GetPicSize(enPicSize, &stSize), "GetPicSize failed!");

Expand All @@ -457,7 +466,7 @@ namespace maix::camera
image::Format format_tmp = (format == image::FMT_INVALID) ? _format : format;
int fps_tmp = (fps == -1) ? _fps : fps;
int buff_num_tmp =( buff_num == -1) ? _buff_num : buff_num;
mmf_camera_priv_t *priv = (mmf_camera_priv_t *)_param;
camera_priv_t *priv = (camera_priv_t *)_param;

// check format
err::check_bool_raise(_check_format(format_tmp), "Format not support");
Expand Down Expand Up @@ -836,6 +845,11 @@ namespace maix::camera
err::check_raise(e, "open camera failed");
}

camera_priv_t *priv = (camera_priv_t *)this->_param;
if (!priv->raw) {
err::check_raise(err::ERR_NOT_READY, "you need to enable the raw parameter when constructing the Camera object.");
}

VI_DUMP_ATTR_S attr;
memset(&attr, 0, sizeof(VI_DUMP_ATTR_S));
CVI_VI_GetPipeDumpAttr(0, &attr);
Expand Down
11 changes: 7 additions & 4 deletions examples/camera_display/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ int _main(int argc, char* argv[])
image::Format cam_fmt = image::Format::FMT_RGB888;
int cam_fps = -1;
int cam_buffer_num = 3;
bool raw = true;
if (argc > 1) {
if (!strcmp(argv[1], "-h")) {
log::info("./camera_display <width> <height> <format> <fps> <buff_num>");
log::info("example: ./camera_display 640 480 0 60 2");
log::info("./camera_display <width> <height> <format> <fps> <buff_num> <raw>");
log::info("example: ./camera_display 640 480 0 60 2 1");
exit(0);
} else {
cam_w = atoi(argv[1]);
Expand All @@ -43,9 +44,11 @@ int _main(int argc, char* argv[])
if (argc > 3) cam_fmt = (image::Format)atoi(argv[3]);
if (argc > 4) cam_fps = atoi(argv[4]);
if (argc > 5) cam_buffer_num = atoi(argv[5]);
log::info("Camera width:%d height:%d format:%s fps:%d buffer_num:%d", cam_w, cam_h, image::fmt_names[cam_fmt].c_str(), cam_fps, cam_buffer_num);
if (argc > 6) raw = atoi(argv[6]) ? true : false;
log::info("Camera width:%d height:%d format:%s fps:%d buffer_num:%d raw:%d",
cam_w, cam_h, image::fmt_names[cam_fmt].c_str(), cam_fps, cam_buffer_num, raw);

camera::Camera cam = camera::Camera(cam_w, cam_h, cam_fmt, "", cam_fps, cam_buffer_num);
camera::Camera cam = camera::Camera(cam_w, cam_h, cam_fmt, "", cam_fps, cam_buffer_num, true, raw);
camera::Camera *cam2 = NULL;
display::Display disp = display::Display();
display::Display *disp2 = NULL;
Expand Down

0 comments on commit 7fa844f

Please sign in to comment.