mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-04 06:06:17 +00:00
t/calib: Add support to load images
This commit is contained in:
parent
0cbd3e8601
commit
9b60bd7c77
|
@ -148,6 +148,12 @@ public:
|
||||||
uint32_t collected_of_part = 0;
|
uint32_t collected_of_part = 0;
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
bool enabled = false;
|
||||||
|
uint32_t num_images = 20;
|
||||||
|
} load;
|
||||||
|
|
||||||
//! Should we use subpixel enhancing for checkerboard.
|
//! Should we use subpixel enhancing for checkerboard.
|
||||||
bool subpixel_enable = true;
|
bool subpixel_enable = true;
|
||||||
//! What subpixel range for checkerboard enhancement.
|
//! What subpixel range for checkerboard enhancement.
|
||||||
|
@ -887,6 +893,18 @@ make_calibration_frame_sbs(class Calibration &c)
|
||||||
send_rgb_frame(c);
|
send_rgb_frame(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
make_calibration_frame(class Calibration &c, struct xrt_frame *xf)
|
||||||
|
{
|
||||||
|
switch (xf->stereo_format) {
|
||||||
|
case XRT_STEREO_FORMAT_SBS: make_calibration_frame_sbs(c); break;
|
||||||
|
case XRT_STEREO_FORMAT_NONE: make_calibration_frame_mono(c); break;
|
||||||
|
default:
|
||||||
|
P("ERROR: Unknown stereo format! '%i'", xf->stereo_format);
|
||||||
|
make_gui_str(c);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -927,6 +945,60 @@ process_frame_yuyv(class Calibration &c, struct xrt_frame *xf)
|
||||||
cv::cvtColor(data_full, c.grey, cv::COLOR_YUV2GRAY_YUYV);
|
cv::cvtColor(data_full, c.grey, cv::COLOR_YUV2GRAY_YUYV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XRT_NO_INLINE static void
|
||||||
|
process_load_image(class Calibration &c, struct xrt_frame *xf)
|
||||||
|
{
|
||||||
|
char buf[512];
|
||||||
|
|
||||||
|
// We need to change the settings for frames to make it work.
|
||||||
|
uint32_t num_collect_restart = 1;
|
||||||
|
uint32_t num_cooldown_frames = 0;
|
||||||
|
uint32_t num_wait_for = 0;
|
||||||
|
|
||||||
|
std::swap(c.num_collect_restart, num_collect_restart);
|
||||||
|
std::swap(c.num_cooldown_frames, num_cooldown_frames);
|
||||||
|
std::swap(c.num_wait_for, num_wait_for);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < c.load.num_images; i++) {
|
||||||
|
// Early out if the user requeted less images.
|
||||||
|
if (c.state.calibrated) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buf, 512, "grey_%03i.png", i);
|
||||||
|
c.grey = cv::imread(buf, cv::IMREAD_GRAYSCALE);
|
||||||
|
|
||||||
|
if (c.grey.rows == 0 || c.grey.cols == 0) {
|
||||||
|
fprintf(stderr, "Could not find image '%s'!\n", buf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.grey.rows != (int)xf->height ||
|
||||||
|
c.grey.cols != (int)xf->width) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Image size does not match frame size! Image: "
|
||||||
|
"(%ix%i) Frame: (%ux%u)\n",
|
||||||
|
c.grey.cols, c.grey.rows, xf->width,
|
||||||
|
xf->height);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new RGB image and then copy the grey data to it.
|
||||||
|
refresh_gui_frame(c, c.grey.rows, c.grey.cols);
|
||||||
|
cv::cvtColor(c.grey, c.gui.rgb, cv::COLOR_GRAY2RGB);
|
||||||
|
|
||||||
|
// Call the normal frame processing now.
|
||||||
|
make_calibration_frame(c, xf);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore settings.
|
||||||
|
c.num_collect_restart = num_collect_restart;
|
||||||
|
c.num_cooldown_frames = num_cooldown_frames;
|
||||||
|
c.num_wait_for = num_wait_for;
|
||||||
|
|
||||||
|
c.load.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -939,6 +1011,10 @@ t_calibration_frame(struct xrt_frame_sink *xsink, struct xrt_frame *xf)
|
||||||
{
|
{
|
||||||
auto &c = *(class Calibration *)xsink;
|
auto &c = *(class Calibration *)xsink;
|
||||||
|
|
||||||
|
if (c.load.enabled) {
|
||||||
|
process_load_image(c, xf);
|
||||||
|
}
|
||||||
|
|
||||||
// Fill both c.gui.rgb and c.grey with the data we got.
|
// Fill both c.gui.rgb and c.grey with the data we got.
|
||||||
switch (xf->format) {
|
switch (xf->format) {
|
||||||
case XRT_FORMAT_YUV888: process_frame_yuv(c, xf); break;
|
case XRT_FORMAT_YUV888: process_frame_yuv(c, xf); break;
|
||||||
|
@ -967,14 +1043,7 @@ t_calibration_frame(struct xrt_frame_sink *xsink, struct xrt_frame *xf)
|
||||||
cv::Scalar(0, 0, 0), -1, 0);
|
cv::Scalar(0, 0, 0), -1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (xf->stereo_format) {
|
make_calibration_frame(c, xf);
|
||||||
case XRT_STEREO_FORMAT_SBS: make_calibration_frame_sbs(c); break;
|
|
||||||
case XRT_STEREO_FORMAT_NONE: make_calibration_frame_mono(c); break;
|
|
||||||
default:
|
|
||||||
P("ERROR: Unknown stereo format! '%i'", xf->stereo_format);
|
|
||||||
make_gui_str(c);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1031,6 +1100,8 @@ t_calibration_stereo_create(struct xrt_frame_context *xfctx,
|
||||||
c.num_wait_for = params->num_wait_for;
|
c.num_wait_for = params->num_wait_for;
|
||||||
c.num_collect_total = params->num_collect_total;
|
c.num_collect_total = params->num_collect_total;
|
||||||
c.num_collect_restart = params->num_collect_restart;
|
c.num_collect_restart = params->num_collect_restart;
|
||||||
|
c.load.enabled = params->load.enabled;
|
||||||
|
c.load.num_images = params->load.num_images;
|
||||||
c.mirror_rgb_image = params->mirror_rgb_image;
|
c.mirror_rgb_image = params->mirror_rgb_image;
|
||||||
c.save_images = params->save_images;
|
c.save_images = params->save_images;
|
||||||
|
|
||||||
|
|
|
@ -343,6 +343,10 @@ t_psvr_create(struct xrt_frame_context *xfctx,
|
||||||
17, \
|
17, \
|
||||||
0.02f, \
|
0.02f, \
|
||||||
}, \
|
}, \
|
||||||
|
{ \
|
||||||
|
false, \
|
||||||
|
20, \
|
||||||
|
}, \
|
||||||
20, 5, 20, 1, false, true, \
|
20, 5, 20, 1, false, true, \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,6 +392,12 @@ struct t_calibration_params
|
||||||
float diagonal_distance_meters;
|
float diagonal_distance_meters;
|
||||||
} asymmetric_circles;
|
} asymmetric_circles;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
bool enabled;
|
||||||
|
int num_images;
|
||||||
|
} load;
|
||||||
|
|
||||||
int num_cooldown_frames;
|
int num_cooldown_frames;
|
||||||
int num_wait_for;
|
int num_wait_for;
|
||||||
int num_collect_total;
|
int num_collect_total;
|
||||||
|
|
|
@ -116,6 +116,12 @@ scene_render_select(struct gui_scene *scene, struct gui_program *p)
|
||||||
igCheckbox("Mirror (no calibration effect)", &cs->params.mirror_rgb_image);
|
igCheckbox("Mirror (no calibration effect)", &cs->params.mirror_rgb_image);
|
||||||
igCheckbox("Save images (mono only)", &cs->params.save_images);
|
igCheckbox("Save images (mono only)", &cs->params.save_images);
|
||||||
|
|
||||||
|
igSeparator();
|
||||||
|
igCheckbox("Load images (kinda mono only)", &cs->params.load.enabled);
|
||||||
|
if (cs->params.load.enabled) {
|
||||||
|
igInputInt("# images", &cs->params.load.num_images, 1, 5, 0);
|
||||||
|
}
|
||||||
|
|
||||||
igSeparator();
|
igSeparator();
|
||||||
igInputInt("Cooldown for # frames", &cs->params.num_cooldown_frames, 1, 5, 0);
|
igInputInt("Cooldown for # frames", &cs->params.num_cooldown_frames, 1, 5, 0);
|
||||||
igInputInt("Wait for # frames (steady)", &cs->params.num_wait_for, 1, 5, 0);
|
igInputInt("Wait for # frames (steady)", &cs->params.num_wait_for, 1, 5, 0);
|
||||||
|
|
Loading…
Reference in a new issue