c_cpp dlib图样本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp dlib图样本相关的知识,希望对你有一定的参考价值。

#include "pch.h"
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <dlib/graph_cuts.h>
#include <dlib/graph_utils.h>
#include <dlib/directed_graph.h>
#include <dlib/graph.h>
#include <dlib/rand.h>
#include <dlib/matrix/matrix.h>


using namespace std;
using namespace dlib;


int main(void)
{
	graph<double, double>::kernel_1a_c g;
	
	g.set_number_of_nodes(4);
	
	g.add_edge(0, 1);
	g.add_edge(1, 2);
	g.add_edge(2, 3);
	g.add_edge(3, 0);

	g.node(0).data = std::numeric_limits<double>::infinity();
	g.node(1).data = -std::numeric_limits<double>::infinity();
	g.node(2).data = std::numeric_limits<double>::infinity();
	g.node(3).data = -std::numeric_limits<double>::infinity();

	// set the 1-D vector for the edge between node 0 and 1 to the value of 1.
	// ...and all of them
	edge(g, 0, 1) = 1;
	edge(g, 1, 2) = 1;
	edge(g, 2, 3) = 1;
	edge(g, 3, 0) = 1;

	std::vector<node_label> labels;
	find_max_factor_graph_potts(g, labels);

	// ------------------------------------------------ //
	// define our own graph.
	// there will be 2-D vectors at each node 
	// there will be 1-D vectors at each edge. 
	// ----------------------------------------------- //
	//	4 nodes and with the structure shown below :
	// (0)---- - (1)
	//	 |       |
	//	 |       |
	//	 |       |
	// (3)---- - (2)
	typedef matrix<double, 2, 1> node_vector_type;
	typedef matrix<double, 1, 1> edge_vector_type;
	typedef graph<node_vector_type, edge_vector_type>::kernel_1a graph_type;
	graph_type my_graph;

	my_graph.set_number_of_nodes(4);
	my_graph.node(0).data = { 0, 1 };
	my_graph.node(1).data = { 0, 0 };
	my_graph.node(2).data = { 1, 0 };
	my_graph.node(3).data = { 0, 0 };

	my_graph.add_edge(0, 1);
	my_graph.add_edge(1, 2);
	my_graph.add_edge(2, 3);
	my_graph.add_edge(3, 0);

	edge(my_graph, 0, 1) = 1;
	edge(my_graph, 1, 2) = 0;
	edge(my_graph, 2, 3) = 1;
	edge(my_graph, 3, 0) = 0;

	return 0;
}

以上是关于c_cpp dlib图样本的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp dlib矩阵运算

c_cpp 转换为dlib垫

c_cpp dlib_LearnSVM

c_cpp dlib_utils

c_cpp dlib min_cut

c_cpp mat to dlib to eigen