⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 videodlg.cpp

📁 本程序是2005年参加中国机器人大赛的比赛程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
													int tempMain,len=1000;
													int k=-1;
													for (int f=0;f<3;f++)
													{
													if (len>((tempCentreGravity[0]-tempCentre[f][0])*(tempCentreGravity[0]-tempCentre[f][0])+
														(tempCentreGravity[1]-tempCentre[f][1])*(tempCentreGravity[1]-tempCentre[f][1])))
													{
														len=(tempCentreGravity[0]-tempCentre[f][0])*(tempCentreGravity[0]-tempCentre[f][0])+
														(tempCentreGravity[1]-tempCentre[f][1])*(tempCentreGravity[1]-tempCentre[f][1]);
														tempMain=f;
													}//end if
													}//end for
													CPoint temp;												
														if(tempMain==0)
														{
															k=whichNum(tempCentre[0][2],tempCentre[1][2],
																		tempCentre[2][2]);
															temp.x=(tempCentre[1][1]+tempCentre[2][1])/2;
															temp.y=(tempCentre[1][0]+tempCentre[2][0])/2;
															My_LableCentreGravity[k][0] = tempCentreGravity[0];
															My_LableCentreGravity[k][1] = tempCentreGravity[1];
															My_CentreGravity[k][0] =tempCentre[0][0];
															My_CentreGravity[k][1] = tempCentre[0][1];	
															setPlayer(tempCentreGravity[1],
																		tempCentreGravity[0],
																		tempCentre[0][1],
																		tempCentre[0][0],
																		temp.x,
																		temp.y,
																		k);		
														}
														if(tempMain==1)
														{
															k=whichNum(tempCentre[1][2],
																		tempCentre[0][2],
																		tempCentre[2][2]);
															temp.x=(tempCentre[0][1]+tempCentre[2][1])/2;
															temp.y=(tempCentre[0][0]+tempCentre[2][0])/2;
															My_LableCentreGravity[k][0] = tempCentreGravity[0];
															My_LableCentreGravity[k][1] = tempCentreGravity[1];
															My_CentreGravity[k][0] =tempCentre[1][0];
															My_CentreGravity[k][1] = tempCentre[1][1];	
															setPlayer(tempCentreGravity[1],
																		tempCentreGravity[0],
																		tempCentre[1][1],
																		tempCentre[1][0],
																		temp.x,
																		temp.y,
																		k);		
														}
														if(tempMain==2)
														{
															k=whichNum(tempCentre[2][2],
																		tempCentre[1][2],
																		tempCentre[0][2]);
															temp.x=(tempCentre[1][1]+tempCentre[0][1])/2;
															temp.y=(tempCentre[1][0]+tempCentre[0][0])/2;
															My_LableCentreGravity[k][0] = tempCentreGravity[0];
															My_LableCentreGravity[k][1] = tempCentreGravity[1];
															My_CentreGravity[k][0] =tempCentre[2][0];
															My_CentreGravity[k][1] = tempCentre[2][1];	
															setPlayer(tempCentreGravity[1],
																		tempCentreGravity[0],
																		tempCentre[2][1],
																		tempCentre[2][0],
																		temp.x,
																		temp.y,
																		k);		
														}	
														m_lable1x=tempCentre[0][1];
														m_lable1y=tempCentre[0][0];
														m_lable2x=tempCentre[1][1];
														m_lable2y=tempCentre[1][0];
														m_lable3x=tempCentre[2][1];
														m_lable3y=tempCentre[2][0];
														m_angle=g_MyTeam[k+1].Get_m_Angle();
														m_k=tempMain+1;
														UpdateData(false);

														k=-1;
													/***********************
													setPlayer(tempCentreGravity[1],
													tempCentreGravity[0],
													temp.x,
													temp.y,
													k);		***********/											
												MyLableRectNum++;//表示第几个我队队员
												ObjectRectNum++;	
												isScanMyteam[k]=true;																			
												ObjectRect[ObjectRectNum-1].left = tempCentreGravity[1]-2*m_pConfigDlg->m_ObjectDia;
												ObjectRect[ObjectRectNum-1].right = tempCentreGravity[1]+2*m_pConfigDlg->m_ObjectDia;
												ObjectRect[ObjectRectNum-1].top = tempCentreGravity[0]-2*m_pConfigDlg->m_ObjectDia;
												ObjectRect[ObjectRectNum-1].bottom = tempCentreGravity[0]+2*m_pConfigDlg->m_ObjectDia;
												
												m=tempCentreGravity[1]+2*m_pConfigDlg->m_ObjectDia;
												l=tempCentreGravity[0]+2*m_pConfigDlg->m_ObjectDia;			
												}//end lable==3

										/*if (myone)
											{
												MyLableRectNum++;//表示第几个我队队员
												ObjectRectNum++;
												myone=false;int k;
												k=-1;
												
												if(ObjectRectNum > 11)
													ObjectRectNum = 11;
												if ((num==1)&&(num2==1)&&(!isScanMyteam[0])) k=0;
												if ((num==2)&&(num2==2)&&(!isScanMyteam[1])) k=1;
												if ((num==3)&&(num2==3)&&(!isScanMyteam[2])) k=2;
												if ((num==1)&&(num2==2)&&(!isScanMyteam[3])) k=3;
												if ((num==2)&&(num2==1)&&(!isScanMyteam[3])) k=3;
												if ((num==3)&&(num2==1)&&(!isScanMyteam[4])) k=4;
												if ((num==1)&&(num2==3)&&(!isScanMyteam[4])) k=4;
												if ((k<0)||(k>5))  break;
											//	if ((num==0)&&(num2==2)) k=5;
											//	if ((num==2)&&(num2==0)) k=5;
												CPoint temp;
												temp.x=(tempCentreGravity2[1]+tempCentreGravity3[1])/2;
												temp.y=(tempCentreGravity2[0]+tempCentreGravity3[0])/2;
												My_LableCentreGravity[k][0] = tempCentreGravity[0];
												My_LableCentreGravity[k][1] = tempCentreGravity[1];
												My_CentreGravity[k][0] = tempCentreGravity2[0];
												My_CentreGravity[k][1] = tempCentreGravity2[1];			
												setPlayer(tempCentreGravity[1],
													tempCentreGravity[0],
													temp.x,
													temp.y,
													k);
												isScanMyteam[k]=true;
												k=-1;
																			
												ObjectRect[ObjectRectNum-1].left = tempCentreGravity[1]-2*m_pConfigDlg->m_ObjectDia;
												ObjectRect[ObjectRectNum-1].right = tempCentreGravity[1]+2*m_pConfigDlg->m_ObjectDia;
												ObjectRect[ObjectRectNum-1].top = tempCentreGravity[0]-2*m_pConfigDlg->m_ObjectDia;
												ObjectRect[ObjectRectNum-1].bottom = tempCentreGravity[0]+2*m_pConfigDlg->m_ObjectDia;
												
												m=tempCentreGravity[1]+2*m_pConfigDlg->m_ObjectDia;
												l=tempCentreGravity[0]+2*m_pConfigDlg->m_ObjectDia;
												ScanRect3.left = 0;
												ScanRect3.top = 0;
												ScanRect3.right = 0;
												ScanRect3.bottom = 0;
											}
											else
											{
												ScanRect3.left = tempCentreGravity2[1] - m_pConfigDlg->m_ObjectDia/2;
												ScanRect3.top = tempCentreGravity2[0]-m_pConfigDlg->m_ObjectDia/2;
												ScanRect3.right = tempCentreGravity2[1] +m_pConfigDlg->m_ObjectDia/2;
												ScanRect3.bottom = tempCentreGravity2[0] + m_pConfigDlg->m_ObjectDia/2;
												tempCentreGravity3[1]=tempCentreGravity2[1];
												tempCentreGravity3[0]=tempCentreGravity2[0];
												m=tempCentreGravity3[1]+m_pConfigDlg->m_ObjectDia/2;
												myone = true;
												num2=num;
											}//end myone*/
										}//end ScanNearRect
								   }
								}//end if 
							}//end for						
					}//end MyLableRectNum			
				}//end if ScanNearRect
			  }
			}//end //识别我队标志			
			//else if(IsMeetRestrict(Col_YUV, m_pConfigDlg->m_upper_TheirTeamLable, m_pConfigDlg->m_lower_TheirTeamLable))
			else if(YUVClass[Col_YUV[2]][5][2]
			      &&YUVClass[Col_YUV[1]][5][1]
			      &&YUVClass[Col_YUV[0]][5][0])	
			{//识别他队标志
				int tempCentreGravity[2];
				ScanRect.left = i - m_pConfigDlg->m_ObjectDia;
				ScanRect.top = j-m_pConfigDlg->m_ObjectDia/2;
				ScanRect.right = i + m_pConfigDlg->m_ObjectDia;
				ScanRect.bottom = j + m_pConfigDlg->m_ObjectDia;
				if( ScanNearRect(ScanRect,
					 thlable_Percent,
					 m_pConfigDlg->m_upper_TheirTeamLable,
					 m_pConfigDlg->m_lower_TheirTeamLable,
					 tempCentreGravity
					 ,5) )
					{
						if (their_yellow)
						{
							bool isexit;
							bool isexit2;
							ScanRect2.left = tempCentreGravity[1]-3/2*m_pConfigDlg->m_ObjectDia;
							ScanRect2.top = tempCentreGravity[0]-3/2*m_pConfigDlg->m_ObjectDia;
							ScanRect2.right =tempCentreGravity[1]+3/2*m_pConfigDlg->m_ObjectDia;
							ScanRect2.bottom =tempCentreGravity[0]+3/2*m_pConfigDlg->m_ObjectDia;
							isexit=rectExist(m_pConfigDlg->m_upper_TheirTeam[0],m_pConfigDlg->m_lower_TheirTeam[0],ScanRect2,6);
							isexit2=false;
						//	isexit2=rectExist(m_pConfigDlg->m_upper_TheirTeam[0],m_pConfigDlg->m_lower_TheirTeam[0],ScanRect2,7);
					
							if (isexit||isexit2)
							{
								if(TheirLableRectNum < 5)
								{
								TheirLableRectNum++;
								ObjectRectNum++;
								if(ObjectRectNum > 11)
								ObjectRectNum = 11;
								isScanTheirteam[TheirLableRectNum-1]=true;
								Their_LableCentreGravity[TheirLableRectNum-1][0] = tempCentreGravity[0];
								Their_LableCentreGravity[TheirLableRectNum-1][1] = tempCentreGravity[1];
								g_TheirTeam[TheirLableRectNum-1].Set_vPos(Vector(Their_LableCentreGravity[TheirLableRectNum-1][1]-m_FieldRect.left,m_FieldRect.bottom-Their_LableCentreGravity[TheirLableRectNum-1][0]));
								ObjectRect[ObjectRectNum-1].left = tempCentreGravity[1]-2*m_pConfigDlg->m_ObjectDia;
								ObjectRect[ObjectRectNum-1].right = tempCentreGravity[1]+2*m_pConfigDlg->m_ObjectDia;
								ObjectRect[ObjectRectNum-1].top = tempCentreGravity[0]-2*m_pConfigDlg->m_ObjectDia;
								ObjectRect[ObjectRectNum-1].bottom = tempCentreGravity[0]+2*m_pConfigDlg->m_ObjectDia;
								}
							}
						}
						else
						{
							if(TheirLableRectNum < 5)
							{
							TheirLableRectNum++;
							ObjectRectNum++;
							if(ObjectRectNum > 11)
							 ObjectRectNum = 11;
							Their_LableCentreGravity[TheirLableRectNum-1][0] = tempCentreGravity[0];
							Their_LableCentreGravity[TheirLableRectNum-1][1] = tempCentreGravity[1];
							g_TheirTeam[TheirLableRectNum-1].Set_vPos(Vector(Their_LableCentreGravity[TheirLableRectNum-1][1]-m_FieldRect.left,m_FieldRect.bottom-Their_LableCentreGravity[TheirLableRectNum-1][0]));
							ObjectRect[ObjectRectNum-1].left = tempCentreGravity[1]-2*m_pConfigDlg->m_ObjectDia;
							ObjectRect[ObjectRectNum-1].right = tempCentreGravity[1]+2*m_pConfigDlg->m_ObjectDia;
							ObjectRect[ObjectRectNum-1].top = tempCentreGravity[0]-2*m_pConfigDlg->m_ObjectDia;
							ObjectRect[ObjectRectNum-1].bottom = tempCentreGravity[0]+2*m_pConfigDlg->m_ObjectDia;
							}
						}		
					}
			}//识别他队标志
		//	else if(IsMeetRestrict(Col_YUV,m_pConfigDlg->m_upper_Ball, m_pConfigDlg->m_lower_Ball))
			else if(YUVClass[Col_YUV[2]][4][2]
			      &&YUVClass[Col_YUV[1]][4][1]
			      &&YUVClass[Col_YUV[0]][4][0])
			{//识别球
				int tempCentreGravity[2];
				ScanRect.left = i - m_pConfigDlg->m_ObjectDia;
				ScanRect.top = j;
				ScanRect.right = i + m_pConfigDlg->m_ObjectDia;
				ScanRect.bottom = j + m_pConfigDlg->m_ObjectDia;
				if( ScanNearRect(ScanRect, 
							 ball_Percent,
							 m_pConfigDlg->m_upper_Ball,
							 m_pConfigDlg->m_lower_Ball,
							 tempCentreGravity,
							 4) )
					{
					//	if (isBall(tempCentreGravity))
					//	{
							if(0 == BallRectNum)
							{
								if (tempCentreGravity)
								BallRectNum = 1;
								ObjectRectNum++;
								if(ObjectRectNum > 11)
								ObjectRectNum = 11;
								Ball_CentreGravity[BallRectNum-1][0] = tempCentreGravity[0];
								Ball_CentreGravity[BallRectNum-1][1] = tempCentreGravity[1];
								ObjectRect[ObjectRectNum-1] = ScanRect;
								isScanBall=true;
								Vector tempPos;	
								double dist;
								tempPos.x = tempCentreGravity[1];//x==>1
								tempPos.y = tempCentreGravity[0];//y==>0
								dist = tempPos.dist(g_Ball.Get_vPos());
								Vector temp;
								temp.x=tempPos.x-m_FieldRect.left;
								temp.y=m_FieldRect.bottom-tempPos.y;
								g_Ball.Set_vPos(temp);
	
							}
					//	}
					}
				//	if(ObjectRectNum = 11) return;
			}//识别球
	}
		/////////////////////////////////输出球的位置/////////////////////////////////
/***
		flag=FALSE;
	//识别我方球门员
	for(j = my_Door.top; j < my_Door.bottom; j++)
		for(i = my_Door.left; i < my_Door.right; i+=2)		
		{	
			GetPixelColor(i, j, Get_RGB);
			RGB_TO_YUV(Get_RGB,Col_YUV);
			if(YUVClass[Col_YUV[2]][0][2]
			      &&YUVClass[Col_YUV[1]][0][1]
			      &&YUVClass[Col_YUV[0]][0][0])
			{//识别我队标志
				GetPixelColor(i+1, j, Get_RGB);
				RGB_TO_YUV(Get_RGB,Col_YUV);
				if(YUVClass[Col_YUV[2]][0][2]
			      &&YUVClass[Col_YUV[1]][0][1]
			      &&YUVClass[Col_YUV[0]][0][0])
				{
				int tempCentreGravity[2];
				int tempCentreGravity2[2];
				int tempCentreGravity3[2];
				ScanRect.left = i - m_pConfigDlg->m_ObjectDia/2;
				ScanRect.top = j- m_pConfigDlg->m_ObjectDia/2;
				ScanRect.right = i + m_pConfigDlg->m_ObjectDia;
				ScanRect.bottom = j + m_pConfigDlg->m_ObjectDia;
				if( ScanNearRect(ScanRect, 
								 m_pConfigDlg->m_ObjectPercent,
								 m_pConfigDlg->m_upper_MyTeamLable,
								 m_pConfigDlg->m_lower_MyTeamLable,
								 tempCentreGravity,
								 0) )
				{
					for(l=tempCentreGravity[0]-2*m_pConfigDlg->m_ObjectDia;l<tempCentreGravity[0]+2*m_pConfigDlg->m_ObjectDia;l++)
						for(m=tempCentreGravity[1]-2*m_pConfigDlg->m_ObjectDia;m<tempCentreGravity[1]+2*m_pConfigDlg->m_ObjectDia;m++)							
							{									 
								if(isInRect(m,l,ScanRect3))
									 continue;
								GetPixelColor(m, l, Get_RGB);
								RGB_TO_YUV(Get_RGB,Col_YUV);
								if((YUVClass[Col_YUV[2]][1][2]&&YUVClass[Col_YUV[1]][1][1]&&YUVClass[Col_YUV[0]][1][0])
									||(YUVClass[Col_YUV[2]][3][2]&&YUVClass[Col_YUV[1]][3][1]&&YUVClass[Col_YUV[0]][3][0]))									
								{	
								   GetPixelColor(m+1, l, Get_RGB);
								   RGB_TO_YUV(Get_RGB,Col_YUV);
								   if((YUVClass[Col_YUV[2]][1][2]&&YUVClass[Col_YUV[1]][1][1]&&YUVClass[Col_YUV[0]][1][0])
									   ||(YUVClass[Col_YUV[2]][3][2]&&YUVClass[Col_YUV[1]][3][1]&&YUVClass[Col_YUV[0]][3][0]))
								   {
									if (YUVClass[Col_YUV[2]][1][2]
									&&YUVClass[Col_YUV[1]][1][1]
									&&YUVClass[Col_YUV[0]][1][0])									
									num=1;
									if (YUVClass[Col_YUV[2]][2][2]
									&&YUVClass[Col_YUV[1]][2][1]
									&&YUVClass[Col_YUV[0]][2][0])									
									num=2;
									if (YUVClass[Col_YUV[2]][3][2]
									&&YUVClass[Col_YUV[1]][3][1]
									&&YUVClass[Col_YUV[0]][3][0])								
									num=3;									
									ScanRect2.left = m - m_pConfigDlg->m_ObjectDia;
									ScanRect2.top = l;
									ScanRect2.right = m + m_pConfigDlg->m_ObjectDia;
									ScanRect2.bottom = l + m_pConfigDlg->m_ObjectDia;
									if(ScanNearRect(ScanRect2, 											
											 m_pConfigDlg->m_ObjectPercent,
											 m_pConfigDlg->m_upper_MyTeam[k],
											 m_pConfigDlg->m_lower_MyTeam[k],
											 tempCentreGravity2
											 ,
											 num) )
										{
											if (myone)
											{
												MyLableRectNum++;//表示第几个我队队员
												ObjectRectNum++;
												myone=false;int k;
												k=-1;
												
												if(ObjectRectNum > 11)
													ObjectRectNum = 11;
												if ((num==3)&&(num2==1)&&(!isScanMyteam[4])) k=4;
												if ((num==1)&&(num2==3)&&(!isScanMyteam[4])) k=4;
												if ((k<0)||(k>5))  break;
											//	if ((num==0)&&(num2==2)) k=5;
											//	if ((num==2)&&(num2==0)) k=5;
												CPoint temp;
												temp.x=(tempCentreGravity2[1]+tempCentreGravity3[1])/2;
												temp.y=(tempCentreGravity2[0]+tempCentreGravity3[0])/2;
												My_LableCentreGravity[k][0] = tempCentreGravity[0];
												My_LableCentreGravity[k][1] = tempCentreGravity[1];
												My_CentreGravity[k][0] = tempCentreGravity2[0];
												My_CentreGravity[k][1] = tempCentreGravity2[1];			
												setPlayer(tempCentreGravity[1],
													tempCentreGravity[0],
													temp.x,
													temp.y,
													k);
												isScanMyteam[k]=true;
												k=-1;
																			
												ObjectRect[ObjectRectNum-1].left = tempCentreGravity[1]-2*m_pConfigDlg->m_ObjectDia;
												ObjectRect[ObjectRectNum-1].right = tempCentreGravity[1]+2*m_pConfigDlg->m_ObjectDia;
												ObjectRect[ObjectRectNum-1].top = tempCentreGravity[0]-2*m_pConfigDlg->m_ObjectDia;
												ObjectRect[ObjectRectNum-1].bottom = tempCentreGravity[0]+2*m_pConfigDlg->m_ObjectDia;
												ScanRect3.left = 0;
												ScanRect3.top = 0;
												ScanRect3.right = 0;
												ScanRect3.bottom = 0;																							
												break;
											}
											else
											{
												ScanRect3.left = tempCentreGravity2[1] - m_pConfigDlg->m_ObjectDia/2;
												ScanRect3.top = tempCentreGravity2[0]-m_pConfigDlg->m_ObjectDia/2;
												ScanRect3.right = tempCentreGravity2[1] +m_pConfigDlg->m_ObjectDia/2;
												ScanRect3.bottom = tempCentreGravity2[0] + m_pConfigDlg->m_ObjectDia/2;
												tempCentreGravity3[1]=tempCentreGravity2[1];
												tempCentreGravity3[0]=tempCentreGravity2[0];
												m=tempCentreGravity3[1]+m_pConfigDlg->m_ObjectDia/2;
												myone = true;
												num2=num;
											}//end myone
										}//end ScanNearRect
								   }
								}//end if 
								}
						}

					
				}
			}
		}
	//识别对方球门员
	for(j = th_Door.top; j < th_Door.bottom; j++)
		for(i = th_Door.left; i < th_Door.right; i+=2)		
		{	
			GetPixelColor(i, j, Get_RGB);
			RGB_TO_YUV(Get_RGB,Col_YUV);
			if(YUVClass[Col_YUV[2]][5][2]
			      &&YUVClass[Col_YUV[1]][5][1]
			      &&YUVClass[Col_YUV[0]][5][0])	
			{//识别他队标志
				int tempCentreGravity[2];
				ScanRect.left = i - m_pConfigDlg->m_ObjectDia;
				ScanRect.top = j-m_pConfigDlg->m_ObjectDia/2;
				ScanRect.right = i + m_pConfigDlg->m_ObjectDia;
				ScanRect.bottom = j + m_pConfigDlg->m_ObjectDia;
				if( ScanNearRect(ScanRect, 																				 m_pConfigDlg->m_ObjectPercent,
					 m_pConfigDlg->m_upper_TheirTeamLable,
					 m_pConfigDlg->m_lower_TheirTeamLable,
					 tempCentreGravity
					

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -