Beispiel #1
0
    bool Controller::SpinOnce()
    {

        time_t tstart = time(0);

        ros::spinOnce();

        CompareFeatures();

        time_t duration = time(0) - tstart;
        stringstream ss;
        ss << "[Controller] CompareFeatures took " << duration << " seconds.";
        DebugIO(ss.str());
        tstart = time(0);
        ss.str("");


        this->ap.AnalyzeList();
        robot.SetWeightedPerspective(ap.GetGuess());

        this->PublishData(robotdata, " ");

        duration = time(0) - tstart;
        ss << "[Controller] AnalyzeList took " << duration << " seconds.";
        DebugIO(ss.str());
        tstart = time(0);
        ss.str("");

        ros::spinOnce();
        
        if(!GenDistributionAndSample())
        {
            ErrorIO("[Controller] Failed to generate distribution and sample new particles");
            this->EXIT_FLAG = true;
            return false;
        }

        duration = time(0) - tstart;
        ss << "[Controller] GenDistributionAndSample took " << duration << " seconds.";
        DebugIO(ss.str());
        tstart = time(0);
        ss.str("");

        ros::spinOnce();
        
        if(!MoveUpdate())
        {
            ErrorIO("[Controller] MoveUpdate Failed");
            return false;
        }

        duration = time(0) - tstart;
        ss << "[Controller] MoveUpdate took " << duration << " seconds.";
        DebugIO(ss.str());

        ros::spinOnce();

        UpdateRobotData();
        
        ros::spinOnce();

        return true;
    }
Beispiel #2
0
// находит новоое местоположение объекта на изображении
// pImage
// формат изображения pImage - AWP_DOUBLE, nChannels = 1
// содержание - интегральное изображение, полученное из исходного
void TLFBLOBObject::TrackBLOB(awpImage* pImage)
{
	if (m_pSymptom == NULL)
		return;
	m_new_blob = false;
	// обработка времени. 
	float t = clock() / (float)CLOCKS_PER_SEC;
	m_current_dt = t - m_current_time;
	m_current_time = t;

	float f[NUM_FEATURES];
	memset(f, 0, sizeof(f));
	awpRect r; r = m_bounds;
	int w = m_bounds.right - m_bounds.left; 
	int h = m_bounds.bottom - m_bounds.top;
	int mx;
	int my;
	double mf =10000000000000;
	double d = 10000000000000;
	//m_dL = m_pSymptom->GetBinary()->sSizeX*m_current_dt / c_flMinT;
	m_dL = (float)m_pSymptom->GetSearchDelta()*w/100.f;
	//if (m_current_dt > c_flMinT*w/m_pSymptom->GetBinary()->sSizeX)
	//{
	//	// установить максимальную область наблюдения
	//	m_dL = w / 2;		
	//}
	SetSearchArea(m_dL);
	if (true)
	{
		// объект соприкасается с границей roi	
		TrackOnBorder();
		return;
	}
	else if (false)
	{
		for (int y = m_search_area.top; y < m_search_area.top + 2*m_dL ; y++)
		{
			// проверка принадлежности объекта кадру
			if (y < 0 || y + h >= pImage->sSizeY)
			{
					// объект вышел за пределы кадра по вертикали 
					m_Leave = true;
					return;
			}
			for (int x = m_search_area.left; x < m_search_area.left + 2*m_dL; x++)
			{
				// проверка принадлежности объекта кадру
				if (x < 0 || x + w >= pImage->sSizeX )
				{
					// объект вышел за пределы кадра по горизонтали
					m_Leave = true;
					return;
				}
				r.left = x; 
				r.right = x+w;
				r.top = y;
				r.bottom = y+h;
				CalcFeatures(pImage, r, f);
				d = CompareFeatures(f, m_data);
				if (mf > d)
				{
					mf = d;
					mx = x;
					my = y;
				}
			}
		}
	}

	// анализ наилучшего положения объекта
#ifdef _DEBUG
	printf("obj dist = %f id = %d\n",mf, m_id );
#endif

	if (mf > 50)
	{
		// объект потерян. 
		m_Leave = true;
		return;
	}

	// объект присутствует на сцене
	m_bounds.left = mx;
	if (m_bounds.left < 0)
		m_bounds.left = 0;
	m_bounds.right = mx + w;
	if (m_bounds.right >= pImage->sSizeX)
		m_bounds.right = pImage->sSizeX -1;
	m_bounds.top = my;
	if (m_bounds.top < 0)
		m_bounds.top = 0;
	m_bounds.bottom = my + h;
	if (m_bounds.bottom > pImage->sSizeY -1)
		m_bounds.bottom =  pImage->sSizeY - 1;

	// установка параметров объекта
	UpdateBLOBState();
}