void CSceneManager::Update_() { // トランジションが生成されていれば、シーン遷移関数を呼ぶ if(CTransition::IsExistTransition()) TransitionScene(); // 現在のシーンの更新呼び出し Scene->updateScene(); }
HRESULT CTrafficLightImpl::RecognizeTrafficLight(HV_COMPONENT_IMAGE* pSceneImage, int* iCurrentStatus, int* iLastStatus, bool fNight) { if (m_tlpTrafficLightParam.iLightGroupCount <= 0) return S_FALSE; HRESULT hResult = S_FALSE; static int nSceneStatusPos= 0; LIGHT_TEAM_STATUS ltsInfo; ltsInfo.nTeamCount = m_tlpTrafficLightParam.iLightGroupCount; bool fDynamic = false; static int iSkipFrameNo = m_tlpTrafficLightParam.iSkipFrameNo; for(int i = 0; i<m_tlpTrafficLightParam.iLightGroupCount; i++) { if (m_tlpTrafficLightParam.iCheckType == 0) { //红绿灯识别 if (iSkipFrameNo == 0 && m_tlpTrafficLightParam.iAutoScanLight == 1) { m_rgLightInfo[i].UpdateStatus3( pSceneImage , fNight); m_rgLightRect[i] = m_rgLightInfo[i].GetRect(); m_rgLightStatus[i] = m_rgLightInfo[i].GetLastStatus(); fDynamic = true; } else { m_rgLightInfo[i].UpdateStatus( pSceneImage ); m_rgLightRect[i] = m_rgLightInfo[i].GetRect(); m_rgLightStatus[i] = m_rgLightInfo[i].GetLastStatus(); } sv::utTrace("<123dsp light>status:%08x.", m_rgLightStatus[i]); } else { if (m_pCallback == NULL) { return E_FAIL; } m_rgLightRect[i] = m_rgLightInfo[i].GetRect(); BYTE8 bLevel = 0; if (S_OK != m_pCallback->GetTrafficLightStatus(&bLevel)) { return E_FAIL; } m_rgLightStatus[i] = GetIOStatus(i, bLevel); } m_rgLightInfo[i].m_iRedLightCountFinded = 0; m_rgLightInfo[i].m_iGreenLightCountFinded = 0; ltsInfo.pdwStatus[i] = m_rgLightStatus[i]; ltsInfo.pnLightCount[i] = m_rgLightInfo[i].GetPosCount(); //传检测到的灯传出去显示 if(m_pCallback) { m_pCallback->TrafficLightStatusEx( i, m_rgLightInfo[i].m_iRedLightCountFinded, m_rgLightInfo[i].m_rcRedLightPosFinded, m_rgLightInfo[i].m_iGreenLightCountFinded, m_rgLightInfo[i].m_rcGreenLightPosFinded ); } } if (iSkipFrameNo <= 0) { iSkipFrameNo = m_tlpTrafficLightParam.iSkipFrameNo; } else { iSkipFrameNo--; } //取得当前场景 bool fFlag = (m_tlpTrafficLightParam.iSceneCheckMode == 0); int nCurScene = TransitionScene(ltsInfo, m_tlpTrafficLightParam.iSceneCount, m_iLastOkLightStatus, fFlag); sv::utTrace("<123dsp light>CurScene:%08x.", nCurScene); //调整发送出去的红灯的坐标 if (m_tlpTrafficLightParam.iAutoScanLight == 1 && fDynamic) { ////更新最后可正常识别的灯组的位置 if (nCurScene != -1) { for (int i = 0; i < m_tlpTrafficLightParam.iLightGroupCount; i++) { m_rgLightInfo[i].UpdateLastSureLight(m_rgLightInfo[i].GetRect()); } } else { //处于中间状态时,则将灯红坐标还原回最后可识别出的状态 for (int i = 0; i < m_tlpTrafficLightParam.iLightGroupCount; i++) { m_rgLightInfo[i].SetRect(m_rgLightInfo[i].GetLastSureLight(), m_rgLightInfo[i].GetPosCount(), m_rgLightInfo[i].GetLightDirection()); } } //更新红灯的坐标 UpdateRedLightPos(); } if( m_pCallback ) { int nSceneStatus = -1; if( m_pCallback != NULL) { //把红灯的位置传出去 m_pCallback->TrafficLightStatus( m_tlpTrafficLightParam.iLightGroupCount, m_rgLightStatus, &nSceneStatus, m_rgLightRect, m_iRedLightCount, m_rgRedLightRect, pSceneImage ); } nSceneStatus = nCurScene; #if 0 //新增输出红绿灯灯组信息 lixh 2011-09-19 static char pLightStatus[64] = "", pLastStatus[64] = ""; memset(pLightStatus, 0, 64); PrintLightStatus(ltsInfo , pLightStatus , 64); if(0 != strcmp(pLightStatus, pLastStatus)) { strcpy(pLastStatus, pLightStatus); sprintf(g_szDebugInfo, "rg status = %s", pLastStatus); for(int i = 0; i < m_tlpTrafficLightParam.iLightGroupCount; i++) { CRect rc = m_rgLightInfo[i].GetRect(); sprintf(g_szDebugInfo + strlen(g_szDebugInfo), "(%d,%d,%d,%d)", rc.left, rc.top, rc.right, rc.bottom); } } #endif m_iCurLightStatus = nSceneStatus; //如果用户设置了场景状态则加入场景状态队列 //if(hr == S_OK && nSceneStatus != -1) if( nSceneStatus != -1 ) { m_iErrorSceneCount = 0; SetSceneStatus(nSceneStatusPos, nSceneStatus); nSceneStatusPos++; //下一个存储位置,同时也是计数 int iRelayTimeMs = m_tlpTrafficLightParam.iValidSceneStatusCount * 100; //加入场景状态后判断是否输出 if(m_tlpTrafficLightParam.iValidSceneStatusCount > 0 && nSceneStatusPos >= m_tlpTrafficLightParam.iValidSceneStatusCount) { int nLastPos = nSceneStatusPos - 1; int nLastStatus = GetSceneStatus(nLastPos); BOOL fValid = TRUE; for( int i = nLastPos - 1; i > (nLastPos - m_tlpTrafficLightParam.iValidSceneStatusCount); i--) { if( GetSceneStatus(i) != nLastStatus) { fValid = FALSE; break; } } //如果是快速模式,则有一帧判断为下一场景就跳变. if( m_fCheckSpeed && !fValid && m_iLastOkLightStatus != -1 && m_iLastOkLightStatus != nSceneStatus) { int iNextStatus = (m_iLastOkLightStatus + 1) % m_tlpTrafficLightParam.iSceneCount; if( iNextStatus == nSceneStatus ) { fValid = true; iRelayTimeMs = 100; nLastStatus = nSceneStatus; } } if( fValid && nLastStatus != m_iLastLightStatus) { //如果有绿灯变成红灯且设有黄灯延迟 TRAFFICLIGHT_SCENE tsLast, tsRelay; GetLightScene(m_iLastOkLightStatus, &tsLast); GetLightScene(nLastStatus, &tsRelay); DWORD32 dwTick = GetSystemTick(); bool fRelayTimeOut = true; if( m_tlpTrafficLightParam.iRedLightDelay > 0 ) { if( tsLast.lsLeft == TLS_GREEN && tsRelay.lsLeft == TLS_RED ) { if( m_ltRedRelay.dwLeft == 0 ) m_ltRedRelay.dwLeft = dwTick; if( int(dwTick - m_ltRedRelay.dwLeft) < (m_tlpTrafficLightParam.iRedLightDelay * 1000) ) { fRelayTimeOut = false; } } if( tsLast.lsForward == TLS_GREEN && tsRelay.lsForward == TLS_RED ) { if( m_ltRedRelay.dwForward == 0 ) m_ltRedRelay.dwForward = dwTick; if( int(dwTick - m_ltRedRelay.dwForward) < (m_tlpTrafficLightParam.iRedLightDelay * 1000) ) { fRelayTimeOut = false; } } if( tsLast.lsRight == TLS_GREEN && tsRelay.lsRight == TLS_RED ) { if( m_ltRedRelay.dwRight == 0 ) m_ltRedRelay.dwRight = dwTick; if( int(dwTick - m_ltRedRelay.dwRight) < (m_tlpTrafficLightParam.iRedLightDelay * 1000) ) { fRelayTimeOut = false; } } if( tsLast.lsTurn == TLS_GREEN && tsRelay.lsTurn == TLS_RED ) { if( m_ltRedRelay.dwTurn == 0 ) m_ltRedRelay.dwTurn = dwTick; if( int(dwTick - m_ltRedRelay.dwTurn) < (m_tlpTrafficLightParam.iRedLightDelay * 1000) ) { fRelayTimeOut = false; } } } if( fRelayTimeOut ) { m_ltRedRelay.Reset(); m_iLastLightStatus = nLastStatus; TRAFFICLIGHT_SCENE tsSceneStatus, tsNow; GetLightScene(m_iLastLightStatus, &tsSceneStatus); GetLightScene(m_iLastLightStatus, &tsNow); int iGreenRelayMs = 1000; //新增输出红绿灯灯组信息 lixh 2011-09-19 char pLightStatus[64]; memset(pLightStatus, 0, 64); PrintLightStatus(ltsInfo , pLightStatus , 64); if( m_pCallback != NULL ) { m_pCallback->TrafficSceneStatus(tsSceneStatus,pLightStatus); } //更新红灯开始时间 if( nLastStatus != -1 ) { m_iLastOkLightStatus = nLastStatus; } //DWORD32 dwTimeLow, dwTimeHigh; //ConvertTickToSystemTime((GetSystemTick() - iRelayTimeMs), dwTimeLow, dwTimeHigh); //一体机代码,红绿灯时间只有L,没有H,在ARM端在通过ConvertTickToSystemTime进行转换,黄国超修改,2011-07-21 DWORD32 dwTimeLow = GetSystemTick() - iRelayTimeMs, dwTimeHigh = 0; if( tsNow.lsLeft == TLS_RED && tsLast.lsLeft != TLS_RED ) { m_redrealtime.dwLeftL = dwTimeLow; m_redrealtime.dwLeftH = dwTimeHigh; } if( tsNow.lsLeft == TLS_GREEN && tsLast.lsLeft != TLS_GREEN ) { m_greentick.dwLeft = GetSystemTick() - iRelayTimeMs - iGreenRelayMs; } else if( tsNow.lsLeft != TLS_GREEN ) { m_greentick.dwLeft = 0; } if( tsNow.lsForward == TLS_RED && tsLast.lsForward != TLS_RED ) { m_redrealtime.dwForwardL = dwTimeLow; m_redrealtime.dwForwardH = dwTimeHigh; } if( tsNow.lsForward == TLS_GREEN && tsLast.lsForward != TLS_GREEN ) { m_greentick.dwForward = GetSystemTick() - iRelayTimeMs - iGreenRelayMs; } else if( tsNow.lsForward != TLS_GREEN ) { m_greentick.dwForward = 0; } if( tsNow.lsRight == TLS_RED && tsLast.lsRight != TLS_RED ) { m_redrealtime.dwRightL = dwTimeLow; m_redrealtime.dwRightH = dwTimeHigh; } if( tsNow.lsRight == TLS_GREEN && tsLast.lsRight != TLS_GREEN ) { m_greentick.dwRight = GetSystemTick() - iRelayTimeMs - iGreenRelayMs; } else if( tsNow.lsRight != TLS_GREEN ) { m_greentick.dwRight = 0; } if( tsNow.lsTurn == TLS_RED && tsLast.lsTurn != TLS_RED ) { m_redrealtime.dwTurnL = dwTimeLow; m_redrealtime.dwTurnH = dwTimeHigh; } if( tsNow.lsTurn == TLS_GREEN && tsLast.lsTurn != TLS_GREEN ) { m_greentick.dwTurn = GetSystemTick() - iRelayTimeMs - iGreenRelayMs; } else if( tsNow.lsTurn != TLS_GREEN ) { m_greentick.dwTurn = 0; } } } } } else { //如果无效场景数大于设定的值,则把当前的场景设成-1. m_iErrorSceneCount++; if( m_iErrorSceneCount >= (m_tlpTrafficLightParam.iValidSceneStatusCount * 2)) { m_iLastLightStatus = -1; TRAFFICLIGHT_SCENE tsSceneStatus; GetLightScene(m_iLastLightStatus, &tsSceneStatus); //新增输出红绿灯灯组信息 lixh 2011-09-19 char pLightStatus[64]; memset(pLightStatus, 0, 64); PrintLightStatus(ltsInfo , pLightStatus , 64); if( m_pCallback != NULL ) { m_pCallback->TrafficSceneStatus(tsSceneStatus,pLightStatus); } //无效场景有可能是中间状态,红灯时间不能重置。 } //如果无效场景帧数大过设定的值,则重置红绿灯框位置,红灯时间重置 if( m_iErrorSceneCount > MAX_ERROR_COUNT ) { m_iErrorSceneCount = 0; m_iLastOkLightStatus = -1; for(int i = 0; i < 4; ++i) { m_redrealtime.Reset(); m_greentick.Reset(); } if( m_tlpTrafficLightParam.iAutoScanLight == 1 ) { for(int i = 0; i <m_tlpTrafficLightParam.iLightGroupCount; ++i) { if( S_OK == m_rgLightInfo[i].ReScan() ) { HV_Trace(5, "TrafficLight ReScan ...\n"); } } } } } } *iCurrentStatus = m_iCurLightStatus; *iLastStatus = m_iLastLightStatus; return hResult; }