Skip to content

Commit

Permalink
test-surround-view: support saving output in cubemap
Browse files Browse the repository at this point in the history
  • Loading branch information
unishift authored and zongwave committed Aug 17, 2021
1 parent d490afe commit 56a2b85
Showing 1 changed file with 123 additions and 45 deletions.
168 changes: 123 additions & 45 deletions tests/test-surround-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ enum SVModule {
SVModuleVulkan
};

enum SVOutIdx {
IdxStitch = 0,
IdxTopView,
IdxCount
struct SVOutConfig {
bool save_output = true;
uint32_t stitch_index = 0;

bool save_topview = false;
uint32_t topview_index;

bool save_cubemap = false;
uint32_t cubemap_index;

bool is_save() const {
return save_output || save_topview || save_cubemap;
}
};

class SVStream
Expand Down Expand Up @@ -320,22 +329,59 @@ remap_topview_buf (const SmartPtr<SVStream> &stitch, const SmartPtr<SVStream> &t
return XCAM_RETURN_NO_ERROR;
}

static XCamReturn
create_cubemap_mapper (
const SmartPtr<Stitcher> &stitcher, const SmartPtr<SVStream> &stitch,
const SmartPtr<SVStream> &cubemap, SVModule module)
{
CubeMapModel cubemap_model (stitch->get_width (), stitch->get_height ());
CubeMapModel::PointMap points;

cubemap_model.get_cubemap_rect_map (points, cubemap->get_width (), cubemap->get_height ());
SmartPtr<GeoMapper> mapper;
if (module == SVModuleSoft) {
mapper = GeoMapper::create_soft_geo_mapper ();
} else if (module == SVModuleGLES) {
#if HAVE_GLES
mapper = GeoMapper::create_gl_geo_mapper ();
#endif
} else if (module == SVModuleVulkan) {
#if HAVE_VULKAN
SmartPtr<VKDevice> dev = stitch->get_vk_device ();
XCAM_ASSERT (dev.ptr ());
mapper = GeoMapper::create_vk_geo_mapper (dev, "cubemap-map");
#endif
}
XCAM_ASSERT (mapper.ptr ());

mapper->set_output_size (cubemap->get_width (), cubemap->get_height ());
mapper->set_lookup_table (points.data (), cubemap->get_width (), cubemap->get_height ());
cubemap->set_mapper (mapper);

return XCAM_RETURN_NO_ERROR;
}

static void
write_image (
const SmartPtr<Stitcher> &stitcher,
const SVStreams &ins, const SVStreams &outs,
bool save_output, bool save_topview)
const SVOutConfig &out_config)
{
static uint32_t frame_num = 0;

write_in_image (stitcher, ins, frame_num);

if (save_output)
write_out_image (outs[IdxStitch], frame_num);
if (out_config.save_output)
write_out_image (outs[out_config.stitch_index], frame_num);

if (out_config.save_topview) {
remap_topview_buf (outs[out_config.stitch_index], outs[out_config.topview_index]);
write_out_image (outs[out_config.topview_index], frame_num);
}

if (save_topview) {
remap_topview_buf (outs[IdxStitch], outs[IdxTopView]);
write_out_image (outs[IdxTopView], frame_num);
if (out_config.save_cubemap) {
remap_topview_buf (outs[out_config.stitch_index], outs[out_config.cubemap_index]);
write_out_image (outs[out_config.cubemap_index], frame_num);
}

frame_num++;
Expand All @@ -356,7 +402,7 @@ static int
single_frame (
const SmartPtr<Stitcher> &stitcher,
const SVStreams &ins, const SVStreams &outs,
bool save_output, bool save_topview, int loop)
const SVOutConfig &out_config, int loop)
{
for (uint32_t i = 0; i < ins.size (); ++i) {
CHECK (ins[i]->rewind (), "rewind buffer from file(%s) failed", ins[i]->get_file_name ());
Expand All @@ -374,13 +420,13 @@ single_frame (
while (loop--) {
XCAM_OBJ_PROFILING_START;

CHECK (stitcher->stitch_buffers (in_buffers, outs[IdxStitch]->get_buf ()), "stitch buffer failed.");
CHECK (stitcher->stitch_buffers (in_buffers, outs[out_config.stitch_index]->get_buf ()), "stitch buffer failed.");

XCAM_OBJ_PROFILING_END ("stitch-buffers", XCAM_OBJ_DUR_FRAME_NUM);

if (save_output || save_topview) {
if (out_config.is_save()) {
if (stitcher->complete_stitch ()) {
write_image (stitcher, ins, outs, save_output, save_topview);
write_image (stitcher, ins, outs, out_config);
}
}

Expand All @@ -396,7 +442,7 @@ static int
multi_frame (
const SmartPtr<Stitcher> &stitcher,
const SVStreams &ins, const SVStreams &outs,
bool save_output, bool save_topview, int loop)
const SVOutConfig &out_config, int loop)
{
XCamReturn ret = XCAM_RETURN_NO_ERROR;

Expand All @@ -423,14 +469,14 @@ multi_frame (
XCAM_OBJ_PROFILING_START;

CHECK (
stitcher->stitch_buffers (in_buffers, outs[IdxStitch]->get_buf ()),
stitcher->stitch_buffers (in_buffers, outs[out_config.stitch_index]->get_buf ()),
"stitch buffer failed.");

XCAM_OBJ_PROFILING_END ("stitch-buffers", XCAM_OBJ_DUR_FRAME_NUM);

if (save_output || save_topview) {
if (out_config.is_save()) {
if (stitcher->complete_stitch ()) {
write_image (stitcher, ins, outs, save_output, save_topview);
write_image (stitcher, ins, outs, out_config);
}
}

Expand All @@ -447,7 +493,7 @@ static int
run_stitcher (
const SmartPtr<Stitcher> &stitcher,
const SVStreams &ins, const SVStreams &outs,
FrameMode frame_mode, bool save_output, bool save_topview, int loop)
FrameMode frame_mode, const SVOutConfig &out_config, int loop)
{
XCAM_OBJ_PROFILING_INIT;

Expand All @@ -456,9 +502,9 @@ run_stitcher (

int ret = -1;
if (frame_mode == FrameSingle)
ret = single_frame (stitcher, ins, outs, save_output, save_topview, loop);
ret = single_frame (stitcher, ins, outs, out_config, loop);
else if (frame_mode == FrameMulti)
ret = multi_frame (stitcher, ins, outs, save_output, save_topview, loop);
ret = multi_frame (stitcher, ins, outs, out_config, loop);
else
XCAM_LOG_ERROR ("invalid frame mode: %d", frame_mode);

Expand Down Expand Up @@ -516,6 +562,8 @@ int main (int argc, char *argv[])
uint32_t output_height = 640;
uint32_t topview_width = 1280;
uint32_t topview_height = 720;
uint32_t cubemap_width = 1280;
uint32_t cubemap_height = 720;

SVStreams ins;
SVStreams outs;
Expand All @@ -541,8 +589,7 @@ int main (int argc, char *argv[])

int loop = 1;
int repeat = 1;
bool save_output = true;
bool save_topview = false;
SVOutConfig out_config;

const struct option long_opts[] = {
{"module", required_argument, NULL, 'm'},
Expand All @@ -555,6 +602,8 @@ int main (int argc, char *argv[])
{"out-h", required_argument, NULL, 'H'},
{"topview-w", required_argument, NULL, 'P'},
{"topview-h", required_argument, NULL, 'V'},
{"cubemap-w", required_argument, NULL, 'X'},
{"cubemap-h", required_argument, NULL, 'Y'},
{"in-format", required_argument, NULL, 'p'},
{"fisheye-num", required_argument, NULL, 'N'},
{"cam-model", required_argument, NULL, 'C'},
Expand All @@ -570,6 +619,7 @@ int main (int argc, char *argv[])
{"frame-mode", required_argument, NULL, 'f'},
{"save", required_argument, NULL, 's'},
{"save-topview", required_argument, NULL, 't'},
{"save-cubemap", required_argument, NULL, 'q'},
{"loop", required_argument, NULL, 'L'},
{"repeat", required_argument, NULL, 'R'},
{"help", no_argument, NULL, 'e'},
Expand Down Expand Up @@ -635,6 +685,12 @@ int main (int argc, char *argv[])
case 'V':
topview_height = atoi(optarg);
break;
case 'X':
cubemap_width = atoi(optarg);
break;
case 'Y':
cubemap_height = atoi(optarg);
break;
case 'N':
fisheye_num = atoi(optarg);
if (fisheye_num > XCAM_STITCH_FISHEYE_MAX_NUM) {
Expand Down Expand Up @@ -748,10 +804,13 @@ int main (int argc, char *argv[])
}
break;
case 's':
save_output = (strcasecmp (optarg, "false") == 0 ? false : true);
out_config.save_output = (strcasecmp (optarg, "false") == 0 ? false : true);
break;
case 't':
save_topview = (strcasecmp (optarg, "false") == 0 ? false : true);
out_config.save_topview = (strcasecmp (optarg, "false") == 0 ? false : true);
break;
case 'q':
out_config.save_cubemap = (strcasecmp (optarg, "false") == 0 ? false : true);
break;
case 'L':
loop = atoi(optarg);
Expand Down Expand Up @@ -786,8 +845,8 @@ int main (int argc, char *argv[])
CHECK_EXP (strlen (ins[i]->get_file_name ()), "input file name was not set, index:%d", i);
}

CHECK_EXP (outs.size () == 1 && outs[IdxStitch].ptr (), "surrond view needs 1 output stream");
CHECK_EXP (strlen (outs[IdxStitch]->get_file_name ()), "output file name was not set");
CHECK_EXP (outs.size () == 1 && outs[out_config.stitch_index].ptr (), "surrond view needs 1 output stream");
CHECK_EXP (strlen (outs[out_config.stitch_index]->get_file_name ()), "output file name was not set");

for (uint32_t i = 0; i < ins.size (); ++i) {
printf ("input%d file:\t\t%s\n", i, ins[i]->get_file_name ());
Expand All @@ -798,13 +857,15 @@ int main (int argc, char *argv[])
printf ("stitch module:\t\t%s\n", module == SVModuleGLES ? "GLES" :
(module == SVModuleVulkan ? "Vulkan" : (module == SVModuleSoft ? "Soft" : "Unknown")));
printf ("device node:\t\t%s\n", device_node != NULL ? device_node : "Not specified, use default model");
printf ("output file:\t\t%s\n", outs[IdxStitch]->get_file_name ());
printf ("output file:\t\t%s\n", outs[out_config.stitch_index]->get_file_name ());
printf ("input width:\t\t%d\n", input_width);
printf ("input height:\t\t%d\n", input_height);
printf ("output width:\t\t%d\n", output_width);
printf ("output height:\t\t%d\n", output_height);
printf ("topview width:\t\t%d\n", topview_width);
printf ("topview height:\t\t%d\n", topview_height);
printf ("cubemap width:\t\t%d\n", cubemap_width);
printf ("cubemap height:\t\t%d\n", cubemap_height);
printf ("input format:\t\t%s\n", input_format == V4L2_PIX_FMT_YUV420 ? "yuv" : "nv12");
printf ("blend pyr levels:\t%d\n", blend_pyr_levels);
printf ("dewarp mode: \t\t%s\n", dewarp_mode == DewarpSphere ? "sphere" : "bowl");
Expand All @@ -820,8 +881,9 @@ int main (int argc, char *argv[])
((fm_status == FMStatusHalfWay) ? "halfway" : "fmfirst"));
#endif
printf ("frame mode:\t\t%s\n", (frame_mode == FrameSingle) ? "singleframe" : "multiframe");
printf ("save output:\t\t%s\n", save_output ? "true" : "false");
printf ("save topview:\t\t%s\n", save_topview ? "true" : "false");
printf ("save output:\t\t%s\n", out_config.save_output ? "true" : "false");
printf ("save topview:\t\t%s\n", out_config.save_topview ? "true" : "false");
printf ("save cubemap:\t\t%s\n", out_config.save_cubemap ? "true" : "false");
printf ("loop count:\t\t%d\n", loop);
printf ("repeat count:\t\t%d\n", repeat);

Expand Down Expand Up @@ -860,8 +922,8 @@ int main (int argc, char *argv[])
for (uint32_t i = 0; i < ins.size (); ++i) {
ins[i]->set_vk_device (vk_dev);
}
XCAM_ASSERT (outs[IdxStitch].ptr ());
outs[IdxStitch]->set_vk_device (vk_dev);
XCAM_ASSERT (outs[out_config.stitch_index].ptr ());
outs[out_config.stitch_index]->set_vk_device (vk_dev);
#else
XCAM_LOG_ERROR ("vulkan module is unsupported");
return -1;
Expand Down Expand Up @@ -899,18 +961,18 @@ int main (int argc, char *argv[])
CHECK (ins[i]->open_reader ("rb"), "open input file(%s) failed", ins[i]->get_file_name ());
}

outs[IdxStitch]->set_buf_size (output_width, output_height);
if (save_output) {
CHECK (outs[IdxStitch]->estimate_file_format (),
"%s: estimate file format failed", outs[IdxStitch]->get_file_name ());
CHECK (outs[IdxStitch]->open_writer ("wb"), "open output file(%s) failed", outs[IdxStitch]->get_file_name ());
outs[out_config.stitch_index]->set_buf_size (output_width, output_height);
if (out_config.save_output) {
CHECK (outs[out_config.stitch_index]->estimate_file_format (),
"%s: estimate file format failed", outs[out_config.stitch_index]->get_file_name ());
CHECK (outs[out_config.stitch_index]->open_writer ("wb"), "open output file(%s) failed", outs[out_config.stitch_index]->get_file_name ());
}

while (repeat--) {

XCAM_LOG_DEBUG ("create stitcher and run test, remain repeat %d times", repeat);

SmartPtr<Stitcher> stitcher = create_stitcher (outs[IdxStitch], module);
SmartPtr<Stitcher> stitcher = create_stitcher (outs[out_config.stitch_index], module);
XCAM_ASSERT (stitcher.ptr ());

stitcher->set_camera_num (fisheye_num);
Expand Down Expand Up @@ -963,19 +1025,35 @@ int main (int argc, char *argv[])
stitcher->set_bowl_config (bowl_config (cam_model));
}

if (save_topview) {
if (out_config.save_topview) {
const uint32_t prev_out_size = outs.size();
add_stream (outs, "topview", topview_width, topview_height);
XCAM_ASSERT (outs.size () >= IdxCount);
XCAM_ASSERT (outs.size() == prev_out_size + 1);

CHECK (outs[IdxTopView]->estimate_file_format (),
"%s: estimate file format failed", outs[IdxTopView]->get_file_name ());
CHECK (outs[IdxTopView]->open_writer ("wb"), "open output file(%s) failed", outs[IdxTopView]->get_file_name ());
out_config.topview_index = outs.size() - 1;

create_topview_mapper (stitcher, outs[IdxStitch], outs[IdxTopView], module);
CHECK (outs[out_config.topview_index]->estimate_file_format (),
"%s: estimate file format failed", outs[out_config.topview_index]->get_file_name ());
CHECK (outs[out_config.topview_index]->open_writer ("wb"), "open output file(%s) failed", outs[out_config.topview_index]->get_file_name ());

create_topview_mapper (stitcher, outs[out_config.stitch_index], outs[out_config.topview_index], module);
}

if (out_config.save_cubemap) {
const uint32_t prev_out_size = outs.size();
add_stream (outs, "cubemap", cubemap_width, cubemap_height);
XCAM_ASSERT (outs.size() == prev_out_size + 1);

out_config.cubemap_index = outs.size() - 1;

CHECK (outs[out_config.cubemap_index]->estimate_file_format (),
"%s: estimate file format failed", outs[out_config.cubemap_index]->get_file_name ());
CHECK (outs[out_config.cubemap_index]->open_writer ("wb"), "open output file(%s) failed", outs[out_config.cubemap_index]->get_file_name ());

create_cubemap_mapper (stitcher, outs[out_config.stitch_index], outs[out_config.cubemap_index], module);
}
CHECK_EXP (
run_stitcher (stitcher, ins, outs, frame_mode, save_output, save_topview, loop) == 0,
run_stitcher (stitcher, ins, outs, frame_mode, out_config, loop) == 0,
"run stitcher failed");
}

Expand Down

0 comments on commit 56a2b85

Please sign in to comment.