Skip to content
Snippets Groups Projects
main.cpp 2.51 KiB
Newer Older
#include <voltu/voltu.hpp>
#include <voltu/opencv.hpp>
#include <iostream>
#include <thread>
#include <chrono>

Nicolas Pope's avatar
Nicolas Pope committed
#include "../common/cmd_args.hpp"

#include <opencv2/highgui.hpp>

using std::cout;
using std::endl;
using std::string;

int main(int argc, char **argv)
{
Nicolas Pope's avatar
Nicolas Pope committed
	bool do_fusion = true;
	bool do_eval = true;
Nicolas Pope's avatar
Nicolas Pope committed
	int frameno = 0;
	int sourceno = 0;
Nicolas Pope's avatar
Nicolas Pope committed
	voltu::Channel display_channel = voltu::Channel::kColour;
	std::list<std::string> paths;

	auto opts = read_options(&argv, &argc);

	for (const auto &s : opts)
	{
		if (s.first == "--no-fusion")
		{
			do_fusion = false;
		}
		else if (s.first == "--display")
		{
Nicolas Pope's avatar
Nicolas Pope committed
			if (s.second == "\"normals\"")
Nicolas Pope's avatar
Nicolas Pope committed
			{
				display_channel = voltu::Channel::kNormals;
			}
Nicolas Pope's avatar
Nicolas Pope committed
			else if (s.second == "\"depth\"")
			{
				display_channel = voltu::Channel::kDepth;
			}
Nicolas Pope's avatar
Nicolas Pope committed
		}
		else if (s.first == "--no-eval")
		{
			do_eval = false;
		}
Nicolas Pope's avatar
Nicolas Pope committed
		else if (s.first == "--frame")
		{
			frameno = std::stoi(s.second);
		}
		else if (s.first == "--source")
		{
			sourceno = std::stoi(s.second);
		}
Nicolas Pope's avatar
Nicolas Pope committed
		else if (s.first[0] != '-')
		{
			paths.push_back(s.first);
		}
	}

	auto vtu = voltu::instance();

Nicolas Pope's avatar
Nicolas Pope committed
	for (const auto &p : paths)
Nicolas Pope's avatar
Nicolas Pope committed
		if (!vtu->open(p))
		{
			cout << "Could not open source" << endl;
			return -1;
		}
	}

	while (vtu->listRooms().size() == 0)
	{
		std::this_thread::sleep_for(std::chrono::milliseconds(100));
Nicolas Pope's avatar
Nicolas Pope committed
		cout << "Wait room..." << endl;
	}

	auto room = vtu->getRoom(vtu->listRooms().front());
	if (!room)
	{
		cout << "Could not get room" << endl;
		return -1;
	}

Nicolas Pope's avatar
Nicolas Pope committed
	for (int i=0; i<frameno; ++i)
	{
		room->waitNextFrame(5000);
		room->getFrame();
	}
	auto frame = room->getFrame();

	auto pipe = vtu->createPipeline();
	auto op1 = pipe->appendOperator(voltu::OperatorId::kFusion);
	auto op2 = pipe->appendOperator(voltu::OperatorId::kGTEvaluator);

Nicolas Pope's avatar
Nicolas Pope committed
	op1->property("enabled")->setBool(do_fusion);
	op2->property("enabled")->setBool(do_eval);
	op2->property("show_colour")->setBool(true);

	pipe->submit(frame);
Nicolas Pope's avatar
Nicolas Pope committed
	if (!pipe->waitCompletion(3000))
	{
		cout << "Pipeline timeout" << endl;
		return -1;
	}

	auto imgset = frame->getImageSet(display_channel);
Nicolas Pope's avatar
Nicolas Pope committed
	if (imgset.size() == 0)
	{
		cout << "No images!" << endl;
		return -1;
	}
Nicolas Pope's avatar
Nicolas Pope committed
	int srccount = 0;
	for (auto img : imgset)
	{
Nicolas Pope's avatar
Nicolas Pope committed
		if (srccount++ < sourceno) continue;
		cv::Mat m;
		voltu::cv::visualise(img, m);
		cv::imshow(string("Image-") + img->getName(), m);
		break;
	}

Nicolas Pope's avatar
Nicolas Pope committed
	std::vector<std::vector<std::string>> msgs = frame->getMessages();
	if (msgs.size() > 0) {
		for (const auto &s : msgs[0])
		{
			cout << s << endl;
		}
	}

	cv::waitKey(-1);

	return 0;
}