Exemplo n.º 1
0
//===========================================================================
///	GetSaliencyMap
///
/// Outputs a saliency map with a value assigned per pixel. The values are
/// normalized in the interval [0,255] if normflag is set true (default value).
//===========================================================================
void Saliency::GetSaliencyMap(
	const vector<UINT>&				inputimg,
	const int&						width,
	const int&						height,
	vector<double>&					salmap,
	const bool&						normflag) 
{
	int sz = width*height;
	salmap.clear();
	salmap.resize(sz);

	vector<double> lvec(0), avec(0), bvec(0);
	RGB2LAB(inputimg, lvec, avec, bvec);
	//--------------------------
	// Obtain Lab average values
	//--------------------------
	double avgl(0), avga(0), avgb(0);
	{for( int i = 0; i < sz; i++ )
	{
		avgl += lvec[i];
		avga += avec[i];
		avgb += bvec[i];
	}}
	avgl /= sz;
	avga /= sz;
	avgb /= sz;

	vector<double> slvec(0), savec(0), sbvec(0);

	//----------------------------------------------------
	// The kernel can be [1 2 1] or [1 4 6 4 1] as needed.
	// The code below show usage of [1 2 1] kernel.
	//----------------------------------------------------
	vector<double> kernel(0);
	kernel.push_back(1.0);
	kernel.push_back(2.0);
	kernel.push_back(1.0);

	GaussianSmooth(lvec, width, height, kernel, slvec);
	GaussianSmooth(avec, width, height, kernel, savec);
	GaussianSmooth(bvec, width, height, kernel, sbvec);

	{for( int i = 0; i < sz; i++ )
	{
		salmap[i] = (slvec[i]-avgl)*(slvec[i]-avgl) +
					(savec[i]-avga)*(savec[i]-avga) +
					(sbvec[i]-avgb)*(sbvec[i]-avgb);
	}}

	if( true == normflag )
	{
		vector<double> normalized(0);
		Normalize(salmap, width, height, normalized);
		swap(salmap, normalized);
	}
}
Exemplo n.º 2
0
TEST_F(SHAPE, Init)
{
	ade::Shape scalar;

	std::vector<ade::DimT> slist = {12, 43, 56};
	ade::Shape vec(slist);
	uint8_t n = slist.size();

	std::vector<ade::DimT> longlist = {4, 23, 44, 52, 19, 92, 12, 2, 5};
	ade::Shape lvec(longlist);

	std::vector<ade::DimT> zerolist = {43, 2, 5, 33, 0, 2, 7};
	std::string fatalmsg = "cannot create shape with vector containing zero: " +
		fmts::to_string(zerolist.begin(), zerolist.end());
	EXPECT_FATAL(ade::Shape junk(zerolist), fatalmsg.c_str());

	for (uint8_t i = 0; i < ade::rank_cap; ++i)
	{
		EXPECT_EQ(1, scalar.at(i));
	}

	for (uint8_t i = 0; i < n; ++i)
	{
		EXPECT_EQ(slist[i], vec.at(i));
	}
	for (uint8_t i = n; i < ade::rank_cap; ++i)
	{
		EXPECT_EQ(1, vec.at(i));
	}

	for (uint8_t i = 0; i < ade::rank_cap; ++i)
	{
		EXPECT_EQ(longlist[i], lvec.at(i));
	}

	EXPECT_FATAL(scalar.at(ade::rank_cap), "cannot access out of bounds index 8");
	EXPECT_FATAL(vec.at(ade::rank_cap), "cannot access out of bounds index 8");
}
Exemplo n.º 3
0
/***********************************************************
check trigger on object action
***********************************************************/
void NPCHandler::PlayerAction(Ice::Long PlayerId, const LbaNet::PlayerPosition &info,
									const std::string &ObjectMode)
{
	if(!_agentState->CanTalk())
		return;

	if(ObjectMode != "Normal")
		return;

	boost::shared_ptr<PhysicalObjectHandlerBase> physO = _character->GetPhysicalObject();
	if(!physO)
		return;

	if(std::find(_targetedplayers.begin(), _targetedplayers.end(), PlayerId) != _targetedplayers.end())
		return;

	if(_rootdialog->GetChilds().size() == 0)
		return;

	float posX, posY, posZ;
	physO->GetPosition(posX, posY, posZ);

	float diffX = (info.X - posX);
	float diffY = (info.Y - posY);
	float diffZ = (info.Z - posZ);

	float distance = (diffX*diffX) + (diffY*diffY) + (diffZ*diffZ);
	if(distance <= 9)
	{
		LbaVec3 lvec(-diffX, -diffY, -diffZ);
		float angle = LbaQuaternion::GetAngleFromVector(lvec);
		float angle1a = (angle - 50);
		float angle1b = (angle - 50);

		float angle2a = (angle + 50);
		float angle2b = (angle + 50);



		if(angle1a < 0)
		{
			angle1a += 360;
			angle2a += 360;
			angle1b = 0;		
		}

		if(angle2b > 360)
		{
			angle1b -= 360;
			angle2b -= 360;
			angle2a = 360;
		}

		if(	((info.Rotation > angle1a) && (info.Rotation < angle2a)) ||
			((info.Rotation > angle1b) && (info.Rotation < angle2b)) )
		{
			// start dialog
			if(m_scripthandler)
				m_scripthandler->StartDialog((long)PlayerId, m_actorinfo.ObjectId, 
										_npcnametextid, _simpledialog, _rootdialog);

			// target player
			_targetedplayers.push_back(PlayerId);
			if(_targetedplayers.size() == 1)
				TargetPlayer(PlayerId);
		}
	}
}
Exemplo n.º 4
0
inline
void
op_unique::apply(Mat<typename T1::elem_type>& out, const Op<T1, op_unique>& X)
  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const Proxy<T1> P(X.m);
  
  const uword in_n_rows = P.get_n_rows();
  const uword in_n_cols = P.get_n_cols();
  const uword in_n_elem = P.get_n_elem();
  
  
  if(in_n_elem <= 1)
    {
    if(in_n_elem == 1)
      {
      const eT tmp = P[0];
      
      out.set_size(in_n_rows, in_n_cols);
      
      out[0] = tmp;
      }
    else
      {
      out.set_size(in_n_rows, in_n_cols);
      }
    
    return;
    }
  
  
  std::vector<eT> lvec(in_n_elem);
  
  
  if(Proxy<T1>::prefer_at_accessor == false)
    {
    typename Proxy<T1>::ea_type Pea = P.get_ea();
    
    uword i,j;
    for(i=0, j=1; j < in_n_elem; i+=2, j+=2)
      {
      const eT tmp_i = Pea[i];
      const eT tmp_j = Pea[j];
      
      lvec[i] = tmp_i;
      lvec[j] = tmp_j;
      }
    
    if(i < in_n_elem)
      {
      lvec[i] = Pea[i];
      }
    }
  else
    {
    uword i = 0;
    
    for(uword col=0; col < in_n_cols; ++col)
    for(uword row=0; row < in_n_rows; ++row, ++i)
      {
      lvec[i] = P.at(row,col);
      }
    }
  
  std::sort( lvec.begin(), lvec.end() );
  
  uword N_unique = 1;
  
  for(uword i=1; i < in_n_elem; ++i)
    {
    const eT a = lvec[i-1];
    const eT b = lvec[i  ];
    
    const eT diff = a - b;
    
    if(diff != eT(0)) { ++N_unique; }
    }
  
  uword out_n_rows;
  uword out_n_cols;
  
  if( (in_n_rows == 1) || (in_n_cols == 1) )
    {
    if(in_n_rows == 1)
      {
      out_n_rows = 1;
      out_n_cols = N_unique;
      }
    else
      {
      out_n_rows = N_unique;
      out_n_cols = 1;
      }
    }
  else
    {
    out_n_rows = N_unique;
    out_n_cols = 1;
    }
  
  // we don't need to worry about aliasing at this stage, as all the data is stored in lvec
  out.set_size(out_n_rows, out_n_cols);
  
  eT* out_mem = out.memptr();
  
  if(in_n_elem > 0) { out_mem[0] = lvec[0]; }
  
  N_unique = 1;
  
  for(uword i=1; i < in_n_elem; ++i)
    {
    const eT a = lvec[i-1];
    const eT b = lvec[i  ];
    
    const eT diff = a - b;
    
    if(diff != eT(0))
      {
      out_mem[N_unique] = b;
      ++N_unique;
      }
    }
  
  }