int main( int argc, char ** argv ) { //Declarations IplImage * template_img; IplImage * plate_img; int numContours; plateInfo * plate_info; charInfo * char_info; char** plate_number; char pNumber[7]; int i; if( argc < 5 ) exit (0); else { char *state = findState(argv); //Load template image template_img = cvLoadImage( argv[1], CV_LOAD_IMAGE_GRAYSCALE); //Load original license image plate_img = cvLoadImage( argv[2], CV_LOAD_IMAGE_COLOR ); plate_info = processPlateChars( plate_img ); char_info = processTemplateChars( template_img, &numContours ); plate_number = compareChar( char_info, plate_info, &numContours ); //Mkay, this should do it.. //Print that bad boy! printf("\nPlate number: "); for(i = 1; i < 8; i++) { printf("%s", plate_number[i]); strcpy((pNumber + (i-1)), plate_number[i]); } printf("\n"); // char * number = pNumber[6]; printf("%s", pNumber); Owner owner; owner = newOwner(state, pNumber); WriteToXML(owner); return EXIT_SUCCESS; } }
void Grammar::computeSuccessors(LR1State &state) { //dump(state); pause(); BitSet itemsDone(state.m_items.size()); // this is correct! for(UINT i = 0; i < state.m_items.size(); i++) { if(itemsDone.contains(i)) { continue; } const LR1Item &origItem = state.m_items[i]; if(isAcceptItem(origItem)) { continue; // No successor, but accept } const Production &origProduction = getProduction(origItem); if(origItem.m_dot < origProduction.getLength()) { // origItem is A -> alfa . X beta [la] CompactIntArray successorItems; successorItems.add(i); int symbolNr = origProduction.m_rightSide[origItem.m_dot]; LR1State newState(getStateCount()); const LR1Item newItem(true, origItem.m_prod, origItem.m_dot+1, origItem.m_la); // newItem is A -> alfa X . beta [la] (kernelItem) newState.addItem(newItem); itemsDone += i; for(UINT k = i+1; k < state.m_items.size(); k++) { if(itemsDone.contains(k)) { continue; } const LR1Item &sameSymbolItem = state.m_items[k]; const Production &sameSymbolProd = getProduction(sameSymbolItem); if(sameSymbolItem.m_dot < sameSymbolProd.getLength() && sameSymbolProd.m_rightSide[sameSymbolItem.m_dot] == symbolNr) { // sameSymbolItem is C -> gamma . X zeta [la1] const LR1Item newItem1(true, sameSymbolItem.m_prod, sameSymbolItem.m_dot+1, sameSymbolItem.m_la); // newItem1 is C -> gamma X . zeta [la1] (kernelItem) newState.addItem(newItem1); itemsDone += k; successorItems.add(k); } } newState.sortItems(); int succStateIndex = findState(newState); if(succStateIndex < 0) { computeClosure(newState, true); succStateIndex = addState(newState); } else { if(mergeLookahead(m_states[succStateIndex], newState)) { m_unfinishedSet.add(succStateIndex); // printf(_T(")%d ", succStateIndex); } } assert(succStateIndex >= 0); for(size_t j = 0; j < successorItems.size(); j++) { state.m_items[successorItems[j]].m_succ = succStateIndex; } } } }
ObjectState *Set::addObjectState(int setupID, ObjectState::Position pos, const char *bitmap, const char *zbitmap, bool transparency) { ObjectState *state = findState(bitmap); if (state) { return state; } state = new ObjectState(setupID, pos, bitmap, zbitmap, transparency); addObjectState(state); return state; }
void CSIMSlmWithIteration::findBackOffState(int n, TSIMWordId*hw, unsigned & bol, unsigned& bon) { while (n > 1) { --n; ++hw; int idx = findState(n, hw); if (idx >= 0 && ((TNode*)(level[n]))[idx].child < ((TNode*)(level[n]))[idx+1].child) { bol = n; bon = idx; return; } } bol = bon = 0; return; }
/* Finds the initial state of the string from the first character. 0 sets FSM to state leading to Zero, Octal, Hex or Float. 1-9 sets FSM to state leading to Decimal and Float. If the character is whitespace, recursively looks to the next character. If null, ends token. Otherwise, returns a malformed token state. */ enum FSMState findState (TokenizerT *tok) { if (*tok->current == '0') return State_1; else if (isdigit(*tok->current) && *tok->current != '0') return State_2; else if (isspace(*tok->current)) { tok->current++; tok->tokStart++; return findState(tok); } else if (*tok->current == '\0') return EndState; else { return MalState; } }
char *TKGetNextToken( TokenizerT * tk ) { tk->tokStart = tk->current; tk->tokLength = 0; tk->currState = findState(tk); //Iterates through Finite State Machine by character and changes state accordingly. while(tk->currState != EndState) { tk->tokLength++; tk->current++; switch(tk->currState) { case State_1: tk->currState = FSMState_1(tk); break; case State_2: tk->currState = FSMState_2(tk); break; case State_3: tk->currState = FSMState_3(tk); break; case State_4: tk->currState = FSMState_4(tk); break; case State_5: tk->currState = FSMState_5(tk); break; case State_6: tk->currState = FSMState_6(tk); break; case State_7: tk->currState = FSMState_7(tk); break; case State_8: tk->currState = FSMState_8(tk); break; case State_9: tk->currState = FSMState_9(tk); break; case State_10: tk->currState = FSMState_10(tk); break; case MalState: tk->currState = FSMMalState(tk); break; default: break; } } //Creates a token by copying a substring from the original string and appends a null terminating character on the end if (tk->tokLength > 0) { char * token = malloc(tk->tokLength +1); strncpy(token, tk->tokStart, tk->tokLength); token[tk->tokLength] = '\0'; return token; } return NULL; }
int LRBuilder::buildState(const vector<LRProduction> initProduction) { //build Closure LRState state{ initProduction, {} }; cout << "build state; production size:"; cout << initProduction.size() << endl; while (true) { vector<LRProduction> newProduction; for (const auto& lrproduction : state.productions) { const auto& prooduction = productionManager.getProduction(lrproduction.productionId); if (lrproduction.pos < (int)prooduction.right.size()) { //dot is not at end const auto& nextToken = prooduction.right[lrproduction.pos]; if (!tokenManager.isTerminal(nextToken)) {//.后面是非终结符,开始展开 const auto& nextProdutions = productionManager.getProductions((NonterminalToken&)nextToken); for (const auto& nextProdution : nextProdutions) { int id = productionManager.getProductionID(nextProdution); vector<int> tokenids; if (lrproduction.pos + 1 < (int)prooduction.right.size()) { int tid = tokenManager.getTokenId(prooduction.right[lrproduction.pos + 1].name); tokenids.push_back(tid); } tokenids.push_back(lrproduction.lookAhead); const auto& nextFirsts = getFirst(tokenids); for (auto& nextFirst : nextFirsts) { LRProduction nextLR{ id, 0, nextFirst}; if (find(state.productions.begin(), state.productions.end(), nextLR) == state.productions.end()) { newProduction.push_back(nextLR); } } } } } } if (newProduction.size() == 0) { //不再增加新的产生式了。 break; } state.productions.insert(state.productions.end(), newProduction.begin(), newProduction.end());//将新增加的产生式插入状态末尾 } int sid = findState(state); if (sid != -1) { return sid; } int id = lrstatus.size(); lrstatus[state] = id; // build GOTO cout << "state id:" << id<<endl; map<Token, vector<LRProduction>> trans; for (const auto& lrproduction : state.productions) { const auto& prooduction = productionManager.getProduction(lrproduction.productionId); if (lrproduction.pos < (int)prooduction.right.size()) { const auto& nextToken = prooduction.right[lrproduction.pos]; auto& transInit = trans[nextToken]; auto newLR = lrproduction; newLR.pos++; if (find(transInit.begin(), transInit.end(), newLR) == transInit.end()) { trans[nextToken].push_back(newLR); } } } for (const auto& tran : trans) { const auto& token = tran.first; const auto& productions = tran.second; state.action[token] = buildState(productions); } lrstatus_id[id] = state; return id; }
int emf_searchBlob(int key) { static int status = 0; static int status2 = 0; static int change = 0; double tmp; static BlobTracker *bt; static PID tiltSrvPID = {0.05, 0.035, 0.001, 0.0, 0.0, 0.0}; static PID panSrvPID = {0.02, 0.009, 0.001, 0.0, 0.0, 0.0}; double bx, by; double errX, errY; double resp; static CvPoint center; static FILE *fp; unsigned int sw; if (!fp) { fp = fopen("hist_fb_7.data", "w"); if (!fp) fprintf(stderr, "history file not opened!\n"); } if (key == 0) { change = 0; status = 0; status2 = 0; if (findState(&is, "intruder_near")||findState(&is, "intruder_found")) ; else bt = intruder; } trackBlobs(bt, frame, 0); if (bt->blobs->trackable) { if (status2 == 3) { //sendCommand(STOP, is.ltMotorVal=0, is.rtMotorVal=0); is.ltMotorVal=0, is.rtMotorVal=0; send_command(MOTOR_DIR, MOTOR_STOP); //stop if (bt == intruder) addState(&is, "intruder_found"); return 1; } if (status2 == 0) { clearPid(&tiltSrvPID); clearPid(&panSrvPID); status2 = 1; printf("tilt_clear: prev_resp=%g pan_prev_resp=%g.\n", tiltSrvPID.prevResp, panSrvPID.prevResp); } if (status2 == 1) { center = bt->blobs->center; bx = ((double)center.x/(double)fsize.width)*100.0; by = ((double)center.y/(double)fsize.height)*100.0; errY = by-50.0; errX = bx-50.0; printf("errorX %g, Y %g\n", errX, errY); if (errY<5.0f) { tmp = is.hdPanAngle; //writeServo(PAN_SRV, is.hdPanAngle=90.0f); send_command(SERVO_PAN, (byte)((int)(is.hdPanAngle=90.0f))); printf("waiting for 1sec...pan %g\n",tmp); sw = getTickCount(); while ((getTickCount()-sw)<2000) { printf("time = %dms\n", getTickCount()-sw); frame = cvQueryFrame(capture); } printf("out of 1sec loop...\n"); status2 = 3; if (MOD(tmp-90.0f)<10.0f) { printf("go straight\n"); return 1; } if (tmp>90.0f) { printf("go right\n"); is.ltMotorVal=is.rtMotorVal=40; send_command(RIGHT_MTR_VAL, 128+is.ltMotorVal/2); send_command(LEFT_MTR_VAL, 128-is.rtMotorVal/2); send_command(MOTOR_DIR, MOTOR_FWD); //sendCommand(LTMTR_SDIR, 1, 0); //sendCommand(DIFF_DRV, is.ltMotorVal=175, is.rtMotorVal=80); } else { printf("go left\n"); is.ltMotorVal=is.rtMotorVal=40; send_command(LEFT_MTR_VAL, 128+is.rtMotorVal/2); send_command(RIGHT_MTR_VAL, 128-is.ltMotorVal/2); send_command(MOTOR_DIR, MOTOR_FWD); //sendCommand(RTMTR_SDIR, 1, 0); //sendCommand(DIFF_DRV, is.ltMotorVal=80, is.rtMotorVal=175); } return 1; } //resp = getPidRespVerb(&tiltSrvPID, errY, fp, "Tilt"); resp = (double)errY*0.05f; is.hdTiltAngle -= resp; if (is.hdTiltAngle < MAX_SERVO_TILT_DOWN) is.hdTiltAngle = MAX_SERVO_TILT_DOWN; else if (is.hdTiltAngle > MAX_SERVO_TILT_UP) is.hdTiltAngle = MAX_SERVO_TILT_UP; if (is.hdPanAngle < MAX_SERVO_PAN_LEFT) is.hdPanAngle = MAX_SERVO_PAN_LEFT; else if (is.hdPanAngle > MAX_SERVO_PAN_RIGHT) is.hdPanAngle = MAX_SERVO_PAN_RIGHT; writePanTiltServos(is.hdPanAngle, is.hdTiltAngle); return 1; } } if (status2 == 3) return 1; if (status2) status2 = 0; if (!status) { status = 1; writePanTiltServos(is.hdPanAngle=150.0f/*30.0f*/, is.hdTiltAngle=90.0f); printf("waiting for 1sec...\n"); sw = getTickCount(); while ((getTickCount()-sw)<2000) { printf("time = %dms\n", getTickCount()-sw); frame = cvQueryFrame(capture); } printf("out of 1sec loop...\n"); return 1; } if (!change) { if (is.hdPanAngle>160.0f||is.hdPanAngle<20.0f) { if (is.hdTiltAngle<40/*>140.0f*/) { writePanTiltServos(is.hdPanAngle=90.0f, is.hdTiltAngle=90.0f); cleanStates(&is); return 1; } //writeServo(TILT_SRV, is.hdTiltAngle-=20.0f); send_command(SERVO_TILT, (byte)((int)(is.hdTiltAngle-=20.0f))); status = -status; change = 1; return 1; } } if (change) change = 0; if (status==1) //writeServo(PAN_SRV, is.hdPanAngle-=5.0f); send_command(SERVO_PAN, (byte)((int)(is.hdPanAngle-=5.0f))); else //writeServo(PAN_SRV, is.hdPanAngle+=5.0f); send_command(SERVO_PAN, (byte)((int)(is.hdPanAngle+=5.0f))); return 1; }
void ABLModule::read(ABLFile* moduleFile) { //---------------------------------------------------------------------------- // If this is called on a newly init'd module, then it will do all appropriate // memory alloc, etc. If it's being called on a module that's already been // setup (via a call to init(moduleHandle)), then it simply loads the // module's data... bool fresh = (id == -1); if(fresh) { id = NumModules++; moduleFile->readString((puint8_t)name); handle = moduleFile->readLong(); staticData = nullptr; } else { char tempName[1024]; moduleFile->readString((puint8_t)tempName); //int32_t ignore = moduleFile->readLong(); } char stateName[256]; memset(stateName, 0, 256); moduleFile->readString((puint8_t)stateName); prevState = nullptr; if(strcmp(stateName, "NULLPrevState")) prevState = findState(stateName); memset(stateName, 0, 256); moduleFile->readString((puint8_t)stateName); state = nullptr; if(strcmp(stateName, "NULLState")) state = findState(stateName); bool savedInitCalled = (moduleFile->readLong() == 1); int32_t numStatics = ModuleRegistry[handle].numStaticVars; if(numStatics) { if(fresh) { staticData = (StackItemPtr)ABLStackMallocCallback(sizeof(StackItem) * numStatics); if(!staticData) { char err[255]; sprintf(err, "ABL: Unable to AblStackHeap->malloc staticData [Module %d]", id); ABL_Fatal(0, err); } } int32_t* sizeList = ModuleRegistry[handle].sizeStaticVars; for(size_t i = 0; i < numStatics; i++) if(sizeList[i] > 0) { if(fresh) { staticData[i].address = (PSTR)ABLStackMallocCallback(sizeList[i]); if(!staticData) { char err[255]; sprintf(err, "ABL: Unable to AblStackHeap->malloc staticData address [Module %d]", id); ABL_Fatal(0, err); } } int32_t result = moduleFile->read((puint8_t)staticData[i].address, sizeList[i]); if(!result) { char err[255]; sprintf(err, "ABL: Unable to read staticData.address [Module %d]", id); ABL_Fatal(0, err); } } else { staticData[i].integer = 0; int32_t result = moduleFile->read((puint8_t)&staticData[i], sizeof(StackItem)); if(!result) { char err[255]; sprintf(err, "ABL: Unable to read staticData [Module %d]", id); ABL_Fatal(0, err); } } } if(ModuleRegistry[handle].numOrderCalls) { int32_t numLongs = 1 + ModuleRegistry[handle].numOrderCalls / 32; orderCallFlags = (uint32_t*)ABLStackMallocCallback(sizeof(uint32_t) * numLongs); if(!orderCallFlags) { char err[255]; sprintf(err, "ABLModule.read: Unable to AblStackHeap->malloc orderCallFlags [Module %d]", id); ABL_Fatal(0, err); } for(size_t i = 0; i < numLongs; i++) orderCallFlags[i] = 0; } if(fresh) { ModuleRegistry[handle].numInstances++; initCalled = savedInitCalled; //------------------------------------------------------ // This Active Module is now on the instance registry... ModuleInstanceRegistry[NumModuleInstances++] = this; if(debugger) { watchManager = new WatchManager; if(!watchManager) ABL_Fatal(0, " Unable to AblStackHeap->malloc WatchManager "); int32_t result = watchManager->init(MaxWatchesPerModule); if(result != ABL_NO_ERR) ABL_Fatal(0, " Unable to AblStackHeap->malloc WatchManager "); breakPointManager = new BreakPointManager; if(!breakPointManager) ABL_Fatal(0, " Unable to AblStackHeap->malloc BreakPointManager "); result = breakPointManager->init(MaxBreakPointsPerModule); if(result != ABL_NO_ERR) ABL_Fatal(0, " Unable to AblStackHeap->malloc BreakPointManager "); } } }
void Service::changeState(std::string stateName) { m_currentState = findState(stateName); }
void Service::setInitialState(std::string stateName) { if( m_currentState ) return; // 設定済み m_currentState = findState(stateName); }
// findState() returns an object's state from the cache or null if the // state was not found. GString *XMLObjectCache::findState( const char* oid, const char *pzClassName ) { GString strKey; strKey << oid << pzClassName; return findState( strKey ); }