Example #1
0
TEST(ALPose2DTest, getAngle)
{
  const float eps = 1e-4f;
  AL::Math::Pose2D pos1(1.5f, 0.0f, 0.0f);
  EXPECT_NEAR(pos1.getAngle(), 0.0f, eps);

  AL::Math::Pose2D pos2(1.5f, 0.0f, 2.0f);
  EXPECT_NEAR(pos2.getAngle(), 0.0f, eps);

  AL::Math::Pose2D pos3(1.0f, -1.0f, 2.0f);
  EXPECT_NEAR(pos3.getAngle(), -AL::Math::PI_4, eps);

  AL::Math::Pose2D pos4(0.0f, 1.0f, 1.0f);
  EXPECT_NEAR(pos4.getAngle(), AL::Math::PI_2, eps);

  AL::Math::Pose2D pos5(-2.0f, 1.0f, 2.0f);
  EXPECT_NEAR(pos5.getAngle(), 2.67792f, eps);
}
void EntryExitEvaluator::process(FrameList &frames)
{
    frameCount++;
    if (frameCount > numberOfFrames) {
        return;
    }

    std::vector<inOutEvent> inOut;
    for (std::vector<CameraObject>::size_type i = 0; i < frames.getCurrent().getCameras().size(); i++) {
        inOutEvent temp;
        temp.in = 0;
        temp.out = 0;
        inOut.push_back(temp);
    }

    // Save the values for entry and exit
    for (std::vector<CameraObject>::size_type i = 0; i < frames.getCurrent().getCameras().size(); i++) {
        // getEntered/getExited is the sum of all entrys and exits.
        inOut[i].in = frames.getCurrent().getCameras()[i].getEntered() - prevEntered[i];
        inOut[i].out = frames.getCurrent().getCameras()[i].getExited() - prevExited[i];

        // Save current values for next iteration
        prevEntered[i] = frames.getCurrent().getCameras()[i].getEntered();
        prevExited[i] = frames.getCurrent().getCameras()[i].getExited();



        // Sum ground truth enties and exits
        sumEntryGT[i] = sumEntryGT[i] + groundTruth[i][frameCount].in;
        sumExitGT[i] = sumExitGT[i] + groundTruth[i][frameCount].out;

        //---------- Save data -----------
        if(save == 10) {
        saveAccuracyToFile(prevEntered[i], "/Users/erikfall/Desktop/entMeas.csv");
        saveAccuracyToFile(prevExited[i], "/Users/erikfall/Desktop/exiMeas.csv");

        saveAccuracyToFile(sumEntryGT[i], "/Users/erikfall/Desktop/entryGT.csv");
        saveAccuracyToFile(sumExitGT[i], "/Users/erikfall/Desktop/exitGT.csv");
        //--------------------------------
        }


        //Accuracy computation
        if(sumEntryGT[i] != 0 && sumExitGT[i] != 0){
            accuracyTot = 1 - float(std::abs(frames.getCurrent().getCameras()[i].getEntered()-
                                             frames.getCurrent().getCameras()[i].getExited()-
                                             (sumEntryGT[i]-sumExitGT[i])))/(sumEntryGT[i]+sumExitGT[i]);
            accuracyIn  = 1 - float(std::abs(frames.getCurrent().getCameras()[i].getEntered()-sumEntryGT[i])) / sumEntryGT[i];
            accuracyOut = 1 - float(std::abs(frames.getCurrent().getCameras()[i].getExited()-sumExitGT[i])) / sumExitGT[i];

            diffEntries[i]       = sumEntryGT[i] - frames.getCurrent().getCameras()[i].getEntered();
            diffExits[i]         = sumExitGT[i] - frames.getCurrent().getCameras()[i].getExited();
            diffTotalOfPeople[i] = (sumEntryGT[i] - sumExitGT[i])-
                    (frames.getCurrent().getCameras()[i].getEntered() - frames.getCurrent().getCameras()[i].getExited());


            // Debug, print entry and exit information on the image.
            if(frames.getCurrent().getCameras()[i].hasImage("debugImage"))
            {
                cv::Mat debugIm = frames.getCurrent().getCameras()[i].getImage("debugImage");
                std::string accIn = "";
                std::string accOut = "";
                std::string accTotDiff = "";
                std::string GTIn = "";
                std::string GTOut = "";
                std::string GTTotal = "";

                int fontFace     = cv::FONT_HERSHEY_PLAIN;
                double fontScale = 1;
                int thickness    = 1;

                cv::Point2d pos1(430,15);
                cv::Point2d pos2(430,35);
                cv::Point2d pos3(430,55);
                cv::Point2d pos4(140,20);
                cv::Point2d pos5(140,40);
                cv::Point2d pos6(140,60);

                accIn      = "Accuracy In:      " + std::to_string(int(round(accuracyIn*100))) + " %";
                accOut     = "Accuracy Out:     " + std::to_string(int(round(accuracyOut*100))) + " %";
                accTotDiff = "Accuracy TotDiff: " + std::to_string(int(round(accuracyTot*100))) + " %";
                GTIn       = "(" + std::to_string(sumEntryGT[i]) + ")";
                GTOut      = "(" + std::to_string(sumExitGT[i]) + ")";
                GTTotal    = "(" + std::to_string(sumEntryGT[i] - sumExitGT[i]) + ")";

                putText(debugIm, accIn,      pos1, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
                putText(debugIm, accOut,     pos2, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
                putText(debugIm, accTotDiff, pos3, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
                putText(debugIm, GTIn,       pos4, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
                putText(debugIm, GTOut,      pos5, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
                putText(debugIm, GTTotal,    pos6, fontFace, fontScale, cv::Scalar(0,255,0), thickness, 8);
            }
        }

        if(save == 10) {
        saveAccuracyToFile(accuracyIn, "/Users/erikfall/Desktop/accuracyIn.csv");
        saveAccuracyToFile(accuracyOut, "/Users/erikfall/Desktop/accuracyOut.csv");
        saveAccuracyToFile(accuracyTot, "/Users/erikfall/Desktop/accuracyTot.csv");
        }
        if(save == 10) {
            save = 0;
        }
        ++ save;

    }
}
Example #3
0
void Result::showResultLose(int score){
	int left = -320;
	int right = 320;
	int top = 240;
	int bot = -240;
	char strbuffer[64];
	// L
	Point pol1(left+60,top-80);
	Point pol2(left+60,bot+220);
	Point pol3(left+180,bot+220);
	Point pol4(left+180,bot+270);
	Point pol5(left+110,bot+270);
	Point pol6(left+110,top-80);
	Point polc((pol1.x+pol3.x)/2,(pol1.y+pol3.y)/2);
	vector<Point> pol;
	pol.push_back(pol1);
	pol.push_back(pol2);
	pol.push_back(pol3);
	pol.push_back(pol4);
	pol.push_back(pol5);
	pol.push_back(pol6);
	if (firsttime){
		pol_l.setCorner(pol);
		pol_l.setCenter(polc);
		Transform scale = createScale(0.1, 0.1);
		pol_l.applyTransform(scale);
	}

	// O
	Point poo1(left+190,top-80);
	Point poo2(left+190,bot+220);
	Point poo3(left+310,bot+220);
	Point poo4(left+310,top-80);
	Point poo5(left+230,top-120);
	Point poo6(left+230,bot+260);
	Point poo7(left+270,bot+260);
	Point poo8(left+270,top-120);
	Point pooc((poo1.x+poo3.x)/2,(poo1.y+poo3.y)/2);
	vector<Point> poo, poov;
	poo.push_back(poo1);
	poo.push_back(poo2);
	poo.push_back(poo3);
	poo.push_back(poo4);
	poov.push_back(poo5);
	poov.push_back(poo6);
	poov.push_back(poo7);
	poov.push_back(poo8);
	if (firsttime){
		pol_o.setCorner(poo);
		pol_o.setCenter(pooc);
		pol_o1.setCorner(poov);
		pol_o1.setCenter(pooc);
		Transform scale = createScale(0.1, 0.1);
		pol_o.applyTransform(scale);
		pol_o1.applyTransform(scale);
	}
	// S
	Point pos1(left+320,top-80);
	Point pos2(left+320,top-190);
	Point pos3(left+410,top-190);
	Point pos4(left+410,top-220);
	Point pos5(left+320,top-220);
	Point pos6(left+320,top-260);
	Point pos7(left+450,top-260);
	Point pos8(left+450,top-150);
	Point pos9(left+360,top-150);
	Point pos10(left+360,top-120);
	Point pos11(left+450,top-120);
	Point pos12(left+450,top-80);
	Point posc((pos1.x+pos7.x)/2,(pos1.y+pos7.y)/2);
	vector<Point> pos;
	pos.push_back(pos1);
	pos.push_back(pos2);
	pos.push_back(pos3);
	pos.push_back(pos4);
	pos.push_back(pos5);
	pos.push_back(pos6);
	pos.push_back(pos7);
	pos.push_back(pos8);
	pos.push_back(pos9);
	pos.push_back(pos10);
	pos.push_back(pos11);
	pos.push_back(pos12);
	if (firsttime){
		pol_s.setCorner(pos);
		pol_s.setCenter(posc);
		Transform scale = createScale(0.1, 0.1);
		pol_s.applyTransform(scale);
	}
	

	// E
	Point poe1(left+460,top-80);
	Point poe2(left+460,bot+220);
	Point poe3(left+580,bot+220);
	Point poe4(left+580,bot+260);
	Point poe5(left+510,bot+260);
	Point poe6(left+510,bot+290);

	Point poe7(left+580,bot+220+70);
	Point poe8(left+580,bot+260+70);
	Point poe9(left+510,bot+260+70);
	Point poe10(left+510,bot+290+70);

	Point poe11(left+580,bot+220+140);
	Point poe12(left+580,bot+260+140);
	Point poec((poe1.x+poe3.x)/2,(poe1.y+poe3.y)/2);
	vector<Point> poe;
	poe.push_back(poe1);
	poe.push_back(poe2);
	poe.push_back(poe3);
	poe.push_back(poe4);
	poe.push_back(poe5);
	poe.push_back(poe6);
	poe.push_back(poe7);
	poe.push_back(poe8);
	poe.push_back(poe9);
	poe.push_back(poe10);
	poe.push_back(poe11);
	poe.push_back(poe12);
	if (firsttime){
		pol_e.setCorner(poe);
		pol_e.setCenter(poec);
		Transform scale = createScale(0.1, 0.1);
		pol_e.applyTransform(scale);
	}

	

	// Other
	Point pot1(left+60, top-40);
	Point pot2(right-60, top-40);
	Point pot3(right-60, top-60);
	Point pot4(left+60, top-60);
	Point potc((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2);
	vector<Point> pot;
	pot.push_back(pot1);
	pot.push_back(pot2);
	pot.push_back(pot3);
	pot.push_back(pot4);
	if (firsttime){
		pol_pot1.setCorner(pot);
		pol_pot1.setCenter(potc);
		Transform scale = createScale(0.1, 0.1);
		pol_pot1.applyTransform(scale);
	}
	

	pot1.set(left+60, bot+180);
	pot2.set(right-60, bot+180);
	pot3.set(right-60, bot+200);
	pot4.set(left+60, bot+200);
	potc.set((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2);
	pot.clear();
	pot.push_back(pot1);
	pot.push_back(pot2);
	pot.push_back(pot3);
	pot.push_back(pot4);
	if (firsttime){
		pol_pot2.setCorner(pot);
		pol_pot2.setCenter(potc);
		Transform scale = createScale(0.1, 0.1);
		pol_pot2.applyTransform(scale);
	}
	

	resultframe++;
	if (resultframe >= 25)
		resultframe = 25;
	else {
		Transform scale = createScale(1.1, 1.1);
		pol_pot1.applyTransform(scale);
		pol_pot2.applyTransform(scale);
		pol_l.applyTransform(scale);
		pol_o.applyTransform(scale);
		pol_o1.applyTransform(scale);
		pol_s.applyTransform(scale);
		pol_e.applyTransform(scale);
	}
	pol_l.draw(WHITE);
	fill_polygon(pol_l[0].x, pol_l[2].y, pol_l[2].x, pol_l[0].y,WHITE,WHITE);
	pol_o.draw(WHITE);
	fill_polygon(pol_o[0].x, pol_o[2].y, pol_o[2].x, pol_o[0].y,WHITE,WHITE);
	pol_o1.draw(BLACK);
	fill_polygon(pol_o1[0].x, pol_o1[2].y, pol_o1[2].x, pol_o1[0].y,BLACK,BLACK);	
	pol_s.draw(WHITE);
	fill_polygon(pol_s[0].x, pol_s[6].y, pol_s[6].x, pol_s[0].y,WHITE,WHITE);
	pol_e.draw(WHITE);
	fill_polygon(pol_e[0].x, pol_e[2].y, pol_e[2].x, pol_e[0].y,WHITE,WHITE);
	pol_pot1.draw(WHITE);
	pol_pot2.draw(WHITE);

	settextstyle(7,0,40);
	setcolor(WHITE);
	sprintf(strbuffer,"%d",score);
	outtextxy(getmaxx()/2-50, getmaxy()/2+100, strbuffer);
	firsttime = false;
}
Example #4
0
// An Update() helper that draws the image.
void GameWindow::Draw()
{
    //make sure the Direct3D device is valid
    if (!m_d3ddev) return;

    //create pointer to the back buffer
    m_d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &m_Backbuffer);
	//if in game
	if(m_bInGame){
		//load sprite textures
		m_wPlayer.m_Texture = Load_Texture(m_wPlayer.m_Image);
		for(int i = 0; i < 7; i++){
			if(m_eAllEnemies[i].m_bOnScreen){
				m_eAllEnemies[i].m_Texture = Load_Texture(m_eAllEnemies[i].m_Image);
				m_eAllEnemies[i].m_HPTexture = Load_Texture(m_eAllEnemies[i].m_HPimg);
			}
		}
		for(int i = 0; i < 7; i++){
			if(m_pProjectileList[i].m_bOnScreen){
				m_pProjectileList[i].m_Texture = Load_Texture(m_pProjectileList[i].m_Image);
			}
		}
	}
    //start rendering
    if (m_d3ddev->BeginScene())
    {
		
        //draw m_Surface to the m_Backbuffer
		m_d3ddev->StretchRect(m_Surface, NULL, m_Backbuffer, NULL, D3DTEXF_NONE);
		//begin drawing sprites
		m_Sprite->Begin(D3DXSPRITE_ALPHABLEND);
		//if in game
		if(m_bInGame){
			
			//Turn x and y into a vector. Eventually I will set all coordinates to be vectors
			D3DXVECTOR3 pos1(m_wPlayer.m_X, m_wPlayer.m_Y, 0);
			
			//draw player
			m_Sprite->Draw(m_wPlayer.m_Texture, NULL, NULL, &pos1, D3DCOLOR_XRGB(255,255,255));
			
			//draw player's spell icon
			m_wPlayer.m_Texture = Load_Texture(m_wPlayer.m_SpellImage);
			D3DXVECTOR3 spellpos(m_wPlayer.m_X+0.25f*m_wPlayer.m_Width, m_wPlayer.m_Y-48, 0);
			m_Sprite->Draw(m_wPlayer.m_Texture, NULL, NULL, &spellpos, D3DCOLOR_XRGB(255,255,255));
			
			//draw all enemies
			for(int i = 0; i < 7; i++){
				if(m_eAllEnemies[i].m_bOnScreen){
					D3DXVECTOR3 pos2(m_eAllEnemies[i].m_X, m_eAllEnemies[i].m_Y, 0);
					m_Sprite->Draw(m_eAllEnemies[i].m_Texture, NULL, NULL, &pos2, D3DCOLOR_XRGB(255,255,255));
					//draw hp icons
					D3DXVECTOR3 pos4(m_eAllEnemies[i].m_X, m_eAllEnemies[i].m_Y- 32, 0);
					m_Sprite->Draw(m_eAllEnemies[i].m_HPTexture, NULL, NULL, &pos4, D3DCOLOR_XRGB(255,255,255));
				}
			}
			
			//draw projectile spells 
			for(int i = 0; i < 10; i++){
				if(m_pProjectileList[i].m_bOnScreen){
					D3DXVECTOR3 pos3(m_pProjectileList[i].m_X, m_pProjectileList[i].m_Y, 0);
					m_Sprite->Draw(m_pProjectileList[i].m_Texture, NULL, NULL, &pos3, D3DCOLOR_XRGB(255,255,255));
				}
			}

			//draw powerups
			D3DXVECTOR3 pos5(m_pPowerup.m_X, m_pPowerup.m_Y, 0);
			m_Sprite->Draw(m_pPowerup.m_Texture, NULL, NULL, &pos5, D3DCOLOR_XRGB(255, 255, 255));
			//draw hp ui
			D3DXVECTOR3 HpPos(16, 684, 0);
			m_Sprite->Draw(m_HpTexture, NULL, NULL, &HpPos, D3DCOLOR_XRGB(255,255,255));
			if(m_wPlayer.m_Health > 1){
				D3DXVECTOR3 HpPos(48, 684, 0);
				m_Sprite->Draw(m_HpTexture, NULL, NULL, &HpPos, D3DCOLOR_XRGB(255,255,255));
			}
			if(m_wPlayer.m_Health > 2){
				D3DXVECTOR3 HpPos(80, 684, 0);
				m_Sprite->Draw(m_HpTexture, NULL, NULL, &HpPos, D3DCOLOR_XRGB(255,255,255));
			}
		}
		else{
			//write title
			m_Font->DrawTextA(NULL, "Snape Simulator 2012", -1, &m_rTitle, DT_RIGHT, D3DCOLOR_XRGB(0, 0, 70));
			//draw "press space to start" in center of screen
			D3DXVECTOR3 StartPos(356, 256, 0);
			m_Sprite->Draw(m_StartGameTexture, NULL, NULL, &StartPos, D3DCOLOR_XRGB(255, 255, 255));
		}
		//UI- draw scores
		std::stringstream ss;//create a stringstream
		ss << m_Score;//add number to the stream
		std::string j = ss.str();
		m_Font->DrawTextA(NULL, j.c_str(), -1, &m_rCurrScore, DT_RIGHT, D3DCOLOR_ARGB(255, 255, 255, 255));

		std::stringstream ss2;
		ss2 << m_Highscore;
		j = ss2.str();
		m_Font->DrawTextA(NULL, j.c_str(), -1, &m_rBest, DT_RIGHT, D3DCOLOR_ARGB(255, 255, 255, 255));

        //stop rendering
        m_Sprite->End();
		m_d3ddev->EndScene();
        m_d3ddev->Present(NULL, NULL, NULL, NULL);

	}
}
Example #5
0
BOOL COSMCtrlAppApp::InitInstance()
{
	//Initialize OLE
	if (!AfxOleInit())
  {
 		AfxMessageBox(IDS_OLE_INIT_FAILED, MB_OK | MB_ICONSTOP);
		return FALSE;
  }
  
  //Initialize GDI+
#ifdef COSMCTRL_NOD2D
  Gdiplus::GdiplusStartupInput gdiplusStartupInput;
  if (Gdiplus::GdiplusStartup(&m_GDIPlusToken, &gdiplusStartupInput, NULL) != Gdiplus::Ok)
  {
    AfxMessageBox(_T("Failed to initialize GDI+"), MB_OK | MB_ICONSTOP);
    return FALSE;
  }
#endif

	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);


#ifdef _DEBUG //Just some test code to exercise the various methods which implement Vincenty's algorithms
  COSMCtrlPosition pos1(-77.04978, 38.88922);
  double dEndBearing = 0;
  COSMCtrlPosition pos2 = COSMCtrlHelper::GetPosition(pos1, 51.7679, 6179016.13586, &dEndBearing);
  double dStartBearing;
  double dDistance = COSMCtrlHelper::DistanceBetweenPoints(pos1, pos2, &dStartBearing, &dEndBearing);
  dDistance;

  //Do the reverse test
  COSMCtrlPosition pos3(2.29583, 48.85889);
  double dStartBearing2;
  double dEndBearing2;
  double dDistance2 = COSMCtrlHelper::DistanceBetweenPoints(pos1, pos3, &dStartBearing2, &dEndBearing2);

  pos1 = COSMCtrlPosition(175.04978, 38.88922);
  pos2 = COSMCtrlHelper::GetPosition(pos1, 90, 8000, &dEndBearing);
  
  pos1 = COSMCtrlPosition(-77.04978, 38.88922);
  double dEndBearing3;
  COSMCtrlPosition pos4 = COSMCtrlHelper::GetPosition(pos1, dStartBearing2, dDistance2, &dEndBearing3);

  COSMCtrlPosition pos5(-180, 0);
  COSMCtrlPosition pos6(0, 0);
  double dStartBearing5;
  double dEndBearing5;
  double dDistance5 = COSMCtrlHelper::DistanceBetweenPoints(pos5, pos6, &dStartBearing5, &dEndBearing5);
  dDistance5;

  COSMCtrlPosition pos7(0, 0);
  COSMCtrlPosition pos8(-180, 0);
  double dStartBearing7;
  double dEndBearing7;
  double dDistance7 = COSMCtrlHelper::DistanceBetweenPoints(pos7, pos8, &dStartBearing7, &dEndBearing7);
  dDistance7;

  COSMCtrlPosition pos9(0, 90);
  COSMCtrlPosition pos10(0, -90);
  double dStartBearing9;
  double dEndBearing9;
  double dDistance9 = COSMCtrlHelper::DistanceBetweenPoints(pos9, pos10, &dStartBearing9, &dEndBearing9);
  dDistance9;

  COSMCtrlPosition pos11(0, -90);
  COSMCtrlPosition pos12(0, 90);
  double dStartBearing11;
  double dEndBearing11;
  double dDistance11 = COSMCtrlHelper::DistanceBetweenPoints(pos11, pos12, &dStartBearing11, &dEndBearing11);
  dDistance11;

  COSMCtrlPosition pos13(0, 60);
  COSMCtrlPosition pos14(180, -60);
  double dStartBearing13;
  double dEndBearing13;
  double dDistance13 = COSMCtrlHelper::DistanceBetweenPoints(pos13, pos14, &dStartBearing13, &dEndBearing13);
  dDistance13;

  COSMCtrlPosition pos15(180, -60);
  COSMCtrlPosition pos16(0, 60);
  double dStartBearing15;
  double dEndBearing15;
  double dDistance15 = COSMCtrlHelper::DistanceBetweenPoints(pos15, pos16, &dStartBearing15, &dEndBearing15);
  dDistance15;
#endif

	CWinApp::InitInstance();

	//Standard initialization
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));
	LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)

	//Register the application's document templates.  Document templates
	//serve as the connection between documents, frame windows and views
	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(COSMCtrlAppDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(COSMCtrlAppView));
	if (!pDocTemplate)
		return FALSE;
	AddDocTemplate(pDocTemplate);

	//Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	//Dispatch commands specified on the command line.  Will return FALSE if
	//app was launched with /RegServer, /Register, /Unregserver or /Unregister.
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	//The one and only window has been initialized, so show and update it
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	return TRUE;
}