int main(int argc, char** argv) {

	sf::RenderWindow renderWindow(sf::VideoMode(300, 300), "Sprite Demo");
	sf::Event event;

	sf::Texture guyTexture;
	guyTexture.loadFromFile("images/200by200.png");

	sf::Texture blackCircleTexture;
	blackCircleTexture.loadFromFile("images/blackcircle.png");

	sf::IntRect playerDimension(50, 0, 50, 50);
	sf::Sprite player(guyTexture, playerDimension);
	player.setPosition(150, 150);

	sf::Sprite circle(blackCircleTexture);
	circle.setOrigin(sf::Vector2f((circle.getLocalBounds().width / 2), circle.getLocalBounds().height / 2));
	circle.setPosition(player.getPosition().x + player.getLocalbounds().width, player.getPosition().y + player.getLocalbounds().height);

	while (renderWindow.isOpen()) {
		/*
		next_game_tick += SKIP_TICKS;
		sleep_time = next_game_tick - GetTickCount();
		if (sleep_time >= 0) {
			Sleep(sleep_time);
		}
		else {
			// Shit, we are running behind!
		}
		*/
		while (renderWindow.pollEvent(event)) {
			if (event.type == sf::Event::EventType::Closed) {
				renderWindow.close();
			}

			if (event.type == sf::Event::KeyPressed) {

				if (event.key.code == sf::Keyboard::Up) {
					playerDimension.top = 150;
					if (playerDimension.left == 150) {
						playerDimension.left = 0;
					}
					else {
						playerDimension.left += 50;
					}
					player.setTextureRect(playerDimension);
					player.move(0, -10);
					circle.setPosition(player.getPosition().x, player.getPosition().y);
				}

				if (event.key.code == sf::Keyboard::Down) {
					playerDimension.top = 0;
					if (playerDimension.left == 150) {
						playerDimension.left = 0;
					}
					else {
						playerDimension.left += 50;
					}
					player.setTextureRect(playerDimension);
					player.move(0, 10);
					circle.setPosition(player.getPosition().x, player.getPosition().y);
				}

				if (event.key.code == sf::Keyboard::Left) {
					playerDimension.top = 50;
					if (playerDimension.left == 150) {
						playerDimension.left = 0;
					}
					else {
						playerDimension.left += 50;
					}
					player.setTextureRect(playerDimension);
					player.move(-10, 0);
					circle.setPosition(player.getPosition().x, player.getPosition().y);
				}

				if (event.key.code == sf::Keyboard::Right) {
					playerDimension.top = 100;
					if (playerDimension.left == 150) {
						playerDimension.left = 0;
					}
					else {
						playerDimension.left += 50;
					}
					player.setTextureRect(playerDimension);
					player.move(10, 0);
					circle.setPosition(player.getPosition().x, player.getPosition().y);
				}
			}
		}
		renderWindow.clear(sf::Color::White);
		renderWindow.draw(player);
		renderWindow.draw(circle);
		renderWindow.display();
		_sleep(100);
	}
}
Exemple #2
0
void drawLaby(void)
{
	char l=0,lg;
	char *ptr;
	// 1000 HIRES:INK EENC(VIL):POKE#26A,PEEK(#26A) AND 254
	hires();
	ink(eencre[ville-1]);
	ptr = (char*)0x26a; *ptr = *ptr & 254; // Vire le curseur 
	// 1020 CURSET40,30,3:DRAW160,0,1:DRAW0,150,1
    CurrentPixelX=40;
    CurrentPixelY=30;
	OtherPixelX=40+160;
    OtherPixelY=30;
    DrawLine8();
    CurrentPixelX=40+160;
    CurrentPixelY=30;
	OtherPixelX=40+160;
    OtherPixelY=30+150;
    DrawLine8();
	// 1030 DRAW-160,0,1:DRAW0,-150,1
    CurrentPixelX=40+160;
    CurrentPixelY=30+150;
	OtherPixelX=40;
    OtherPixelY=30+150;
    DrawLine8();
    CurrentPixelX=40;
    CurrentPixelY=30+150;
	OtherPixelX=40;
    OtherPixelY=30;
    DrawLine8();
	// 1035 IF BS=1 THEN GOSUB 2800
	// 1040 L=1
	for(l=0;l<3;l++) {
		// 1400 REM DESSINS DES BLOCS 

		// 1070 IF G(L)>0 AND G(L)<7 THEN ON L GOSUB 1500,1550,1600
		if(g[l]>0&&g[l]<7) {
			switch(l) {
				case 0:
					// 1500 CURSET 40,30,3:DRAW20,20,1:DRAW0,110,1:DRAW-20,20,1
					CurrentPixelX=40;
					CurrentPixelY=30;
					OtherPixelX=40+20;
					OtherPixelY=30+20;
					DrawLine8();
					CurrentPixelX=40+20;
					CurrentPixelY=30+20;
					OtherPixelX=40+20;
					OtherPixelY=30+20+110;
					DrawLine8();
					CurrentPixelX=40+20;
					CurrentPixelY=30+20+110;
					OtherPixelX=40;
					OtherPixelY=30+20+110+20;
					DrawLine8();
					break;
				case 1:
					// 1550 CURSET60,50,1:DRAW25,25,1:DRAW0,60,1:DRAW-25,25,1
					CurrentPixelX=60;
					CurrentPixelY=50;
					OtherPixelX=60+25;
					OtherPixelY=50+25;
					DrawLine8();
					CurrentPixelX=60+25;
					CurrentPixelY=50+25;
					OtherPixelX=60+25;
					OtherPixelY=50+25+60;
					DrawLine8();
					CurrentPixelX=60+25;
					CurrentPixelY=50+25+60;
					OtherPixelX=60;
					OtherPixelY=50+25+60+25;
					DrawLine8();
					// 1570 IF G(1)=0 OR G(1)>6 THEN CURSET 40,50,1:DRAW20,0,1:DRAW 0,110,1:DRAW -20,0,1
					if(g[0]==0 || g[0]>6) {
						CurrentPixelX=40;
						CurrentPixelY=50;
						OtherPixelX=40+20;
						OtherPixelY=50;
						DrawLine8();
						CurrentPixelX=40+20;
						CurrentPixelY=50;
						OtherPixelX=40+20;
						OtherPixelY=50+110;
						DrawLine8();
						CurrentPixelX=40+20;
						CurrentPixelY=50+110;
						OtherPixelX=40;
						OtherPixelY=50+110;
						DrawLine8();					
					}
					break;
				case 2:
					// 1600 CURSET85,75,1:DRAW10,10,1:DRAW0,40,1:DRAW-10,10,1
					CurrentPixelX=85;
					CurrentPixelY=75;
					OtherPixelX=85+10;
					OtherPixelY=75+10;
					DrawLine8();
					CurrentPixelX=85+10;
					CurrentPixelY=75+10;
					OtherPixelX=85+10;
					OtherPixelY=75+10+40;
					DrawLine8();
					CurrentPixelX=85+10;
					CurrentPixelY=75+10+40;
					OtherPixelX=85;
					OtherPixelY=75+10+40+10;
					DrawLine8();					
					// 1620 IF G(2)>0 AND G(2)<7  THEN GOTO 1650
					if(!(g[1]>0&&g[1]<7)) {
						char t;
						// 1630 IF G(1)=0 OR G(1)>6 THEN T=45 ELSE T=25
						if(g[0]==0 || g[0]>6) t=45;
						else t=25;
						// 1640 CURSET85,75,1:DRAW0,60,1:DRAW-T,0,1:CURSET85,75,1:DRAW-T,0,1
						CurrentPixelX=85;
						CurrentPixelY=75;
						OtherPixelX=85;
						OtherPixelY=75+60;
						DrawLine8();
						CurrentPixelX=85;
						CurrentPixelY=75+60;
						OtherPixelX=85-t;
						OtherPixelY=75+60;
						DrawLine8();
						CurrentPixelX=85;
						CurrentPixelY=75;
						OtherPixelX=85-t;
						OtherPixelY=75;
						DrawLine8();
					}
					break;
			}
			// 1650 IF G(L)<2 OR G(L)>6 THEN RETURN
			if (!(g[l]<2 || g[l]>6)) {
				// 1670 ON L GOSUB 1700,1750,1800
				switch(l) {
					case 0:
						// 1700 CURSET 48,172,1:DRAW0,-125,1:DRAW -7,-7,1:RETURN
						CurrentPixelX=48;
						CurrentPixelY=172;
						OtherPixelX=48;
						OtherPixelY=172-125;
						DrawLine8();
						CurrentPixelX=48;
						CurrentPixelY=172-125;
						OtherPixelX=48-7;
						OtherPixelY=172-125-7;
						DrawLine8();
						break;
					case 1:
						// 1750 CURSET65,155,1:DRAW0,-95,1:DRAW 15,15,1:DRAW0,65,1
						CurrentPixelX=65;
						CurrentPixelY=155;
						OtherPixelX=65;
						OtherPixelY=155-95;
						DrawLine8();
						CurrentPixelX=65;
						CurrentPixelY=155-95;
						OtherPixelX=65+15;
						OtherPixelY=155-95+15;
						DrawLine8();
						CurrentPixelX=65+15;
						CurrentPixelY=155-95+15;
						OtherPixelX=65+15;
						OtherPixelY=155-95+15+65;
						DrawLine8();
						// 1770 CURSET67,105,3:CIRCLE1,1:RETURN
						curset(67,105,3);
						circle(1,1);
						break;
					case 2:
						// 1800 CURSET 88,132,1:DRAW0,-49,1:DRAW5,5,1:DRAW0,38,1
						CurrentPixelX=88;
						CurrentPixelY=132;
						OtherPixelX=88;
						OtherPixelY=132-49;
						DrawLine8();
						CurrentPixelX=88;
						CurrentPixelY=132-49;
						OtherPixelX=88+5;
						OtherPixelY=132-49+5;
						DrawLine8();
						CurrentPixelX=88+5;
						CurrentPixelY=132-49+5;
						OtherPixelX=88+5;
						OtherPixelY=132-49+5+38;
						DrawLine8();
						// 1820 CURSET 89,105,1
						curset(89,105,1);
						break;
				}
			}
		}
		// 1080 IF D(L)>0 AND D(L)<7 THEN ON L GOSUB 1900,1950,2000
		if(d[l]>0&&d[l]<7) {
			switch(l) {
				case 0:
					// 1900 CURSET200,30,3:DRAW-20,20,1:DRAW0,110,1:DRAW20,20,1					
					CurrentPixelX=200;
					CurrentPixelY=30;
					OtherPixelX=200-20;
					OtherPixelY=30+20;
					DrawLine8();
					CurrentPixelX=200-20;
					CurrentPixelY=30+20;
					OtherPixelX=200-20;
					OtherPixelY=30+20+110;
					DrawLine8();
					CurrentPixelX=200-20;
					CurrentPixelY=30+20+110;
					OtherPixelX=200;
					OtherPixelY=30+20+110+20;
					DrawLine8();
					// 1920 GOTO 2050
					break;
				case 1:
					// 1950 CURSET180,50,3:DRAW-25,25,1:DRAW0,60,1:DRAW25,25,1
					CurrentPixelX=180;
					CurrentPixelY=50;
					OtherPixelX=180-25;
					OtherPixelY=50+25;
					DrawLine8();
					CurrentPixelX=180-25;
					CurrentPixelY=50+25;
					OtherPixelX=180-25;
					OtherPixelY=50+25+60;
					DrawLine8();
					CurrentPixelX=180-25;
					CurrentPixelY=50+25+60;
					OtherPixelX=180;
					OtherPixelY=50+25+60+25;
					DrawLine8();
					// 1970 IF D(1)=0 OR D(1)>6 THEN CURSET 200,50,1:DRAW-20,0,1:DRAW 0,110,1:DRAW20,0,1
					if(d[0]==0 || d[0]>6) {
						CurrentPixelX=200;
						CurrentPixelY=50;
						OtherPixelX=200-20;
						OtherPixelY=50;
						DrawLine8();
						CurrentPixelX=200-20;
						CurrentPixelY=50;
						OtherPixelX=200-20;
						OtherPixelY=50+110;
						DrawLine8();
						CurrentPixelX=200-20;
						CurrentPixelY=50+110;
						OtherPixelX=200;
						OtherPixelY=50+110;
						DrawLine8();
					}
					// 1980 GOTO 2050
					break;
				case 2:
					// 2000 CURSET155,75,1:DRAW-10,10,1:DRAW0,40,1:DRAW10,10,1
					CurrentPixelX=155;
					CurrentPixelY=75;
					OtherPixelX=155-10;
					OtherPixelY=75+10;
					DrawLine8();
					CurrentPixelX=155-10;
					CurrentPixelY=75+10;
					OtherPixelX=155-10;
					OtherPixelY=75+10+40;
					DrawLine8();
					CurrentPixelX=155-10;
					CurrentPixelY=75+10+40;
					OtherPixelX=155;
					OtherPixelY=75+10+40+10;
					DrawLine8();
					// 2020 IF D(2)>0 AND D(2)<7 THEN GOTO 2050
					if(!(d[1]>0 && d[1]<7)) {
						char t;
						// 2030 IF D(1)=0 OR D(1)>6 THEN T=45 ELSE T=25
						if(d[0]==0 || d[0]>6) t=45;
						else t=25;
						// 2040 CURSET155,75,1:DRAW0,60,1:DRAWT,0,1:CURSET 155,75,1:DRAWT,0,1
						CurrentPixelX=155;
						CurrentPixelY=75;
						OtherPixelX=155;
						OtherPixelY=75+60;
						DrawLine8();
						CurrentPixelX=155;
						CurrentPixelY=75+60;
						OtherPixelX=155+t;
						OtherPixelY=75+60;
						DrawLine8();
						CurrentPixelX=155;
						CurrentPixelY=75;
						OtherPixelX=155+t;
						OtherPixelY=75;
						DrawLine8();
					}
					break;
			}
			// 2050 IF D(L)<2 OR D(L)>6 THEN RETURN
			if(!(d[l]<2 || d[l]>6)) {
				// 2070 ON L GOSUB 2100,2150,2200
				switch(l) {
					case 0:
						// 2100 CURSET193,172,1:DRAW0,-125,1:DRAW 7,-7,1
						CurrentPixelX=193;
						CurrentPixelY=172;
						OtherPixelX=193;
						OtherPixelY=172-125;
						DrawLine8();
						CurrentPixelX=193;
						CurrentPixelY=172-125;
						OtherPixelX=193+7;
						OtherPixelY=172-125-7;
						DrawLine8();
						break;
					case 1:
						// 2150 CURSET175,155,1:DRAW0,-95,1:DRAW-15,15,1:DRAW0,65,1
						CurrentPixelX=175;
						CurrentPixelY=155;
						OtherPixelX=175;
						OtherPixelY=155-95;
						DrawLine8();
						CurrentPixelX=175;
						CurrentPixelY=155-95;
						OtherPixelX=175-15;
						OtherPixelY=155-95+15;
						DrawLine8();
						CurrentPixelX=175-15;
						CurrentPixelY=155-95+15;
						OtherPixelX=175-15;
						OtherPixelY=155-95+15+65;
						DrawLine8();
						// 2170 CURSET162,105,3:CIRCLE1,1:RETURN
						curset(162,105,3);
						circle(1,1);
						break;
					case 2:
						// 2200 CURSET 152,132,1:DRAW0,-49,1:DRAW-5,5,1:DRAW0,38,1
						CurrentPixelX=152;
						CurrentPixelY=132;
						OtherPixelX=152;
						OtherPixelY=132-49;
						DrawLine8();
						CurrentPixelX=152;
						CurrentPixelY=132-49;
						OtherPixelX=152-5;
						OtherPixelY=132-49+5;
						DrawLine8();
						CurrentPixelX=152-5;
						CurrentPixelY=132-49+5;
						OtherPixelX=152-5;
						OtherPixelY=132-49+5+38;
						DrawLine8();
						// 2220 CURSET 148,105,1
						curset(148,105,1);
						break;
				}
				// 2080 RETURN
			}
		}
		// 1090 IF F(L)>0 AND F(L)<7 THEN ON L GOSUB 2300,2400
		if(f[l]>0 && f[l]<7) {
			switch(l) {
				case 0:
					// 2300 CURSET 60,50,1:DRAW120,0,1:DRAW0,110,1:DRAW-120,0,1:DRAW0,-110,1
					CurrentPixelX=60;
					CurrentPixelY=50;
					OtherPixelX=60+120;
					OtherPixelY=50;
					DrawLine8();
					CurrentPixelX=60+120;
					CurrentPixelY=50;
					OtherPixelX=60+120;
					OtherPixelY=50+110;
					DrawLine8();
					CurrentPixelX=60+120;
					CurrentPixelY=50+110;
					OtherPixelX=60;
					OtherPixelY=50+110;
					DrawLine8();
					CurrentPixelX=60;
					CurrentPixelY=50+110;
					OtherPixelX=60;
					OtherPixelY=50;
					DrawLine8();
					// 2320 IF (G(1)=0 OR G(1)>6) AND (G(2)>0 AND G(2)<7) THEN 
					if((g[0]==0||g[0]>6)&&(g[1]>0&&g[1]<7)) {
						// DRAW-20,0,1:CURSET60,160,1:DRAW-20,0,1
						CurrentPixelX=60;
						CurrentPixelY=50;
						OtherPixelX=60-20;
						OtherPixelY=50;
						DrawLine8();
						CurrentPixelX=60;
						CurrentPixelY=160;
						OtherPixelX=60-20;
						OtherPixelY=160;
						DrawLine8();
					}
					// 2340 IF (D(1)=0 OR D(1)>6) AND (D(2)>0 AND D(2)<7) THEN 
					if((d[0]==0||d[0]>6)&&(d[1]>0&&d[1]<7)) {
						// CURSET180,50,3:DRAW 20,0,1:CURSET 180,160,1:DRAW20,0,1
						CurrentPixelX=180;
						CurrentPixelY=50;
						OtherPixelX=180+20;
						OtherPixelY=50;
						DrawLine8();
						CurrentPixelX=180;
						CurrentPixelY=160;
						OtherPixelX=180+20;
						OtherPixelY=160;
						DrawLine8();
					}
					// 2350 GOTO 2500
					break;
				case 1:
					// 2400 CURSET 85,75,1:DRAW 70,0,1:DRAW 0,60,1:DRAW-70,0,1:DRAW0,-60,1
					CurrentPixelX=85;
					CurrentPixelY=75;
					OtherPixelX=85+70;
					OtherPixelY=75;
					DrawLine8();
					CurrentPixelX=85+70;
					CurrentPixelY=75;
					OtherPixelX=85+70;
					OtherPixelY=75+60;
					DrawLine8();
					CurrentPixelX=85+70;
					CurrentPixelY=75+60;
					OtherPixelX=85;
					OtherPixelY=75+60;
					DrawLine8();
					CurrentPixelX=85;
					CurrentPixelY=75+60;
					OtherPixelX=85;
					OtherPixelY=75;
					DrawLine8();
					{
						char tg, td;
						// 2415 IF G(1)=0 OR G(1)>6 THEN TG=45 ELSE TG=25
						if(g[0]==0||g[0]>6) tg=45;
						else tg=25;
						// 2416 IF D(1)=0 OR D(1)>6 THEN TD=45 ELSE TD=25
						if(d[0]==0||d[0]>6) td=45;
						else td=25;
						// 2420 IF (G(2)=0 OR G(2)>6) AND (G(3)>0 AND G(3)<7) THEN 
						if((g[1]==0||g[1]>6)&&(g[2]>0&&g[2]<7)) {
							// DRAW-TG,0,1:CURSET85,135,1:DRAW-TG,0,1
							CurrentPixelX=85;
							CurrentPixelY=75;
							OtherPixelX=85-tg;
							OtherPixelY=75;
							DrawLine8();
							CurrentPixelX=85;
							CurrentPixelY=135;
							OtherPixelX=85-tg;
							OtherPixelY=135;
							DrawLine8();
						}
						// 2430 IF (D(2)=0 OR D(2)>6) AND (D(3)>0 AND D(3)<7) THEN 
						if((d[1]==0||d[1]>6)&&(d[2]>0&&d[2]<7)) {
							// CURSET155,75,3:DRAW TD,0,1:CURSET 155,135,1:DRAWTD,0,1
							CurrentPixelX=155;
							CurrentPixelY=75;
							OtherPixelX=155+td;
							OtherPixelY=75;
							DrawLine8();
							CurrentPixelX=155;
							CurrentPixelY=135;
							OtherPixelX=155+td;
							OtherPixelY=135;
							DrawLine8();
						}
					}
					break;
			}
			// 2500 IF F(L)>1 AND F(L)<7 THEN ON L GOSUB 2550,2580
			if(f[l]>1&&f[l]<7) {
				switch(l) {
					case 0:
						// 2550 CURSET 80,160,1:DRAW0,-100,1:DRAW85,0,1:DRAW0,100,1:CURSET 83,115,1:CIRCLE 2,1
						CurrentPixelX=80;
						CurrentPixelY=160;
						OtherPixelX=80;
						OtherPixelY=60;
						DrawLine8();
						CurrentPixelX=80;
						CurrentPixelY=60;
						OtherPixelX=80+85;
						OtherPixelY=60;
						DrawLine8();
						CurrentPixelX=80+85;
						CurrentPixelY=60;
						OtherPixelX=80+85;
						OtherPixelY=60+100;
						DrawLine8();
						curset(83,115,1);
						circle(2,1);
						// 2560 PS=F(L): IF PS>2 AND PS<7 THEN GOSUB 2650
						if(f[l]>2 && f[l]<7) {
							unsigned char p,i,t;
							char *texte;
							if(f[l]==5 || f[l]==6) {
								char g=105,nb=5,h=35,br=25;
								p=3;
								
								// Grille
								// New version Max DEBUG
								if(ville==9 && f[l]==6) {
									nb=7;g=96;br=75;h=53;
								}
								CurrentPixelX=g;
								CurrentPixelY=75;
								OtherPixelX=g+h;
								OtherPixelY=75;
								DrawLine8();
								CurrentPixelX=g+h;
								CurrentPixelY=75;
								OtherPixelX=g+h;
								OtherPixelY=75+br;
								DrawLine8();
								CurrentPixelX=g+h;
								CurrentPixelY=75+br;
								OtherPixelX=g;
								OtherPixelY=75+br;
								DrawLine8();
								CurrentPixelX=g;
								CurrentPixelY=75+br;
								OtherPixelX=g;
								OtherPixelY=75;
								DrawLine8();
								// 2720 FORI=1TO3:CURSETG,75,1:DRAW0,25,1:G=G+9:NEXTI
								for(i=0;i<nb;i++) {
									CurrentPixelX=g;
									CurrentPixelY=75;
									OtherPixelX=g;
									OtherPixelY=75+br;
									DrawLine8();
									g+=9;
								}
							}
							//printf("texte");
							// 2760 FORI=1TOLEN(S$):CURSET T,65,3:CHAR ASC(MID$(S$,I,1)),0,1:T=T+6:NEXTI
							t=(ville-1)*4+(f[l]-3);
							// pour la porte 6 de Winterfell
							if(ville==9 && f[l]==6) {
								// si on regarde vers le nord on écrit NORD
								if (s==1) t+=2;
								// si on regarde vers le sud ou l'ouest on écrit SUD
								else if(s==3 || s==4) t+=1;
								// sinon (on regarde vers l'est)
								// et si on est dedans on affiche pas
								else if(TestBit(&dedans,3)) break;
							} else {
								// si on est dedans on affiche pas
								if(f[l]-3<=3 && TestBit(&dedans,f[l]-3)) break;
							}
							texte = portes[t];
							lg = strlen(texte);
							t=124-lg*3;
							//printf("v:%d,f[l]:%d,i:%d,lg:%d,t:%d,de:%x\n",
							//	ville, f[l], (f[l]-3), lg, t, dedans);
							for(i=0;i<lg;i++) {
								curset(t,65,3);
								hchar(texte[i],0,1);
								//printf("%c",texte[i]);
								t+=6;
							}
							//printf("\n");
							// 2790 RETURN
						}
						// 2565 RETURN
						break;
					case 1:
						// 2580 CURSET95,135,1:DRAW0,-50,1:DRAW50,0,1:DRAW0,50,1:CURSET 96,115,1:RETURN
						CurrentPixelX=95;
						CurrentPixelY=135;
						OtherPixelX=95;
						OtherPixelY=135-50;
						DrawLine8();
						CurrentPixelX=95;
						CurrentPixelY=135-50;
						OtherPixelX=95+50;
						OtherPixelY=135-50;
						DrawLine8();
						CurrentPixelX=95+50;
						CurrentPixelY=135-50;
						OtherPixelX=95+50;
						OtherPixelY=135;
						DrawLine8();
						curset(96,115,1);
						break;
				}
			}
			// 2520 RETURN
			// 1095 IF F(L)>0 AND F(L)<7 THEN GOTO 1200
			// stop looping
			break;
		}
	}
	
	
	// boussole
	if(boussole){
		char dir;
		switch(s) {
			// 2800 IF S=1 THEN DIR=78
			case 0:
				dir=78;
				break;
			// 2820 IF S=2 THEN DIR=69
			case 1:
				dir=69;
				break;
			// 2830 IF S=3 THEN DIR=83
			case 2:
				dir=83;
				break;
			// 2840 IF S=4 THEN DIR=79
			case 3:
				dir=79;
				break;
		}
		// 2850 CURSET 220,10,1:CHAR DIR,0,1:CURMOV 2,8,1
		curset(220,10,0);hchar(dir,0,1);
		// 2860 DRAW 3,15,1:DRAW -3,15,1:DRAW -3,-15,1:DRAW 3,-15,1
		curset(222,18,1);
		CurrentPixelX=220+2;
		CurrentPixelY=10+8;
		OtherPixelX=220+2+3;
		OtherPixelY=10+8+15;
		DrawLine8();
		CurrentPixelX=220+2+3;
		CurrentPixelY=10+8+15;
		OtherPixelX=220+2;
		OtherPixelY=10+8+15+15;
		DrawLine8();
		CurrentPixelX=220+2;
		CurrentPixelY=10+8+15+15;
		OtherPixelX=220+2-3;
		OtherPixelY=10+8+15;
		DrawLine8();
		CurrentPixelX=220+2-3;
		CurrentPixelY=10+8+15;
		OtherPixelX=220+2;
		OtherPixelY=10+8;
		DrawLine8();
		// 2870 CURMOV2,12,1:DRAW 13,3,1:DRAW -13,3,1
		curset(224,30,1);
		CurrentPixelX=220+2+2;
		CurrentPixelY=10+8+12;
		OtherPixelX=220+2+2+13;
		OtherPixelY=10+8+12+3;
		DrawLine8();
		CurrentPixelX=220+2+2+13;
		CurrentPixelY=10+8+12+3;
		OtherPixelX=220+2+2;
		OtherPixelY=10+8+12+3+3;
		DrawLine8();
		// 2880 CURSET 220,30,1:DRAW -13,3,1:DRAW 13,3,1
		curset(220,30,1);
		CurrentPixelX=220;
		CurrentPixelY=30;
		OtherPixelX=220-13;
		OtherPixelY=30+3;
		DrawLine8();
		CurrentPixelX=220-13;
		CurrentPixelY=30+3;
		OtherPixelX=220;
		OtherPixelY=30+3+3;
		DrawLine8();
		// 2900 RETURN
	}
}
Exemple #3
0
void main()
{
int gd=DETECT,gm,area,x=25,y=25,ch,xdirn=1,ydirn=1;
int maxx,maxy;
char *buff;

initgraph(&gd,&gm,"d:\\tc\\bgi");

setcolor(WHITE);
setfillstyle(SOLID_FILL,LIGHTRED);
circle(50,50,25);
floodfill(50,50,WHITE);

area=imagesize(25,25,75,75);
buff=(char *)malloc(area);
getimage(25,25,75,75,buff);

maxx=getmaxx();
maxy=getmaxy();
rectangle(0,20,maxx,maxy);
outtextxy(250,10,"Animation");

while(1)
	{
	if(kbhit())
		{
		ch=getch();

		if(ch=='\r')
			{
			xdirn*=-1;
			ydirn*=-1;
			}
		else
			{
			if(ch==27)
			break;
			}
		}

	putimage(x,y,buff,OR_PUT);
	delay(0);
	x=x+(xdirn*5);
	y=y+(ydirn*2);
	putimage(x,y,buff,OR_PUT);

       if(x>maxx-50||x<0);
		{
		sound(50);
		delay(10);
		nosound();
		xdirn*=-1;
		}

		if(y>maxy-50||y<20)
		{
		sound(50);
		delay(10);
		nosound();
		ydirn*=-1;
		}
       }

getch();
closegraph();
restorecrtmode();
}
///////////////////////////////////////////////////////////////////
// Panel::CannyDetection() 
// Description: This function is called by DetectEdges() and it
//  is the Canny edge detection function which does not contain
//  debugging statements. We run the image through several different 
//  image processing functions to prepare the image before edge
//  detection. After detection the edges we run Hough lines which 
//  approximates lines of minimum length as specified in 
//  Settings.xml. We find all intersections of the Hough lines 
//  then make a minimum area rectangle around the intersections to 
//  approximate the edges of the panel which we are trying to
//  measure. From there we use the unit conversion calculated 
//  in DetectFeatures() to find a length and width of the current
//  panel. We report the length and width with a message box. 
///////////////////////////////////////////////////////////////////
Mat Panel::CannyDetection(Mat image, bool showImg)
{
	Mat greyImage;
	cvtColor(image, greyImage, CV_BGR2GRAY);

	Mat eroded, dilated, thresh, blurredThresh, edges, edgesGray;
	vector<Vec2f> lines;

		threshold(greyImage, thresh, m_lowCannyThreshold, 255, THRESH_BINARY);
		erode(thresh, eroded, Mat());
		dilate(eroded, dilated, Mat());
		GaussianBlur(thresh, blurredThresh, Size(7, 7), m_sigmaX, m_sigmaY);
		Canny(blurredThresh, edges, m_cannyLow, m_cannyLow*m_ratio, 3);
		HoughLines(edges, lines, 1, CV_PI / 180, m_houghLength, 0, 0);

		cvtColor(edges, edgesGray, CV_GRAY2BGR);
		for (size_t i = 0; i < lines.size(); i++)
		{
			float rho = lines[i][0], theta = lines[i][1];
			Point pt1, pt2;
			double a = cos(theta), b = sin(theta);
			double x0 = a*rho, y0 = b*rho;
			pt1.x = cvRound(x0 + 1000 * (-b));
			pt1.y = cvRound(y0 + 1000 * (a));
			pt2.x = cvRound(x0 - 1000 * (-b));
			pt2.y = cvRound(y0 - 1000 * (a));
			line(edgesGray, pt1, pt2, Scalar(0, 0, 255), 3, CV_AA);
		}

		////////////////////////////////////////////////////////
		// Compute the intersection from the lines detected
		////////////////////////////////////////////////////////
		vector<Point2f> intersections;
		for (size_t i = 0; i < lines.size(); i++)
		{
			for (size_t j = 0; j < lines.size(); j++)
			{
				Vec2f line1 = lines[i];
				Vec2f line2 = lines[j];
				if (acceptLinePair(line1, line2, (float)CV_PI / 32))
				{
					Point2f intersection = computeIntersect(line1, line2);
					if (intersection.x >= 0 && intersection.y >= 0)
						intersections.push_back(intersection);
				}
			}
		}

		if (intersections.size() > 0)
		{
			vector<Point2f>::iterator i;
			for (i = intersections.begin(); i != intersections.end(); ++i)
			{
				cout << "Intersection is " << i->x << ", " << i->y << endl;
				circle(image, *i, 2, Scalar(0, 255, 0), 3);
			}
			// Find the minimum bounding rectangle
			RotatedRect rect;
			Point2f rectPoints[4];
			Scalar color = Scalar(255, 0, 0);
			if (intersections.size() == 4)
			{
				// TODO
			}
			rect = minAreaRect(intersections);
			rect.points(rectPoints);
			int j = 0;
			for (j; j < 4; j++)
				line(image, rectPoints[j], rectPoints[(j + 1) % 4], color, 5, 8);

			float topLength = (float)norm(rectPoints[1] - rectPoints[0]);
			float botLength = (float)norm(rectPoints[3] - rectPoints[2]);
			float panelWidthPixels = topLength < botLength ? topLength : botLength;

			float leftHeight = (float)norm(rectPoints[3] - rectPoints[0]);
			float rightHeight = (float)norm(rectPoints[2] - rectPoints[1]);
			float panelHeightPixels = leftHeight < rightHeight ? leftHeight : rightHeight;

			string dimensionDisplayPixels = "Pixels:\nWidth: " + to_string(panelWidthPixels) + " pixels\nHeight: " + to_string(panelHeightPixels) + " pixels";
			// ShowMessage(dimensionDisplayPixels);
			if (m_conversionRate)
			{
				float panelWidthReal = panelWidthPixels / m_conversionRate;
				float panelHeightReal = panelHeightPixels / m_conversionRate;
				string dimensionDisplayActual = "Actual:\nWidth: " + to_string(panelWidthReal) + " cm\nHeight: " + to_string(panelHeightReal) + " cm";
				ShowMessage(dimensionDisplayActual);
			}

		}

		if (showImg){
			namedWindow("Intersections", CV_WINDOW_KEEPRATIO);
			imshow("Intersections", image);
		}
		/////////////////////////////////////////////////////////////
		// End of Computing the intersection from the lines detected
		/////////////////////////////////////////////////////////////
	return edges;
}
///////////////////////////////////////////////////////
// Panel::PixelsToLength() 
//  Description: Not currently used: Calculates the
// ratio of cm to pixels from one checkerboard image
///////////////////////////////////////////////////////
void Panel::PixelsToLength(string sImgPath)
{
	cout << "Pixels to Length" << endl << endl;
	m_pPanel->m_Image = imread(sImgPath);

	Point2f corner1;
	Point2f corner2;
	Point2f corner3;
	Point2f corner4;

	bool found = false;

	found = findChessboardCorners(m_pPanel->m_Image, Size(9, 6), m_pPanel->corners,
		CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_FAST_CHECK | CALIB_CB_NORMALIZE_IMAGE);

	Mat imgGray;
	cvtColor(m_pPanel->m_Image, imgGray, COLOR_BGR2GRAY);
	cornerSubPix(imgGray, m_pPanel->corners, Size(11, 11), Size(-1, -1),
		TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));

	corner1.x = m_pPanel->corners[45].x;
	corner1.y = m_pPanel->corners[45].y;

	corner2.x = m_pPanel->corners[0].x;
	corner2.y = m_pPanel->corners[0].y;

	corner3.x = m_pPanel->corners[8].x;
	corner3.y = m_pPanel->corners[8].y;

	corner4.x = m_pPanel->corners[53].x;
	corner4.y = m_pPanel->corners[53].y;

	// Draw rectangle around checkerboard

	line(m_pPanel->m_Image, corner1, corner2, CV_RGB(0, 0, 255), 2);
	line(m_pPanel->m_Image, corner2, corner3, CV_RGB(0, 0, 255), 2);
	line(m_pPanel->m_Image, corner3, corner4, CV_RGB(0, 0, 255), 2);
	line(m_pPanel->m_Image, corner4, corner1, CV_RGB(0, 0, 255), 2);

	circle(m_pPanel->m_Image, corner1, 10, CV_RGB(0, 0, 255), 2);
	circle(m_pPanel->m_Image, corner2, 10, CV_RGB(0, 255, 0), 2);
	circle(m_pPanel->m_Image, corner3, 10, CV_RGB(255, 0, 0), 2);
	circle(m_pPanel->m_Image, corner4, 10, CV_RGB(100, 100, 100), 2);

	double pixel_length = 0;
	double pixel_width = 0;

	double pixel_width1 = norm(corner1 - corner2);
	double pixel_length1 = norm(corner2 - corner3);
	double pixel_width2 = norm(corner3 - corner4);
	double pixel_length2 = norm(corner4 - corner1);

	if (pixel_length1 >= pixel_length2)
		pixel_length = pixel_length1;
	else 
		pixel_length = pixel_length2;

	if (pixel_width1 >= pixel_width2)
		pixel_width = pixel_width1;
	else
		pixel_width = pixel_width2;


	double ratio = (m_pPanel->m_boardLength - 1.0) / (m_pPanel->m_boardWidth - 1.0);

	if (pixel_length >= (pixel_width * ratio)){
		m_pPanel->m_cmPerPixel = (m_pPanel->m_squareSize * (float)(m_pPanel->m_boardLength - 1)) / pixel_length;
	}
	else
		m_pPanel->m_cmPerPixel = (m_pPanel->m_squareSize * (float)(m_pPanel->m_boardWidth - 1)) / pixel_width;

	cout << "cm per pixel : " << m_pPanel->m_cmPerPixel << endl;

	// Perspective Transform
	//	double ratio = 8.0 / 5.0;
	//	double length = ratio * pixel_width;
	//
	//	vector<Point2f> panel_pts;
	//	vector<Point2f> rect_pts;
	//	panel_pts.push_back(corner1);
	//	panel_pts.push_back(corner2);
	//	panel_pts.push_back(corner3);
	//	panel_pts.push_back(corner4);
	//	rect_pts.push_back(Point2f(0, 0));
	//	rect_pts.push_back(Point2f((float)width, 0));
	//	rect_pts.push_back(Point2f((float)width, (float)length));
	//	rect_pts.push_back(Point2f(0, (float)length));
	//
	//	// Draw new rectangle
	//	line(m_pPanel->m_Image, rect_pts[0], rect_pts[1], CV_RGB(255, 0, 0), 2);
	//	line(m_pPanel->m_Image, rect_pts[1], rect_pts[2], CV_RGB(255, 0, 0), 2);
	//	line(m_pPanel->m_Image, rect_pts[2], rect_pts[3], CV_RGB(255, 0, 0), 2);
	//	line(m_pPanel->m_Image, rect_pts[3], rect_pts[0], CV_RGB(255, 0, 0), 2);
	//
	//	// Perspective Transorm
	//	Mat transmtx = getPerspectiveTransform(panel_pts, rect_pts);
	//	int offsetSize = 500;
	//	Mat transformed = Mat::zeros(m_pPanel->m_Image.cols + offsetSize, m_pPanel->m_Image.rows + offsetSize, CV_8UC3);
	//	warpPerspective(m_pPanel->m_Image, transformed, transmtx, transformed.size());
	//
	////	Mat subImg(transformed, Rect(corner1.x, corner1.y, width, length));
	//
	//	namedWindow("Original", WINDOW_NORMAL);
	//	imshow("Original", m_pPanel->m_Image);
	//	namedWindow("Warped", WINDOW_AUTOSIZE);
	//	imshow("Warped", transformed);
}
void CopterTracking::go() {
    Mat lastFrame;
    Mat nextFrame;
    Mat framePause;
    Rect nextBox;
    bool success;
    bool pause;
    // für FPS
    time_t start_t, end_t; int counter = 0; double fps; double sec;
    //bool boxDefined = true;
    //Das Ausgabefenster
    namedWindow("Ausgabe",1);
    //callback für mouse events
    setMouseCallback("Ausgabe",mouseCallback,0);

    //zu Beginn das erste und das zweite Bild speichern
    *input >> lastFrame;
    tld->showFrame = lastFrame.clone();
    *input >> nextFrame;

    //Eingrauen
    cvtColor( lastFrame,lastFrame,CV_BGR2GRAY);
    cvtColor( nextFrame,nextFrame,CV_BGR2GRAY);
    // FPS berechnen
    time(&start_t);
    //Schleife
    while (true)
    {

        //TLD starten, falls eine Box angegeben wurde
        if (boxDefined)
        {
            //Es wurde eine Box definiert, also ist startBox = false;
            startBox = false;
            //Die Box verkleinern
            box.x = ceil(box.x);
            box.y = ceil(box.y);
            box.width = ceil(box.width);
            box.height = ceil(box.height);
            ///Falls tld das erste Mal gestartet wird, muss es initialisiert werden
            if (!tld->isActive) {
                tld->init(lastFrame,box,lastFrame.cols,lastFrame.rows);
            }
        }
        if (tld->isActive && !startBox) {
            success = tld->process(nextFrame,box,nextBox,tld->showFrame);
        } else if (startBox  && box.width > 0 && box.height > 0)
        {
            tld->isActive = false;
            //Die Box muss eine Mindestgröße haben!!!
            if (box.width < MIN_WIDTH || box.height < MIN_HEIGHT)
            {
                 rectangle(tld->showFrame,cvPoint(box.x,box.y),cvPoint(box.x + box.width, box.y + box.height),Scalar(0,0,255),2); //Wenn zu klein, dann ROT
                 boxDefined = false;
            }
            else
            {
                rectangle(tld->showFrame,cvPoint(box.x,box.y),cvPoint(box.x + box.width, box.y + box.height),Scalar(0,255,0),2); //Wenn ok, dann GRÜN
            }
        //Falls nicht gefunden und auch nicht definiert, lösche box und nextBox
        } else {
            //box.x = 0; box.y = 0; box.width = 0; box.height = 0;
            boxDefined = false;
            //nextBox = Rect();
            nextBox = box;
        }
        //Falls tld erfolgreich war, dann zeige box im nextFrame an
        if (success )
        {
            success = false;
            startBox = false;
            boxDefined = true;
            //Die Box vergrößern
            nextBox.x = ceil(nextBox.x);
            nextBox.y = ceil(nextBox.y);
            nextBox.width = ceil(nextBox.width);
            nextBox.height = ceil(nextBox.height);
            //Die Grenzen genau definieren!!! (REICHT DAS SO???)
            //x
            if (nextBox.x < 0) nextBox.x = 0;
            if (nextBox.x >= tld->showFrame.size().width) nextBox.x = tld->showFrame.size().width - 1;
            //y
            if (nextBox.y < 0) nextBox.x = 0;
            if (nextBox.y >= tld->showFrame.size().height) nextBox.y = tld->showFrame.size().height - 1;

            //Die Breite
            if (nextBox.x + nextBox.width > tld->showFrame.size().width) nextBox.width = nextBox.width - (nextBox.x + nextBox.width - tld->showFrame.size().width - 1);
            //Die Höhe
            if (nextBox.y + nextBox.height > tld->showFrame.size().height) nextBox.height = nextBox.height - (nextBox.y + nextBox.height - tld->showFrame.size().height - 1);

            //aktuelle Box setzen
            box = nextBox;
            //Ausgabe
            if (tld->showBoundingBox)
            {
                imshow("Box",tld->showFrame(box));
            }
            if (tld->showCoordinates)
            {
                //Falls eine Box gefunden wurde, dann gebe die Koordinaten aus, falls gewünscht
                char buffer[20];
                sprintf(buffer,"%d, %d",box.x + (box.width / 2), box.y + (box.height / 2));
                putText(tld->showFrame,
                    buffer,
                    Point(box.x + (box.width / 2) + 5, box.y + (box.height / 2)),
                    CV_FONT_HERSHEY_DUPLEX,
                    0.3,
                    Scalar(0, 255, 255)
                );
                 circle(tld->showFrame, Point2f(box.x + (box.width / 2), box.y + (box.height / 2)), 1, Scalar( 0, 0, 255  ), 5);
            } else {
                rectangle(tld->showFrame,cvPoint(nextBox.x,nextBox.y),cvPoint(nextBox.x + nextBox.width, nextBox.y + nextBox.height),Scalar(0,255,0),2);

            }

        }
        // FPS berechnen
        time(&end_t);
        ++counter;
        sec = difftime(end_t,start_t);
        fps = counter/sec;
        char buffer[20];
        sprintf(buffer,"FPS: %.2f",fps);
        putText(tld->showFrame,
            buffer,
            cvPoint(40,40),
            CV_FONT_HERSHEY_DUPLEX,
            0.3,
            Scalar(0, 255, 255)
        );

        //Ausgabe des nextFrame
        imshow("Ausgabe",  tld->showFrame);
        keyPressed = cvWaitKey( 10 );
        //Das Programm verlassen
        if (keyPressed == 27)
        {
            return;
        }

        //An- und Abschalten der Trackerausgabe
        if (keyPressed == '1')
        {
            tld->showTracker = !tld->showTracker;
            if (tld->showTracker && success) namedWindow("Tracker",1);
            else  destroyWindow("Tracker");

        }
        //An- und Abschalten der Detectorausgabe
        if (keyPressed == '2')
        {
            tld->showDetector = !tld->showDetector;
            if (tld->showDetector && success) namedWindow("Detector",1);
            else  destroyWindow("Detector");

        }

        //Anzeigen der erzeugten Beispiele
        if (keyPressed == '4')
        {
            tld->showFernPos = !tld->showFernPos;
            if (tld->showFernPos && success)
            {
                namedWindow("PositiveFerns",1);

            }
            else  destroyWindow("PositiveFerns");

        }

        //Anzeigen der erzeugten Beispiele
        if (keyPressed == '5')
        {
            tld->showNNCPos = !tld->showNNCPos;
            if (tld->showNNCPos && success)
            {
                namedWindow("PositiveNNC",1);

            }
            else  destroyWindow("PositiveNNC");

        }

        //Anzeigen der erzeugten Beispiele
        if (keyPressed == '6')
        {
            tld->showFernNeg = !tld->showFernNeg;
            if (tld->showFernNeg && success)
            {
                namedWindow("NegativeFerns",1);

            }
            else  destroyWindow("NegativeFerns");

        }

        //Anzeigen der erzeugten Beispiele
        if (keyPressed == '7')
        {
            tld->showNNCNeg = !tld->showNNCNeg;
            if (tld->showNNCNeg && success)
            {
                namedWindow("NegativeNNC",1);

            }
            else  destroyWindow("NegativeNNC");

        }
        if ( keyPressed == 'p')
        {
            pause = !pause;
            *input >> framePause;
        }

        //An- und Abschalten der Ausgabe der Positiven Esembler-Boxen
        if (keyPressed == 'h')
        {
            tld->showHull = !tld->showHull;
        }

        //An- und Abschalten des Lernens
        if (keyPressed == 'l')
        {
            tld->doLearn = !tld->doLearn;
        }
        //Anzeigen der stabilisierten BoundingBox
        if (keyPressed == 'b')
        {
            tld->showBoundingBox = !tld->showBoundingBox;
            if (tld->showBoundingBox && success)
            {
                namedWindow("Box",1);

            }
            else  destroyWindow("Box");

        }

        //Ausgabe der Kooridinaten
        if (keyPressed == 'k') {
                tld->showCoordinates = !tld->showCoordinates;
        }

        //Werte aktualisieren
        lastFrame = nextFrame;
        if (!pause) {
            *input >> nextFrame;
        }  else {
void GazeTracker::draw(Mat& image)
{
	Mat faceEyesInfo;
	Mat focus;
	
	double t = (double)cvGetTickCount();//用来计算算法执行时间
	detector.detectFaceAndEyes(image, 1);
	t = (double)cvGetTickCount() - t;//相减为算法执行的时间  
    printf( "detection time = %g ms\n", t/((double)cvGetTickFrequency()*1000.) ); 

	if(detector.isRecorded || detector.isFaceDetected)
	{
		faceEyesInfo = detector.getFaceAndEyePos();
	}
	else
	{
		faceEyesInfo.data = NULL;
	}

	if(isClicked == true)
	{
		float s[1][2];
		s[0][0] = click.x;
		s[0][1] = click.y;
		Mat output(1, 2, CV_32FC1, s);

		if(faceEyesInfo.data == NULL)
		{
			cout << "fail to detect eyes!" << endl;
		}

		else
		{
//			focusFinder.train(faceEyesInfo, SampleTypes::ROW_SAMPLE, output);
//			cout << "eyes detected and trained!" << endl;
//			focusFinder.save(MODULEPATH);

			//写入记录
			recorder << detector.faceCenter.x << ' ' << detector.faceCenter.y << ' '
					 << detector.faceSize.x << ' '
					 << detector.leftEyeCenter.x << ' ' << detector.leftEyeCenter.y << ' '
					 << detector.leftEyeSize.x << ' '
					 << detector.rightEyeCenter.x << ' ' << detector.rightEyeCenter.y << ' '
					 << detector.rightEyeSize.x << ' ' 
					 << s[0][0] << ' ' << s[0][1] << endl;

			cout << detector.faceCenter.x << ' ' << detector.faceCenter.y << ' '
				 << detector.faceSize.x << ' '
				 << detector.leftEyeCenter.x << ' ' << detector.leftEyeCenter.y << ' '
				 << detector.leftEyeSize.x << ' '
				 << detector.rightEyeCenter.x << ' ' << detector.rightEyeCenter.y << ' '
				 << detector.rightEyeSize.x << ' ' 
				 << s[0][0] << ' ' << s[0][1] << endl;

		}
	}

	isClicked = false;

	if(detector.isRecorded)
	{
		int faceRadius, leftEyeRadius, rightEyeRadius;

		faceRadius = 1;
		circle(image, Point(detector.faceCenter.x, detector.faceCenter.y),
				faceRadius, CV_RGB(0,0,255), 3, 8, 0);

		leftEyeRadius = (detector.leftEyeSize.x + detector.leftEyeSize.y) / 3;
		leftEyeRadius = 1;
		circle(image, Point(detector.leftEyeCenter.x, detector.leftEyeCenter.y),
				leftEyeRadius, CV_RGB(0,0,255), 3, 8, 0);

		rightEyeRadius = (detector.rightEyeSize.x + detector.rightEyeSize.y) / 3;
		rightEyeRadius = 1;
		circle(image, Point(detector.rightEyeCenter.x, detector.rightEyeCenter.y),
				rightEyeRadius, CV_RGB(0,0,255), 3, 8, 0);
	}

	else if(detector.isFaceDetected)
	{
		int faceRadius = (detector.faceSize.x + detector.faceSize.y) / 3;
		circle(image, Point(detector.faceCenter.x, detector.faceCenter.y),
				faceRadius, CV_RGB(0,0,255), 3, 8, 0);
	}

	Mat bigImg(800, 1100, CV_8UC3);
	resize(image, bigImg, bigImg.size());
	imshow(windowName, bigImg);
	waitKey(1);
	
}
vector<Plate> DetectRegions::segment(Mat input){
    vector<Plate> output;

    //convert image to gray
    Mat img_gray;
    cvtColor(input, img_gray, CV_BGR2GRAY);
    blur(img_gray, img_gray, Size(5,5));

    //Finde vertical lines. Car plates have high density of vertical lines
    Mat img_sobel;
    Sobel(img_gray, img_sobel, CV_8U, 1, 0, 3, 1, 0, BORDER_DEFAULT);
    if(showSteps)
        imshow("Sobel", img_sobel);

    //threshold image
    Mat img_threshold;
    threshold(img_sobel, img_threshold, 0, 255, CV_THRESH_OTSU+CV_THRESH_BINARY);
    if(showSteps)
        imshow("Threshold", img_threshold);

    //Morphplogic operation close
    Mat element = getStructuringElement(MORPH_RECT, Size(17, 3) );
    morphologyEx(img_threshold, img_threshold, CV_MOP_CLOSE, element);
    if(showSteps)
        imshow("Close", img_threshold);

    //Find contours of possibles plates
    vector< vector< Point> > contours;
    findContours(img_threshold,
            contours, // a vector of contours
            CV_RETR_EXTERNAL, // retrieve the external contours
            CV_CHAIN_APPROX_NONE); // all pixels of each contours

    //Start to iterate to each contour founded
    vector<vector<Point> >::iterator itc= contours.begin();
    vector<RotatedRect> rects;

    //Remove patch that are no inside limits of aspect ratio and area.
    while (itc!=contours.end()) {
        //Create bounding rect of object
        RotatedRect mr= minAreaRect(Mat(*itc));
        if( !verifySizes(mr)){
            itc= contours.erase(itc);
        }else{
            ++itc;
            rects.push_back(mr);
        }
    }

    // Draw blue contours on a white image
    cv::Mat result;
    input.copyTo(result);
    cv::drawContours(result,contours,
            -1, // draw all contours
            cv::Scalar(255,0,0), // in blue
            1); // with a thickness of 1

    for(int i=0; i< (int)rects.size(); i++){

        //For better rect cropping for each posible box
        //Make floodfill algorithm because the plate has white background
        //And then we can retrieve more clearly the contour box
        circle(result, rects[i].center, 3, Scalar(0,255,0), -1);
        //get the min size between width and height
        float minSize=(rects[i].size.width < rects[i].size.height)?rects[i].size.width:rects[i].size.height;
        minSize=minSize-minSize*0.5;
        //initialize rand and get 5 points around center for floodfill algorithm
        //srand ( time(NULL) );
        //Initialize floodfill parameters and variables
        Mat mask;
        mask.create(input.rows + 2, input.cols + 2, CV_8UC1);
        mask= Scalar::all(0);
        int loDiff = 30;
        int upDiff = 30;
        int connectivity = 4;
        int newMaskVal = 255;
        int NumSeeds = 10;
        Rect ccomp;
        int flags = connectivity + (newMaskVal << 8 ) + CV_FLOODFILL_FIXED_RANGE + CV_FLOODFILL_MASK_ONLY;
        for(int j=0; j<NumSeeds; j++){
            Point seed;
            seed.x=rects[i].center.x+rand()%(int)minSize-(minSize/2);
            seed.y=rects[i].center.y+rand()%(int)minSize-(minSize/2);
            circle(result, seed, 1, Scalar(0,255,255), -1);
            floodFill(input, mask, seed, Scalar(255,0,0), &ccomp, Scalar(loDiff, loDiff, loDiff), Scalar(upDiff, upDiff, upDiff), flags);
        }
        if(showSteps)
            imshow("MASK", mask);
        //cvWaitKey(0);

        //Check new floodfill mask match for a correct patch.
        //Get all points detected for get Minimal rotated Rect
        vector<Point> pointsInterest;
        Mat_<uchar>::iterator itMask= mask.begin<uchar>();
        Mat_<uchar>::iterator end= mask.end<uchar>();
        for( ; itMask!=end; ++itMask)
            if(*itMask==255)
                pointsInterest.push_back(itMask.pos());

        RotatedRect minRect = minAreaRect(pointsInterest);

        if(verifySizes(minRect)){
            // rotated rectangle drawing
            Point2f rect_points[4]; minRect.points( rect_points );
            for( int j = 0; j < 4; j++ )
                line( result, rect_points[j], rect_points[(j+1)%4], Scalar(0,0,255), 1, 8 );

            //Get rotation matrix
            float r= (float)minRect.size.width / (float)minRect.size.height;
            float angle=minRect.angle;
            if(r<1)
                angle=90+angle;
            Mat rotmat= getRotationMatrix2D(minRect.center, angle,1);

            //Create and rotate image
            Mat img_rotated;
            warpAffine(input, img_rotated, rotmat, input.size(), CV_INTER_CUBIC);

            //Crop image
            Size rect_size=minRect.size;
            if(r < 1)
                swap(rect_size.width, rect_size.height);
            Mat img_crop;
            getRectSubPix(img_rotated, rect_size, minRect.center, img_crop);

            Mat resultResized;
            resultResized.create(33,144, CV_8UC3);
            resize(img_crop, resultResized, resultResized.size(), 0, 0, INTER_CUBIC);
            //Equalize croped image
            Mat grayResult;
            cvtColor(resultResized, grayResult, CV_BGR2GRAY);
            blur(grayResult, grayResult, Size(3,3));
            grayResult=histeq(grayResult);
            if(saveRegions){
                stringstream ss(stringstream::in | stringstream::out);
                ss << ".\\output\\possible_plates\\" << filename << "_" << i << ".JPG";
                imwrite(ss.str(), grayResult);
            }
            output.push_back(Plate(grayResult,minRect.boundingRect()));
        }
    }
    if(showSteps)
        imshow("Contours", result);

    return output;
}
void main5()
{
int gd=DETECT,gm=0,col=0,dol=600;
initgraph(&gd,&gm,"c:/tc/bgi");

settextstyle(10,HORIZ_DIR,1);
outtextxy(30,30,"");
settextstyle(11,HORIZ_DIR,1);
settextstyle(10,HORIZ_DIR,1);
outtextxy(30,200,"Hit ENTER to Start the Magic...");
settextstyle(12,HORIZ_DIR,1);
getch();
cleardevice();

while(!kbhit())
{
for(int j=0;j<=50;j++)
{
{
setcolor(2);
circle(col,100,50+j);
setfillstyle(4,2);
floodfill(col,100,2);
delay(3);
col++;
if(col>=600)
col=0;
}


 {
setcolor(4);
circle(dol,330,50+j);
setfillstyle(5,4);
floodfill(dol,330,4);
delay(3);
dol--;
if(dol<=0)
dol=600;
}


for(int i=1;i<=15;i++)
{
if(col==200)
{
setbkcolor(random(i));
}
if(col==400)
{
setbkcolor(random(i));
}
}//for inner close
}//for outer loop

for(int k=1;k<=120;k++)
{
setcolor(random(15));
circle(300,250,1+k);
delay(1);

}

cleardevice();

}
closegraph();
getch();

}
Exemple #10
0
int main(int argc, char* argv[])
{
	// Get device singleton instance.
	auto device = RenderDevice::getInstance();
	
	auto input = InputManager::getInstance();
	
	device->init();
	
	Text text(20.0f);
	
	text.setPosition(0, 30);
	text.setColor(Color::White);
	text.setLineWidth(BOTTOM_SCREEN_WIDTH);
	
	std::string str =
			"Press A to take a screenshot of top screen.\n\n"
			"Press B to take a screenshot of bottom screen.\n";
	
	text.setString(str);
	
	// Setup a basic scene
	CircleShape circle(60);
	circle.setPosition(100, 50);
	circle.setColor(Color::Yellow);
	
	circle.setSegments(20);
	
	TriangleShape triangle(Vec2(110, 60), Vec2(140, 10), Vec2(180, 60));
	triangle.setColor(Color::Red);
	
	// Main loop
	while(device->isRunning())
	{
		if(input->isKeyDown(Keys::A))
		{
			device->takeScreenshot("top.png", ImageFormat::Png, Screen::Top);
		}
		else if(input->isKeyDown(Keys::B))
		{
			device->takeScreenshot("bot.png", ImageFormat::Png, Screen::Bottom);
		}
		
		if(input->isKeyDown(Keys::Start))
		{
			device->quit();
		}
		
		triangle.setScale((float)std::sin(device->getTicks()));
		circle.setAngle(circle.getAngle() + 20.0f * device->getDeltaTime());
		
		device->setTargetScreen(Screen::Top);
		device->clear(Color::Cyan);
		device->startFrame();
		circle.draw();
		triangle.draw();
		device->endFrame();
		
		device->setTargetScreen(Screen::Bottom);
		device->clear(Color::Black);
		device->startFrame();
		text.draw();
		device->endFrame();
		
		device->swapBuffers();
	}
	
	// DON'T FORGET TO CALL THIS OR THE 3DS WILL CRASH AT EXIT
	device->destroy();
	
	return 0;
}