int main(const int argc, const char **argv) { MYLOGVERB = LOG_INFO; ModelManager *mgr = new ModelManager("Extract Patches for Hmax with Feature Learning"); mgr->exportOptions(MC_RECURSE); // required arguments // <c1patchesDir> <trainPosDir> if (mgr->parseCommandLine( (const int)argc, (const char**)argv, "<c1patchesDir> <trainPosDir>", 2, 2) == false) return 1; // Create a temp HmaxFL object to extract C1Patches std::vector<int> c1ScaleSS(2); c1ScaleSS[0] = 1; c1ScaleSS[1] = 3; std::vector<int> c1SpaceSS(2); c1SpaceSS[0] = 10; c1SpaceSS[1] = 11; // desired frame sizes [11 and 13] HmaxFL hmax(NORI,c1SpaceSS,c1ScaleSS,2,true,1.0F,1.0F,0.3F,4.05F,-0.05F,11,2); std::string c1PatchesBaseDir; std::string trainPosName; // Directory where positive images are c1PatchesBaseDir = mgr->getExtraArg(0); trainPosName = mgr->getExtraArg(1); // Extract random patches from a set of images in a positive training directory std::vector<std::string> trainPos = hmax.readDir(trainPosName); int posTrainSize = trainPos.size(); //Image<byte> inputb; Image<float> trainPosImage; std::cout << "Scanned training and testing images" << std::endl; std::vector<int> pS(4); pS[0] = 4; pS[1] = 8, pS[2] = 12; pS[3] = 16; std::srand(time(0)); for(int i=0;i<NUM_PATCHES_PER_SIZE;i++){ // Randomly select an image from the list unsigned int imInd = static_cast<unsigned int>(floor((rand()-1.0F)/RAND_MAX*posTrainSize)); trainPosImage = Raster::ReadFloat(trainPos[imInd]); // Learn the appropriate simple S2 patches from the C1 results hmax.extractRandC1Patch(c1PatchesBaseDir,trainPosImage,i,pS); } std::cout << "Completed extraction of C1 Patches" << std::endl; return 0; }
int main(int argc, const char **argv) { // Instantiate a ModelManager: ModelManager *manager = new ModelManager("Test wiimote"); nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(*manager)); manager->addSubComponent(ofs); //Create the GUI nub::soft_ref<GeneralGUI> pwiiGUI(new GeneralGUI(*manager, "PWiiGUI", "PWiiGUI", Dims(700,512))); manager->addSubComponent(pwiiGUI); //Create the PWiiBot Controller nub::soft_ref<PWiiController> controller(new PWiiController(*manager)); manager->addSubComponent(controller); // Parse command-line: if (manager->parseCommandLine(argc, argv, "", 0, 0) == false) return(1); manager->exportOptions(MC_RECURSE); manager->start(); sleep(1); setupGUI(pwiiGUI, ofs, controller); while(1) { } // sleep(1); #ifdef HAVE_LIBWIIMOTE /* wiimote_t wiimote = WIIMOTE_INIT; //wiimote_report_t report = WIIMOTE_REPORT_INIT; LINFO("Press buttons 1 and 2 on the wiimote now to connect."); int nmotes = wiimote_discover(&wiimote, 1); if (nmotes == 0) LFATAL("no wiimotes were found"); LINFO("found: %s\n", wiimote.link.r_addr); if (wiimote_connect(&wiimote, wiimote.link.r_addr) < 0) { LFATAL("Unable to connect to wiimote"); Raster::waitForKey(); } */ /* Activate the first led on the wiimote. It will take effect on the next call to wiimote_update. */ /* wiimote.led.one = 1; // let's get all our ModelComponent instances started: LINFO("Open "); LINFO("Status %i", wiimote_is_open(&wiimote)); int speed = 100; int motor1_dir = 0; int motor1_vel = 0; int motor2_dir = 0; int motor2_vel = 0; Point2D<int> loc(128,128); */ // while(wiimote_is_open(&wiimote)) // { /* The wiimote_update function is used to synchronize the wiimote object with the real wiimote. It should be called as often as possible in order to minimize latency. */ /* if (wiimote_update(&wiimote) < 0) { wiimote_disconnect(&wiimote); break; }*/ /* The wiimote object has member 'keys' which keep track of the current key state. */ /* if (wiimote.keys.home) { //press home to exit wiimote_write_byte(&wiimote, 0x04a40001, motor1_dir); wiimote_write_byte(&wiimote, 0x04a40002, 0); wiimote_write_byte(&wiimote, 0x04a40003, motor2_dir); wiimote_write_byte(&wiimote, 0x04a40004, 0); LINFO("Shutting Down Motors and Gracefully Disconnecting..."); wiimote_disconnect(&wiimote); LINFO("Disconnected, Goodbye!"); } */ /* Activate the accelerometer when the 'A' key is pressed. */ //if (wiimote.keys.a) { // wiimote.mode.acc = 1; //} //else { // wiimote.mode.acc = 0; //} // Image<PixRGB<byte> > img(255,255,ZEROS); // drawLine(img, Point2D<int>(128, 128), Point2D<int>(128+(int)(wiimote.force.x*400), 128), PixRGB<byte>(255,0,0),3); // drawLine(img, Point2D<int>(128, 128), Point2D<int>(128, 128+(int)(wiimote.force.y*400)), PixRGB<byte>(0,255,0),3); // drawLine(img, Point2D<int>(128, 128), Point2D<int>(128+(int)(wiimote.force.z*400), 128), PixRGB<byte>(0,0,255),3); // ofs->writeRGB(img, "Output", FrameInfo("output", SRC_POS)); /* int key = getKey(ofs); if (key != -1) { switch(key) { case 10: //l speed += 10; break; case 24: speed -= 10; break; case KEY_UP: motor1_dir = 2; motor2_dir = 2; break; case KEY_DOWN: motor1_dir = 1; motor2_dir = 1; break; case KEY_LEFT: motor1_dir = 2; motor2_dir = 1; break; case KEY_RIGHT: motor1_dir = 1; motor2_dir = 2; break; case 65: //space motor1_dir = 4; motor1_vel = 0; motor2_dir = 4; motor2_vel = 0; break; } LINFO("Key: %d -- Sending Motor Command...", key); //send the data to the wiimote wiimote_write_byte(&wiimote, 0x04a40001, motor1_dir); wiimote_write_byte(&wiimote, 0x04a40002, speed); wiimote_write_byte(&wiimote, 0x04a40003, motor2_dir); wiimote_write_byte(&wiimote, 0x04a40004, speed); }*/ /* LINFO("KEYS %04x one=%d two=%d a=%d b=%d <=%d >=%d ^=%d v=%d h=%d +=%d -=%d\n", wiimote.keys.bits, wiimote.keys.one, wiimote.keys.two, wiimote.keys.a, wiimote.keys.b, wiimote.keys.left, wiimote.keys.right, wiimote.keys.up, wiimote.keys.down, wiimote.keys.home, wiimote.keys.plus, wiimote.keys.minus); LINFO("TILT x=%.3f y=%.3f z=%.3f\n", wiimote.tilt.x, wiimote.tilt.y, wiimote.tilt.z); LINFO("FORCE x=%.3f y=%.3f z=%.3f (sum=%.3f)\n", wiimote.force.x, wiimote.force.y, wiimote.force.z, sqrt(wiimote.force.x*wiimote.force.x+wiimote.force.y*wiimote.force.y+wiimote.force.z*wiimote.force.z));*/ // } // stop all our ModelComponents manager->stop(); #else LFATAL("Need the libwiimote"); #endif // all done! return 0; }
int main(const int argc, const char **argv) { MYLOGVERB = LOG_INFO; ModelManager *mgr = new ModelManager("Test ObjRec"); nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(*mgr)); mgr->addSubComponent(ofs); nub::ref<InputFrameSeries> ifs(new InputFrameSeries(*mgr)); mgr->addSubComponent(ifs); nub::ref<EnvSegmenterCannyContour> seg(new EnvSegmenterCannyContour(*mgr)); mgr->addSubComponent(seg); mgr->exportOptions(MC_RECURSE); if (mgr->parseCommandLine( (const int)argc, (const char**)argv, "", 0, 0) == false) return 1; mgr->start(); seg->setModelParamVal("CannyMinCos", 1.0); seg->setModelParamVal("CannyMaxArea", 6000); seg->setModelParamVal("CannyMaxArea", 12000); itsObjectDB.loadFrom("cards.vdb"); while(1) { Image< PixRGB<byte> > inputImg; const FrameState is = ifs->updateNext(); if (is == FRAME_COMPLETE) break; //grab the images GenericFrame input = ifs->readFrame(); if (!input.initialized()) break; inputImg = input.asRgb(); Image<PixRGB<byte> > out; const Rectangle cardbox = seg->getFoa(inputImg, Point2D<int>(), NULL, &out); ofs->writeRGB(out, "input", FrameInfo("input", SRC_POS)); if (cardbox.isValid()) { Image<PixRGB<byte> > card = crop(inputImg, cardbox.getOverlap(inputImg.getBounds())); std::string cardName = recCard(card); if (cardName.length() == 0) { LINFO("Enter name for card:"); std::getline(std::cin, cardName, '\n'); if (cardName.length() > 0) trainCard(card, cardName); } writeText(card, Point2D<int>(0,0), cardName.c_str(), PixRGB<byte>(255), PixRGB<byte>(127)); ofs->writeRGB(card, "card", FrameInfo("card", SRC_POS)); } ofs->updateNext(); } mgr->stop(); return 0; }