Example #1
0
void        base64_decode(char *s, char *d)
{
   unsigned int t;
                     
   while (*s) {
      t = cind(*s) << 18;
      s++;
      t |= cind(*s) << 12;
      s++;
      t |= cind(*s) << 6;
      s++;
      t |= cind(*s) << 0;
      s++;
      
      *(d + 2) = (char) (t & 0xFF);
      t >>= 8;
      *(d + 1) = (char) (t & 0xFF);
      t >>= 8;
      *d = (char) (t & 0xFF);
      
      d += 3;
   }
   *d = 0;
}
Example #2
0
cv::Mat_<int> cModel::__lbf_fast(const cv::Mat_<uchar>&img, const cv::Rect& bbox, const cv::Mat_<float>& shape,int markID, int stage)
{
	int max_stage = m_Model.__head.__num_stage;
	int num_node = m_Model.__head.__num_leaf + m_Model.__head.__num_node;
	int num_point = m_Model.__head.__num_point;
	int num_tree_per_point = m_Model.__head.__num_tree_per_point;
	int num_leaf = m_Model.__head.__num_leaf;
	
	m_AX[stage].row(markID) *= bbox.width;
	m_AY[stage].row(markID) *= bbox.height;
	m_BX[stage].row(markID) *= bbox.width;
	m_BY[stage].row(markID) *= bbox.height;	

	m_AX[stage].row(markID) += shape(markID, 0);
	m_AY[stage].row(markID) += shape(markID, 1);
	m_BX[stage].row(markID) += shape(markID, 0);
	m_BY[stage].row(markID) += shape(markID, 1);

	cv::Mat_<int> cind = cv::Mat::ones(m_AX[stage].cols, 1, CV_32SC1);
	cv::Mat_<float> AX = m_AX[stage].row(markID);
	cv::Mat_<float> AY = m_AY[stage].row(markID);
	cv::Mat_<float> BX = m_BX[stage].row(markID);
	cv::Mat_<float> BY = m_BY[stage].row(markID);
	cv::Mat_<float> Thresh = m_Thresh[stage].row(markID);	
	

	int width =  img.cols;
	int height = img.rows;	
	
	for (int j = 0; j < AX.cols; j += num_node){
		for (int index = 0; index < m_Model.__head.__num_node; index++){
			int pos = j + index;
			int a_x = (int)(AX(0, pos) + 0.5);
			int a_y = (int)(AY(0, pos) + 0.5);
			int b_x = (int)(BX(0, pos) + 0.5);
			int b_y = (int)(BY(0, pos) + 0.5);

			a_x = MAX(0, MIN(a_x, width - 1));
			a_y = MAX(0, MIN(a_y, height - 1));
			b_x = MAX(0, MIN(b_x, width - 1));
			b_y = MAX(0, MIN(b_y, height - 1));

			float pixel_v_a = (float)img(cv::Point(a_x, a_y));
			float pixel_v_b = (float)img(cv::Point(b_x, b_y));
			float val = pixel_v_a - pixel_v_b;
			
			if (val < (float)Thresh(0, pos)){
				cind(pos, 0) = 0;
			}
		}		
	}

	cv::Mat_<int> binfeature = cv::Mat::zeros(1, (int)cv::sum(m_Isleaf).val[0], CV_32SC1);

	int cumnum_nodes = 0;
	int cumnum_leafnodes = 0;

	for (int t = 0; t < num_tree_per_point; t++){		
		int id_cnode = 0;
		while (1){
			if (m_Isleaf(id_cnode + cumnum_nodes)){
				binfeature(0, cumnum_leafnodes + __getindex(m_Idleafnodes, id_cnode)) = 1;
				cumnum_nodes = cumnum_nodes + num_node;
				cumnum_leafnodes = cumnum_leafnodes + num_leaf;
				break;
			}
			id_cnode = m_Cnodes(cumnum_nodes + id_cnode, cind(cumnum_nodes + id_cnode, 0));
		}
	}
	return binfeature;	
}
Example #3
0
//compute bag affiliation for all vertices
//store result in m_bagindex
void ClusterAnalysis::computeBags() {
	const Graph &G = m_C->constGraph();

	// Storage structure for results
	m_bagindex.init(G);
	// We use Union-Find for chunks and bags
	DisjointSets<> uf;
	NodeArray<int> setid(G); // Index mapping for union-find
#if 0
	node* nn = new node[G.numberOfNodes()]; // dito
#endif

	// Every cluster gets its index
	ClusterArray<int> cind(*m_C);
	// We store the lists of cluster vertices
	List<node>* clists = new List<node>[m_C->numberOfClusters()];
	int i = 0;

	// Store index and detect the current leaf clusters
	List<cluster> ccleafs;
	ClusterArray<int> unprocessedChildren(*m_C); //processing below: compute bags
	for(cluster c : m_C->clusters)
	{
		cind[c] = i++;
		if (c->cCount() == 0) ccleafs.pushBack(c);
		unprocessedChildren[c] = c->cCount();
	}


	// Now we run through all vertices, storing them in the parent lists,
	// at the same time, we initialize m_bagindex
	for(node v : G.nodes)
	{
		// setid is constant in the following
		setid[v] = uf.makeSet();
		// Each vertex v gets its own ClusterArray that stores v's bag index per cluster.
		// See comment on use of ClusterArrays above
		m_bagindex[v] = new ClusterArray<int>(*m_C,DefaultIndex, m_C->maxClusterIndex()+1);//m_C->numberOfClusters());
		cluster c = m_C->clusterOf(v);
		// Push vertices in parent list
		clists[cind[c]].pushBack(v);
	}

	// Now each clist contains the direct vertex descendants
	// We process the clusters bottom-up, compute the chunks
	// of the leafs first. At each level, for a cluster the
	// vertex lists of all children are concatenated
	// (could improve this by having an array of size(#leafs)
	// and concatenating only at child1), then the bags are
	// updated as follows: chunks may be linked by exactly
	// the edges with lca(c) ie the ones in m_lcaEdges[c],
	// and bags may be built by direct child clusters that join chunks.
	// While concatenating the vertex lists, we can check
	// for the vertices in each child if the uf number is the same
	// as the one of a first initial vertex, otherwise we join.

	// First, lowest level clusters are processed: All chunks are bags


	OGDF_ASSERT(!ccleafs.empty());

	while (!ccleafs.empty()){
		const cluster c = ccleafs.popFrontRet();
		Skiplist<int*> cbags; //Stores bag indexes ocurring in c

		auto storeResult = [&] {
			for (node v : clists[cind[c]]) {
				int theid = uf.find(setid[v]);
				(*m_bagindex[v])[c] = theid;
				if (!cbags.isElement(&theid)) {
					cbags.add(new int(theid));
				}
				// push into list of outer active vertices
				if (m_storeoalists && isOuterActive(v, c)) {
					(*m_oalists)[c].pushBack(v);
				}
			}
			(*m_bags)[c] = cbags.size(); // store number of bags of c
		};

		if (m_storeoalists){
			//no outeractive vertices detected so far
			(*m_oalists)[c].clear();
		}

		//process leafs separately
		if (c->cCount() == 0) {


			//Todo could use lcaEdges list here too, see below
			for (node u : c->nodes)
			{
				for(adjEntry adj : u->adjEntries) {
					node w = adj->twinNode();
					if (m_C->clusterOf(w) == c)
					{
						uf.link(uf.find(setid[u]),uf.find(setid[w]));
					}
				}
			}
			// Now all chunks in the leaf cluster are computed
			// update for parent is done in the else case

			storeResult();
		}
		else {
			// ?We construct the vertex list by concatenating
			// ?the lists of the children to the current list.
			// We need the lists for storing the results efficiently.
			// (Should be slightly faster than to call clusterNodes each time)
			// Bags are either links of chunks by edges with lca==c
			// or links of chunk by child clusters.
			// Edge links
			for(edge e : (*m_lcaEdges)[c]) {
				uf.link(uf.find(setid[e->source()]),uf.find(setid[e->target()]));
			}

			// Cluster links
			for(cluster cc : c->children)
			{
				//Initial id per child cluster cc: Use value of first
				//vertex, each time we encounter a different value in cc,
				//we link the chunks

				//add (*itcc)'s vertices to c's list
				ListConstIterator<node> itvc = clists[cind[cc]].begin();
				int inid;
				if (itvc.valid()) inid = uf.find(setid[*itvc]);
				while (itvc.valid())
				{
					int theid = uf.find(setid[*itvc]);

					if (theid != inid)
						uf.link(inid,theid);
					clists[cind[c]].pushBack(*itvc);
					++itvc;
				}
			}

			storeResult();
		}
		// Now we update the status of the parent cluster and,
		// in case all its children are processed, add it to
		// the process queue.
		if (c != m_C->rootCluster())
		{
			OGDF_ASSERT(unprocessedChildren[c->parent()] > 0);
			unprocessedChildren[c->parent()]--;
			if (unprocessedChildren[c->parent()] == 0) ccleafs.pushBack(c->parent());
		}
	}

	// clean up
	delete[] clists;
}