void ram (void) { uint8_t key = BTN_RIGHT, button; lcdClear(); while (1) { switch (key) { case BTN_ENTER: // exit return; case BTN_RIGHT: if (direction != DIRECTION_LEFT) direction = DIRECTION_RIGHT; break; case BTN_UP: if (direction != DIRECTION_DOWN) direction = DIRECTION_UP; break; case BTN_LEFT: if (direction != DIRECTION_RIGHT) direction = DIRECTION_LEFT; break; case BTN_DOWN: if (direction != DIRECTION_UP) direction = DIRECTION_DOWN; break; //Default: No keystroke received. Assuming last keystroke. } point newendpoint = snake.endpoint; shiftPoint (&newendpoint, direction); bool resetBacon = false; if (newendpoint.x == bacon.x && newendpoint.y == bacon.y) { growBuf (&snake, direction); resetBacon = true; } else { setGamePixel(snake.startpoint.x, snake.startpoint.y, 0); shiftBuf (&snake, direction); } if (getGamePixel(snake.endpoint.x, snake.endpoint.y)) break; setGamePixel(snake.endpoint.x, snake.endpoint.y, 1); while (resetBacon) { bacon.x = getRandom() % GAME_WIDTH; bacon.y = getRandom() % GAME_HEIGHT; if (!getGamePixel(bacon.x, bacon.y)) resetBacon = false; } drawFood (bacon.x, bacon.y); lcdRefresh(); key = BTN_NONE; for (i=0; i < ( TIME_PER_MOVE / 50 ); ++i) { delayms(50); if ((button = getInputRaw()) != BTN_NONE) key = button; } } // Game ended, show results lcdClear(); lcdNl(); lcdPrintln("Game Over"); lcdPrintln("Your score:"); lcdPrintInt(getLength(&snake) - INITIAL_LENGTH + 1); lcdNl(); lcdPrintln("Press any key"); lcdPrintln("to continue."); lcdRefresh(); delayms(500); while(getInputRaw() == BTN_NONE) delayms(25); }
FastShift::FastShift(const Mat& feature, Mat& convexPoints) { printf("start to meanshift point...\n"); time_t startTime = time(0); data = feature; initial(); printf("start to compute the convex point for every point ...\n"); convexPoints.create(r, n, CV_32FC1); srand(time(0)); vector<float> shiftPoint(n, 0); vector<float> shiftValue(n, 0); double w1, w2; vector<float> total_force, current_force, external_force; vector<int> grid_pos; int maxIterations = 50; for(int counts = 0; counts < r; counts ++) { printf("the %d-th iterations ...\n", counts); int iterations = maxIterations; copy((float*)data.row(counts).data, shiftPoint, n); while(iterations > 0) { iterations --; //choose the best direction radomSelect(); whichGrid(shiftPoint, grid_pos); int pos = findposition(grid_pos); //so many cases to get the external forces #ifdef one_direction external_force = maxDirectionOneSide(shiftPoint, shiftValue); #else #ifdef composite_line external_force = maxDirectionTwoSide(shiftPoint, shiftValue); #else external_force = allDirections(shiftPoint, shiftValue); #endif #endif //shift the feature vector calForce(shiftPoint, pos, current_force); total_force = current_force + external_force; if(l2norm(external_force) < acceptance) continue; if(l2norm(total_force) < stopCond) break; shiftPoint = shiftPoint + step * total_force; /*w1 = l2norm(current_force)/l2norm(total_force); w2 = external_force/total_force; shiftPoint = w1 * shiftPoint + w2 * shiftValue; if(w2 < epsilon) break;*/ } copy(shiftPoint, (float*)convexPoints.row(counts).data, n); //iters.push_back(counts); } string writer = "./output/convex.dat"; MatrixDataIo mdi(writer.c_str(), true, convexPoints); printUsedTime(startTime); programPause(); printf("exit meanshift clustering...\n"); }