int main() { ipp_init(); assertTrue("BeatQ String should be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? STRAIGHTFLUSH J")); assertTrue("BeatQ String should be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? FOUROFAKIND 7 A")); assertTrue("BeatQ String should be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? FULLHOUSE Q 3")); assertTrue("BeatQ String should be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? FLUSH T 9 8 6 2")); assertTrue("BeatQ String should be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? STRAIGHT K")); assertTrue("BeatQ String should be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? THREEOFAKIND 2 Q 7")); assertTrue("BeatQ String should be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? TWOPAIR J 8 A")); assertTrue("BeatQ String should be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? ONEPAIR T A 5 3")); assertTrue("BeatQ String should be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? HIGHCARD Q T 8 7 2")); assertFalse("BeatQ String should not be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? HIGHCARD Q T 8 7 ")); assertFalse("BeatQ String should not be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? HIGHCARD Q T 8 7 S")); assertFalse("BeatQ String should not be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? FLUSH T 9 8 6 22")); assertFalse("BeatQ String should not be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "? FULLHOUSE Q 3")); assertFalse("BeatQ String should not be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "B? 9 8 6 2")); assertFalse("BeatQ String should not be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "")); assertFalse("BeatQ String should not be valid", ipp_validate_msg(REGEX_MSG_BEATQ, "BEAT? X 1 1")); ipp_exit(); return PASS; }
int main() { ipp_init(); assertTrue("Winner String should be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER Alpha 1000 STRAIGHTFLUSH J")); assertTrue("Winner String should be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER Beta 1000 FOUROFAKIND 7 A")); assertTrue("Winner String should be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER Gamma 1000 FULLHOUSE Q 3")); assertTrue("Winner String should be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER BAGELBOT 1234 FLUSH T 9 8 6 2")); assertTrue("Winner String should be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER Coat_Hanger 1239 STRAIGHT K")); assertTrue("Winner String should be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER Amy 1239 THREEOFAKIND 2 Q 7")); assertTrue("Winner String should be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER Amy 1239 TWOPAIR J 8 A")); assertTrue("Winner String should be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER Amy 1239 ONEPAIR T A 5 3")); assertTrue("Winner String should be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER Amy 1239 HIGHCARD Q T 8 7 2")); assertFalse("Winner String should not be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER Amy 1239 HIGHCARD Q T 8 7 ")); assertFalse("Winner String should not be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER Amy 1239 HIGHCARD Q T 8 7 S")); assertFalse("Winner String should not be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER 1239 ONEPAIR T A 5 3")); assertFalse("Winner String should not be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER BAGELBOT 1234 FLUSH T 9 8 6 22")); assertFalse("Winner String should not be valid", ipp_validate_msg(REGEX_MSG_WINNER, "W Gamma 1000 FULLHOUSE Q 3")); assertFalse("Winner String should not be valid", ipp_validate_msg(REGEX_MSG_WINNER, "R BAGELBOT 1234 FLUSH T 9 8 6 2")); assertFalse("Winner String should not be valid", ipp_validate_msg(REGEX_MSG_WINNER, "")); assertFalse("Winner String should not be valid", ipp_validate_msg(REGEX_MSG_WINNER, "WINNER X 1 1")); ipp_exit(); return PASS; }
int main() { ipp_init(); assertTrue("ShowQ String should be valid", ipp_validate_msg(REGEX_MSG_SHOWQ, "SHOW?")); assertFalse("ShowQ String should not be valid", ipp_validate_msg(REGEX_MSG_SHOWQ, "SHW?")); assertFalse("ShowQ String should not be valid", ipp_validate_msg(REGEX_MSG_SHOWQ, "SHOW??")); assertFalse("ShowQ String should not be valid", ipp_validate_msg(REGEX_MSG_SHOWQ, " SHOW?")); assertFalse("ShowQ String should not be valid", ipp_validate_msg(REGEX_MSG_SHOWQ, "SHOW? ")); assertFalse("ShowQ String should not be valid", ipp_validate_msg(REGEX_MSG_SHOWQ, "")); ipp_exit(); return PASS; }
int main() { int msg_type; ipp_init(); msg_type = ipp_validate_unknown_msg("YES STRAIGHTFLUSH J"); assertNotEqual("Yes message should be valid", msg_type, -1); assertEqual("Yes message should have message type of MSG_YES", msg_type, MSG_YES); msg_type = ipp_validate_unknown_msg("FOLD"); assertNotEqual("Fold message should be valid", msg_type, -1); assertEqual("Fold message should have message type of MSG_FOLD", msg_type, MSG_FOLD); ipp_exit(); return PASS; }
int main() { GThread *server_thread; int client_rc; ipp_init(); server_thread = g_thread_create(serverside, NULL, TRUE, NULL); g_thread_yield(); client_rc = clientside(); g_thread_join(server_thread); ipp_exit(); return client_rc; }
int main() { ipp_init(); assertTrue("Call String should be valid", ipp_validate_msg(REGEX_MSG_CALL, "CALL 5")); assertTrue("Call String should be valid", ipp_validate_msg(REGEX_MSG_CALL, "CALL 0")); assertTrue("Call String should be valid", ipp_validate_msg(REGEX_MSG_CALL, "CALL 1234")); assertTrue("Call String should be valid", ipp_validate_msg(REGEX_MSG_CALL, "CALL 012345678")); assertFalse("Call String should not be valid", ipp_validate_msg(REGEX_MSG_CALL, "CALL -1")); assertFalse("Call String should not be valid", ipp_validate_msg(REGEX_MSG_CALL, "CALL 01234567890123456")); assertFalse("Call String should not be valid", ipp_validate_msg(REGEX_MSG_CALL, "CALL S")); assertFalse("Call String should not be valid", ipp_validate_msg(REGEX_MSG_CALL, "CALL ")); assertFalse("Call String should not be valid", ipp_validate_msg(REGEX_MSG_CALL, "")); ipp_exit(); return PASS; }
int main() { ipp_init(); assertTrue("Ante String should be valid", ipp_validate_msg(REGEX_MSG_ANTE, "ANTE 5")); assertTrue("Ante String should be valid", ipp_validate_msg(REGEX_MSG_ANTE, "ANTE 0")); assertTrue("Ante String should be valid", ipp_validate_msg(REGEX_MSG_ANTE, "ANTE 1234")); assertTrue("Ante String should be valid", ipp_validate_msg(REGEX_MSG_ANTE, "ANTE 012345678")); assertFalse("Ante String should not be valid", ipp_validate_msg(REGEX_MSG_ANTE, "ANTE -1")); assertFalse("Ante String should not be valid", ipp_validate_msg(REGEX_MSG_ANTE, "ANTE 01234567890123456")); assertFalse("Ante String should not be valid", ipp_validate_msg(REGEX_MSG_ANTE, "ANTE S")); assertFalse("Ante String should not be valid", ipp_validate_msg(REGEX_MSG_ANTE, "ANTE ")); assertFalse("Ante String should not be valid", ipp_validate_msg(REGEX_MSG_ANTE, "")); ipp_exit(); return PASS; }
int main() { ipp_message *msg; ipp_card *Kh; ipp_card *Kc; ipp_card *Ad, *Kd; ipp_card *As, *Ks, *Qs, *Js, *Ts, *_7s, *_6s; ipp_card *hand[5]; ipp_init(); Kh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kh); Kh->rank = KING; Kh->suit = HEARTS; Kc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kc); Kc->rank = KING; Kc->suit = CLUBS; Ad = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ad); Ad->rank = ACE; Ad->suit = DIAMONDS; Kd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kd); Kd->rank = KING; Kd->suit = DIAMONDS; As = ipp_new_card(); assertNotNull("ipp_new_card() failed", As); As->rank = ACE; As->suit = SPADES; Ks = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ks); Ks->rank = KING; Ks->suit = SPADES; Qs = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qs); Qs->rank = QUEEN; Qs->suit = SPADES; Js = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Js->rank = JACK; Js->suit = SPADES; Ts = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Ts->rank = TEN; Ts->suit = SPADES; _7s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _7s); _7s->rank = SEVEN; _7s->suit = SPADES; _6s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _6s); _6s->rank = SIX; _6s->suit = SPADES; hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH A", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_STRAIGHTFLUSH); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_STRAIGHTFLUSH); ipp_free_message(msg); hand[0] = As; hand[1] = Kd; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "STRAIGHT A", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_STRAIGHT); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_STRAIGHT); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = _7s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "FLUSH A K Q J 7", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_FLUSH); assertEqual("Didn't detect proper hand.", msg->type, MSG_FLUSH); ipp_free_message(msg); hand[0] = As; hand[1] = Kd; hand[2] = Ks; hand[3] = Js; hand[4] = _7s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "ONEPAIR K A J 7", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_ONEPAIR); assertEqual("Didn't detect proper hand.", msg->type, MSG_ONEPAIR); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Ad; hand[3] = Kd; hand[4] = _7s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "TWOPAIR A K 7", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_TWOPAIR); assertEqual("Didn't detect proper hand.", msg->type, MSG_TWOPAIR); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Ad; hand[3] = Kd; hand[4] = Kc; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "FULLHOUSE K A", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_FULLHOUSE); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_FULLHOUSE); ipp_free_message(msg); hand[0] = As; hand[1] = Ks; hand[2] = Js; hand[3] = Kd; hand[4] = Kc; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "THREEOFAKIND K A J", msg->payload); assertEqual("Didn't detect proper hand.", msg->type, MSG_THREEOFAKIND); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_THREEOFAKIND); ipp_free_message(msg); hand[0] = Kh; hand[1] = Ks; hand[2] = Js; hand[3] = Kd; hand[4] = Kc; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "FOUROFAKIND K J", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_FOUROFAKIND); ipp_free_message(msg); hand[0] = As; hand[1] = Kd; hand[2] = Js; hand[3] = _7s; hand[4] = _6s; msg = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msg); assertStringEqual("Didn't detect proper hand.", "HIGHCARD A K J 7 6", msg->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msg->payload), MSG_HIGHCARD); ipp_free_message(msg); ipp_free_card(_6s); ipp_free_card(_7s); ipp_free_card(Ts); ipp_free_card(Js); ipp_free_card(Qs); ipp_free_card(Ks); ipp_free_card(As); ipp_free_card(Kd); ipp_free_card(Ad); ipp_free_card(Kc); ipp_free_card(Kh); ipp_exit(); return PASS; }
int main() { ipp_message *msg; ipp_card *As, *Ad, *Ah; ipp_card *Ks, *Kd, *Kh, *Kc; ipp_card *Qs, *Qh, *Qc; ipp_card *Jh, *Jc, *Jd; guint8 *result; ipp_player *player1, *player2, *player3, *player4; ipp_table *table; int rc, i; ipp_init(); table = ipp_new_table(); player1 = ipp_new_player(); player2 = ipp_new_player(); player3 = ipp_new_player(); player4 = ipp_new_player(); assertNotNull("Table should not be null.", table); assertNotNull("Player 1 should not be null.", player1); assertNotNull("Player 2 should not be null.", player2); assertNotNull("Player 3 should not be null.", player3); assertNotNull("Player 4 should not be null.", player4); assertEqual("Table shouldn't have any players", table->nplayers, 0); rc = ipp_add_player(table, player1); assertNotEqual("Should have been able to add player", rc, -1); assertEqual("Should have one player", table->nplayers, 1); rc = ipp_add_player(table, player2); assertNotEqual("Should have been able to add player", rc, -1); assertEqual("Should have two players", table->nplayers, 2); rc = ipp_add_player(table, player3); assertNotEqual("Should have been able to add player", rc, -1); assertEqual("Should have three players", table->nplayers, 3); rc = ipp_add_player(table, player4); assertNotEqual("Should have been able to add player", rc, -1); assertEqual("Should have four players", table->nplayers, 4); Jh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Jh); Jh->rank = JACK; Jh->suit = HEARTS; Jc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Jc); Jc->rank = JACK; Jc->suit = CLUBS; Jd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Jd); Jd->rank = JACK; Jd->suit = DIAMONDS; Qh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qh); Qh->rank = QUEEN; Qh->suit = HEARTS; Qc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qc); Qc->rank = QUEEN; Qc->suit = CLUBS; Qs = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qs); Qs->rank = QUEEN; Qs->suit = SPADES; Kh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kh); Kh->rank = KING; Kh->suit = HEARTS; Kc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kc); Kc->rank = KING; Kc->suit = CLUBS; Ks = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ks); Ks->rank = KING; Ks->suit = SPADES; Kd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kd); Kd->rank = KING; Kd->suit = DIAMONDS; Ah = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ah); Ah->rank = ACE; Ah->suit = HEARTS; As = ipp_new_card(); assertNotNull("ipp_new_card() failed", As); As->rank = ACE; As->suit = SPADES; Ad = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ad); Ad->rank = ACE; Ad->suit = DIAMONDS; table->board[0] = Ad; table->board[1] = Ah; table->board[2] = Kd; table->board[3] = Kh; table->board[4] = Kc; table->players[0]->hole[0] = Qs; table->players[0]->hole[1] = Qh; table->players[1]->hole[0] = As; table->players[1]->hole[1] = Ks; table->players[2]->hole[0] = Jh; table->players[2]->hole[1] = Jd; table->players[3]->hole[0] = Qc; table->players[3]->hole[1] = Jc; table->stage = SHOWDOWN; for (i = 0; i < 4; i++) { msg = ipp_best_combination(table, i); assertNotNull("ipp_best_combination() should have return an answer", msg); printf("Player #%d Hand => '%s'\n", i, msg->payload); ipp_free_message(msg); } result = NULL; result = ipp_rank_players(table); assertNotNull("ipp_rank_players() should have return an answer.", result); for (i = 0; i < HOLDEM_PLAYERS_PER_TABLE; i++) { int playerid; playerid = result[i]; if (table->players[playerid]) { msg = ipp_best_combination(table, playerid); assertNotNull("ipp_best_combination() should have return an answer", msg); printf("(%d) Player #%d Hand => '%s'\n", i, playerid, msg->payload); ipp_free_message(msg); } } /* (0) Player #1 Hand => 'FOUROFAKIND K A' (1) Player #0 Hand => 'FULLHOUSE K Q' (2) Player #2 Hand => 'FULLHOUSE K J' (3) Player #3 Hand => 'THREEOFAKIND K Q J' */ assertEqual("Player #1 should be 1st", result[0], 1); assertEqual("Player #0 should be 2nd", result[1], 0); assertEqual("Player #2 should be 3rd", result[2], 2); assertEqual("Player #3 should be 4th", result[3], 3); ipp_free_table(table); /* will also free players */ free(result); ipp_exit(); return PASS; }
MAIN_QTHREAD(int, argc, char **, argv) { // macro to enable multithreaded gui #else int main(int argc, char **argv) { // regular main without gui #endif try { // check input parameters if ((argc != 2) && (argc != 3) ) { cerr << "wrong number of parameters." << endl; cerr << "usage: objdetect <config file> [directory or file]" << endl; return -1; } #ifdef __LINUX__ feenableexcept(FE_DIVBYZERO | FE_INVALID); // enable float exceptions #endif ipp_init(1); // limit IPP (if available) to 1 core // load configuration configuration conf(argv[1], true, true, false); if (!conf.exists("root2")) { string dir; dir << dirname(argv[1]) << "/"; cout << "Looking for trained files in: " << dir << endl; conf.set("root2", dir.c_str()); conf.set("current_dir", dir.c_str()); } conf.resolve(); if (conf.exists_true("show_conf")) conf.pretty(); bool color = conf.exists_bool("color"); uint norm_size = conf.get_uint("normalization_size"); Tnet threshold = (Tnet) conf.get_double("threshold"); bool display = false; bool display_states= false; bool mindisplay = false; uint display_sleep = 0; bool save_video = false; string cam_type = conf.get_string("camera"); int height = -1; int width = -1; if (conf.exists("input_height")) height = conf.get_int("input_height"); if (conf.exists("input_width")) width = conf.get_int("input_width"); bool input_random = conf.exists_true("input_random"); uint npasses = 1; char next_on_key = 0; uint wid = 0; // window id uint wid_states = 0; // window id string outdir = "out_"; if (conf.exists("next_on_key")) { next_on_key = conf.get_char("next_on_key"); cout << "Press " << next_on_key << " to process next frame." << endl; } outdir += tstamp(); outdir += "/"; cout << "Saving outputs to " << outdir << endl; // load network and weights parameter<fs(Tnet)> theparam; idx<ubyte> classes(1,1); try { load_matrix<ubyte>(classes, conf.get_cstring("classes")); } catch(string &err) { cerr << "warning: " << err << endl; } vector<string> sclasses = ubyteidx_to_stringvector(classes); answer_module<SFUNC2(Tnet)> *ans = create_answer<SFUNC2(Tnet)>(conf, classes.dim(0)); uint noutputs = ans->get_nfeatures(); module_1_1<SFUNC(Tnet)> *net = create_network<SFUNC(Tnet)>(theparam, conf, noutputs); // loading weights if (!conf.exists("weights")) { // manual weights cerr << "warning: \"weights\" variable not defined, loading manually " << "if manual_load defined" << endl; if (conf.exists_true("manual_load")) manually_load_network(*((layers<SFUNC(Tnet)>*)net), conf); } else { // multiple-file weights // concatenate weights if multiple ones vector<string> w = string_to_stringvector(conf.get_string("weights")); cout << "Loading weights from: " << w << endl; theparam.load_x(w); } // detector detector<fs(Tnet)> detect(*net, sclasses, *ans, NULL, NULL); // multi-scaling parameters double maxs = conf.exists("max_scale")?conf.get_double("max_scale") : 1.0; double mins = conf.exists("min_scale")?conf.get_double("min_scale") : 1.0; t_scaling scaling_type = SCALES_STEP; vector<idxdim> scales; if (conf.exists("scaling_type")) scaling_type = (t_scaling) conf.get_uint("scaling_type"); switch (scaling_type) { case MANUAL: if (!conf.exists("scales")) eblerror("expected \"scales\" variable to be defined in manual mode"); scales = string_to_idxdimvector(conf.get_cstring("scales")); detect.set_resolutions(scales); break ; case ORIGINAL: detect.set_scaling_original(); break ; case SCALES_STEP: detect.set_resolutions(conf.get_double("scaling"), maxs, mins); break ; case SCALES_STEP_UP: detect.set_resolutions(conf.get_double("scaling"), maxs, mins); detect.set_scaling_type(scaling_type); break ; default: detect.set_scaling_type(scaling_type); } // optimize memory usage by using only 2 buffers for entire flow SBUF<Tnet> input(1, 1, 1), output(1, 1, 1); if (!conf.exists_false("mem_optimization")) detect.set_mem_optimization(input, output, true); // zero padding float hzpad = 0, wzpad = 0; if (conf.exists("hzpad")) hzpad = conf.get_float("hzpad"); if (conf.exists("wzpad")) wzpad = conf.get_float("wzpad"); detect.set_zpads(hzpad, wzpad); bool bmask_class = false; if (conf.exists("mask_class")) bmask_class = detect.set_mask_class(conf.get_cstring("mask_class")); if (conf.exists("input_min")) // limit inputs size detect.set_min_resolution(conf.get_uint("input_min")); if (conf.exists("input_max")) // limit inputs size detect.set_max_resolution(conf.get_uint("input_max")); detect.set_silent(); if (conf.exists_bool("save_detections")) { string detdir = outdir; detdir += "detections"; detdir = detect.set_save(detdir); if (conf.exists("save_max_per_frame")) detect.set_save_max_per_frame(conf.get_uint("save_max_per_frame")); } // nms detect.set_cluster_nms(conf.exists_true("cluster_nms")); detect.set_scaler_mode(conf.exists_true("scaler_mode")); if (conf.exists("nms")) detect.set_pruning((t_pruning)conf.get_uint("nms"), conf.exists("min_hcenter_dist") ? conf.get_float("min_hcenter_dist") : 0.0, conf.exists("min_wcenter_dist") ? conf.get_float("min_wcenter_dist") : 0.0, conf.exists("bbox_max_overlap") ? conf.get_float("bbox_max_overlap") : 1.0, conf.exists_true("share_parts"), conf.exists("threshold2") ? (Tnet) conf.get_float("threshold2") : 0.0, conf.exists("bbox_max_center_dist") ? conf.get_float("bbox_max_center_dist") : 0.0, conf.exists("bbox_max_center_dist2") ? conf.get_float("bbox_max_center_dist2") : 0.0, conf.exists("bbox_max_wcenter_dist") ? conf.get_float("bbox_max_wcenter_dist") : 0.0, conf.exists("bbox_max_wcenter_dist2") ? conf.get_float("bbox_max_wcenter_dist2") : 0.0, conf.exists("min_wcenter_dist2") ? conf.get_float("min_wcenter_dist2") : 0.0, conf.exists("bbox_max_overlap2") ? conf.get_float("bbox_max_overlap2") : 0.0, conf.exists_true("mean_bb"), conf.exists("same_scale_mhd") ? conf.get_float("same_scale_mhd") : 0.0, conf.exists("same_scale_mwd") ? conf.get_float("same_scale_mwd") : 0.0, conf.exists("min_scale_pred") ? conf.get_float("min_scale_pred") : 0.0, conf.exists("max_scale_pred") ? conf.get_float("max_scale_pred") : 0.0 ); if (conf.exists("bbox_hfactor") && conf.exists("bbox_wfactor")) detect.set_bbox_factors(conf.get_float("bbox_hfactor"), conf.get_float("bbox_wfactor"), conf.exists("bbox_woverh") ? conf.get_float("bbox_woverh") : 1.0, conf.exists("bbox_hfactor2") ? conf.get_float("bbox_hfactor2") : 1.0, conf.exists("bbox_wfactor2") ? conf.get_float("bbox_wfactor2") : 1.0); if (conf.exists("max_object_hratio")) detect.set_max_object_hratio(conf.get_double("max_object_hratio")); if (conf.exists("net_min_height") && conf.exists("net_min_width")) detect.set_min_input(conf.get_int("net_min_height"), conf.get_int("net_min_width")); if (conf.exists("smoothing")) detect.set_smoothing(conf.get_uint("smoothing")); if (conf.exists("background_name")) detect.set_bgclass(conf.get_cstring("background_name")); // image search can be configured with a search pattern const char *fpattern = IMAGE_PATTERN_MAT; if (conf.exists("file_pattern")) fpattern = conf.get_cstring("file_pattern"); // initialize camera (opencv, directory, shmem or video) idx<ubyte> frame; camera<ubyte> *cam = NULL, *cam2 = NULL; if (!strcmp(cam_type.c_str(), "directory")) { string dir; if (argc >= 3) // read input dir from command line dir = argv[2]; else if (conf.exists("input_dir")) dir = conf.get_string("input_dir"); // given list list<string> files; if (conf.exists("input_list")) { files = string_to_stringlist(conf.get_string("input_list")); cam = new camera_directory<ubyte>(dir.c_str(), height, width, input_random, npasses, std::cout, std::cerr, fpattern, &files); } else // given directory only cam = new camera_directory<ubyte>(dir.c_str(), height, width, input_random, npasses, std::cout, std::cerr, fpattern, &files); } else if (!strcmp(cam_type.c_str(), "opencv")) cam = new camera_opencv<ubyte>(-1, height, width); #ifdef __LINUX__ else if (!strcmp(cam_type.c_str(), "v4l2")) cam = new camera_v4l2<ubyte>(conf.get_cstring("device"), height, width, conf.exists_true("camera_grayscale")); #endif else if (!strcmp(cam_type.c_str(), "shmem")) cam = new camera_shmem<ubyte>("shared-mem", height, width); else if (!strcmp(cam_type.c_str(), "video")) { if (argc >= 3) cam = new camera_video<ubyte> (argv[2], height, width, conf.get_uint("input_video_sstep"), conf.get_uint("input_video_max_duration")); else eblerror("expected 2nd argument"); } else eblerror("unknown camera type"); // a camera directory may be used first, then switching to regular cam if (conf.exists_bool("precamera")) cam2 = new camera_directory<ubyte>(conf.get_cstring("precamdir"), height, width); // answer variables & initializations vector<bbox*> bboxes; vector<bbox*>::iterator ibboxes; ostringstream answer_fname; mkdir_full(outdir); answer_fname << outdir << "bbox.txt"; // open file ofstream fp(answer_fname.str().c_str()); if (!fp) { cerr << "failed to open " << answer_fname.str() << endl; eblerror("open failed"); } // gui #ifdef __GUI__ display = conf.exists_bool("display"); mindisplay = conf.exists_bool("minimal_display"); display_sleep = conf.get_uint("display_sleep"); display_states = conf.exists_bool("display_states"); save_video = conf.exists_bool("save_video"); uint qstep1 = 0, qheight1 = 0, qwidth1 = 0, qheight2 = 0, qwidth2 = 0, qstep2 = 0; if (conf.exists_bool("queue1")) { qstep1 = conf.get_uint("qstep1"); qheight1 = conf.get_uint("qheight1"); qwidth1 = conf.get_uint("qwidth1"); } if (conf.exists_bool("queue2")) { qstep2 = conf.get_uint("qstep2"); qheight2 = conf.get_uint("qheight2"); qwidth2 = conf.get_uint("qwidth2"); } module_1_1_gui netgui; wid_states = display_states ? new_window("network states"):0; night_mode(); wid = display ? new_window("eblearn object recognition") : 0; night_mode(); float zoom = 1; detector_gui<fs(Tnet)> dgui(conf.exists_bool("queue1"), qstep1, qheight1, qwidth1, conf.exists_bool("queue2"), qstep2, qheight2, qwidth2); if (bmask_class) dgui.set_mask_class(conf.get_cstring("mask_class"), (Tnet) conf.get_double("mask_threshold")); if (save_video) { string viddir = outdir; viddir += "video"; cam->start_recording(wid, viddir.c_str()); } #endif // timing variables timer tpass, toverall; long ms; // loop toverall.start(); while(!cam->empty()) { // get a new frame tpass.restart(); // if the pre-camera is defined use it until empty if (cam2 && !cam2->empty()) frame = cam2->grab(); else // empty pre-camera, use regular camera frame = cam->grab(); string frame_name = cam->frame_name(); // run detector if (!display) { // fprop without display bboxes = detect.fprop(frame, threshold, frame_name.c_str()); } #ifdef __GUI__ else { // fprop and display disable_window_updates(); clear_window(); if (mindisplay) bboxes = dgui.display(detect, frame, threshold, frame_name.c_str(), 0, 0, zoom, (Tnet)0, (Tnet)255, wid); else bboxes = dgui.display_inputs_outputs(detect, frame, threshold, frame_name.c_str(), 0, 0, zoom, (Tnet)-1.1, (Tnet)1.1, wid); enable_window_updates(); if (display_states) { dgui.display_current(detect, frame, wid_states); select_window(wid); } if (save_video) cam->record_frame(); } #endif ms = tpass.elapsed_milliseconds(); cout << "processing: " << ms << " ms." << endl; cout << "fps: " << cam->fps() << endl; // save bounding boxes for (ibboxes = bboxes.begin(); ibboxes != bboxes.end(); ++ibboxes) { fp << cam->frame_name() << " " << (*ibboxes)->class_id << " " << (*ibboxes)->confidence << " "; fp << (*ibboxes)->w0 << " " << (*ibboxes)->h0 << " "; fp << (*ibboxes)->w0 + (*ibboxes)->width << " "; fp << (*ibboxes)->h0 + (*ibboxes)->height << endl; } // sleep display if (display_sleep > 0) { cout << "sleeping for " << display_sleep << "ms." << endl; millisleep(display_sleep); } if (conf.exists("save_max") && detect.get_total_saved() > conf.get_uint("save_max")) { cout << "Reached max number of detections, exiting." << endl; break ; // limit number of detection saves } } cout << "Execution time: " << toverall.elapsed_minutes() <<" mins" <<endl; if (save_video) cam->stop_recording(conf.exists_bool("use_original_fps") ? cam->fps() : conf.get_uint("save_video_fps")); // free variables if (net) delete net; if (cam) delete cam; // close files fp.close(); #ifdef __GUI__ if (!conf.exists_true("no_gui_quit")) { cout << "Closing windows..." << endl; quit_gui(); // close all windows cout << "Windows closed." << endl; } #endif } eblcatcherror(); return 0; }
int main() { ipp_message *msg; ipp_card *Ks, *Kd, *Kh, *Kc; ipp_card *As, *Ad, *Ah; ipp_player *player; ipp_table *table; int rc, i; ipp_init(); table = ipp_new_table(); player = ipp_new_player(); assertNotNull("Table should not be null.", table); assertNotNull("Player should not be null.", player); assertEqual("Table shouldn't have any players", table->nplayers, 0); rc = ipp_add_player(table, player); assertNotEqual("Should have been able to add player", rc, -1); assertEqual("Should have one player", table->nplayers, 1); Kh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kh); Kh->rank = KING; Kh->suit = HEARTS; Kc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kc); Kc->rank = KING; Kc->suit = CLUBS; Ks = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ks); Ks->rank = KING; Ks->suit = SPADES; Kd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kd); Kd->rank = KING; Kd->suit = DIAMONDS; Ah = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ah); Ah->rank = ACE; Ah->suit = HEARTS; As = ipp_new_card(); assertNotNull("ipp_new_card() failed", As); As->rank = ACE; As->suit = SPADES; Ad = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ad); Ad->rank = ACE; Ad->suit = DIAMONDS; table->board[0] = Ad; table->board[1] = Ah; table->board[2] = Kd; table->board[3] = Kh; table->board[4] = Kc; table->players[0]->hole[0] = As; table->players[0]->hole[1] = Ks; table->stage = SHOWDOWN; msg = ipp_best_combination(table, 0); assertNotNull("ipp_best_combination() should have return an answer", msg); printf("%s\n", msg->payload); assertStringEqual("Out of Ad Ah As Kd Ks Kh Kc, FOUROFAKIND K A should be the best hand.", "FOUROFAKIND K A", msg->payload); ipp_free_message(msg); ipp_free_table(table); /* will also free player */ ipp_exit(); return PASS; }
int main() { ipp_message *msga, *msgb; ipp_card *Kh; ipp_card *Ac, *Kc; ipp_card *Ad, *Kd; ipp_card *As, *Ks, *Qs, *Js, *Ts, *_9s, *_7s, *_6s; ipp_card *hand[5]; ipp_init(); Kh = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kh); Kh->rank = KING; Kh->suit = HEARTS; Ac = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ac); Ac->rank = ACE; Ac->suit = CLUBS; Kc = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kc); Kc->rank = KING; Kc->suit = CLUBS; Ad = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ad); Ad->rank = ACE; Ad->suit = DIAMONDS; Kd = ipp_new_card(); assertNotNull("ipp_new_card() failed", Kd); Kd->rank = KING; Kd->suit = DIAMONDS; As = ipp_new_card(); assertNotNull("ipp_new_card() failed", As); As->rank = ACE; As->suit = SPADES; Ks = ipp_new_card(); assertNotNull("ipp_new_card() failed", Ks); Ks->rank = KING; Ks->suit = SPADES; Qs = ipp_new_card(); assertNotNull("ipp_new_card() failed", Qs); Qs->rank = QUEEN; Qs->suit = SPADES; Js = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Js->rank = JACK; Js->suit = SPADES; Ts = ipp_new_card(); assertNotNull("ipp_new_card() failed", Js); Ts->rank = TEN; Ts->suit = SPADES; _9s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _9s); _9s->rank = NINE; _9s->suit = SPADES; _7s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _7s); _7s->rank = SEVEN; _7s->suit = SPADES; _6s = ipp_new_card(); assertNotNull("ipp_new_card() failed", _6s); _6s->rank = SIX; _6s->suit = SPADES; /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_STRAIGHTFLUSH); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_STRAIGHTFLUSH); hand[0] = As; hand[1] = Kd; hand[2] = Js; hand[3] = _7s; hand[4] = _6s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "HIGHCARD A K J 7 6", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_HIGHCARD); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Ks; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_STRAIGHTFLUSH); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_STRAIGHTFLUSH); hand[0] = Ks; hand[1] = Qs; hand[2] = Js; hand[3] = Ts; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "STRAIGHTFLUSH K", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_STRAIGHTFLUSH); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Ks; hand[2] = Kd; hand[3] = Kh; hand[4] = Kc; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "FOUROFAKIND K A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_FOUROFAKIND); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_FOUROFAKIND); hand[0] = Ks; hand[1] = Kd; hand[2] = Kh; hand[3] = Kc; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "FOUROFAKIND K 9", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_FOUROFAKIND); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Kd; hand[2] = Qs; hand[3] = Js; hand[4] = Ts; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "STRAIGHT A", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_STRAIGHT); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_STRAIGHT); hand[0] = Qs; hand[1] = Kd; hand[2] = Js; hand[3] = Ts; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "STRAIGHT K", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_STRAIGHT); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Kd; hand[2] = Ac; hand[3] = Ad; hand[4] = Ks; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "FULLHOUSE A K", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_FULLHOUSE); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_FULLHOUSE); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = Ac; hand[4] = Kh; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "FULLHOUSE K A", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_FULLHOUSE); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = As; hand[1] = Kd; hand[2] = Ac; hand[3] = Ts; hand[4] = Ks; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "TWOPAIR A K T", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_TWOPAIR); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_TWOPAIR); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = Ac; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "TWOPAIR A K 9", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_TWOPAIR); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = _9s; hand[1] = Ad; hand[2] = Ac; hand[3] = Ts; hand[4] = As; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "THREEOFAKIND A T 9", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_THREEOFAKIND); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_THREEOFAKIND); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = Kh; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "THREEOFAKIND K A 9", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_THREEOFAKIND); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = _9s; hand[1] = Ad; hand[2] = _7s; hand[3] = Ts; hand[4] = As; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "ONEPAIR A T 9 7", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_ONEPAIR); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_ONEPAIR); hand[0] = Ks; hand[1] = Kd; hand[2] = As; hand[3] = _7s; hand[4] = _9s; msgb = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msgb); assertStringEqual("Didn't detect proper hand.", "ONEPAIR K A 9 7", msgb->payload); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msgb->payload), MSG_ONEPAIR); assertEqual("msga should beat msgb", 1, ipp_hand_compar(msga, msgb)); assertEqual("msga should beat msgb", -1, ipp_hand_compar(msgb, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); ipp_free_message(msga); ipp_free_message(msgb); /* =-=-=-=-=-= */ hand[0] = _9s; hand[1] = Ad; hand[2] = _7s; hand[3] = Ts; hand[4] = As; msga = ipp_eval(hand); assertNotNull("ipp_eval() returned null", msga); assertStringEqual("Didn't detect proper hand.", "ONEPAIR A T 9 7", msga->payload); assertEqual("Didn't detect proper hand.", msga->type, MSG_ONEPAIR); assertEqual("Didn't detect proper hand.", ipp_validate_unknown_msg(msga->payload), MSG_ONEPAIR); assertEqual("msga should beat NULL", 1, ipp_hand_compar(msga, NULL)); assertEqual("msga should beat NULL", -1, ipp_hand_compar(NULL, msga)); assertEqual("msga should equal msga", 0, ipp_hand_compar(msga, msga)); assertEqual("NULL should equal NULL", 0, ipp_hand_compar(NULL, NULL)); ipp_free_message(msga); /* =-=-=-=-=-= */ ipp_free_card(_6s); ipp_free_card(_7s); ipp_free_card(_9s); ipp_free_card(Ts); ipp_free_card(Js); ipp_free_card(Qs); ipp_free_card(Ks); ipp_free_card(As); ipp_free_card(Kd); ipp_free_card(Ad); ipp_free_card(Kc); ipp_free_card(Ac); ipp_free_card(Kh); ipp_exit(); return PASS; }
MAIN_QTHREAD(int, argc, char **, argv) { // macro to enable multithreaded gui #else int main(int argc, char **argv) { // regular main without gui #endif try { // check input parameters if ((argc != 2) && (argc != 3) ) { cerr << "warning: wrong number of parameters." << endl; cerr << "usage: detect <config file> [directory or file]" << endl; // return -1; } #ifdef __LINUX__ feenableexcept(FE_DIVBYZERO | FE_INVALID); // enable float exceptions #endif // load configuration configuration conf(argv[1], true, true, false); if (conf.exists_true("fixed_randomization")) cout << "Using fixed seed: " << fixed_init_drand() << endl; else cout << "Using random seed: " << dynamic_init_drand(argc, argv) << endl; if (!conf.exists("root2") || !conf.exists("current_dir")) { string dir; dir << dirname(argv[1]) << "/"; cout << "Looking for trained files in: " << dir << endl; conf.set("root2", dir.c_str()); conf.set("current_dir", dir.c_str()); } conf.set("run_type", "detect"); // tell conf that we are in detect mode conf.resolve(); // manual call to resolving variable bool silent = conf.exists_true("silent"); if (conf.exists_true("show_conf") && !silent) conf.pretty(); // output synchronization bool sync = conf.exists_true("sync_outputs"); mutex out_mutex; mutex_ostream mutout(std::cout, &out_mutex, "Thread M"); mutex_ostream muterr(std::cerr, &out_mutex, "Thread M"); ostream &mout = sync ? mutout : cout; ostream &merr = sync ? muterr : cerr; bootstrapping<t_net> boot(conf); // output dir string outdir = detection_thread<t_net>::get_output_directory(conf); mout << "Saving outputs to " << outdir << endl; // save conf to output dir string cname = outdir; cname << filename(argv[1]); if (conf.write(cname.c_str())) mout << "Wrote configuration to " << cname << endl; // load classes of network idx<ubyte> classes(1,1); vector<string> sclasses; try { // try loading classes names but do not stop upon failure load_matrix<ubyte>(classes, conf.get_cstring("classes")); } catch(string &err) { merr << "warning: " << err << endl; } sclasses = ubyteidx_to_stringvector(classes); t_bbox_saving bbsaving = bbox_none; if (conf.exists("bbox_saving")) bbsaving = (t_bbox_saving) conf.get_int("bbox_saving"); bboxes boxes(bbsaving, &outdir, mout, merr); uint ipp_cores = 1; if (conf.exists("ipp_cores")) ipp_cores = conf.get_uint("ipp_cores"); ipp_init(ipp_cores); // limit IPP (if available) to 1 core bool save_video = conf.exists_true("save_video"); bool save_detections = conf.exists_true("save_detections"); int height = -1; int width = -1; if (conf.exists("input_height")) height = conf.get_int("input_height"); if (conf.exists("input_width")) width = conf.get_int("input_width"); bool input_random = conf.exists_true("input_random"); uint npasses = 1; char next_on_key = 0; if (conf.exists("next_on_key")) { next_on_key = conf.get_char("next_on_key"); mout << "Press " << next_on_key << " to process next frame." << endl; } uint skip_frames = conf.try_get_uint("skip_frames", 0); if (conf.exists("input_npasses")) npasses = conf.get_uint("input_npasses"); string viddir; if (save_video) { viddir << outdir << "video/"; mkdir_full(viddir); } bool precomputed_boxes = conf.exists("bbox_file"); uint save_bbox_period = conf.try_get_uint("save_bbox_period", 500); idxdim crop(1, 1, 1); if (conf.exists("input_crop")) crop = string_to_idxdim(conf.get_string("input_crop")); string cam_type; #ifdef __LINUX__ // default camera for linux if not defined cam_type = "v4l2"; #endif if (conf.exists("camera")) cam_type = conf.get_string("camera"); // allocate threads uint nthreads = 1; bool updated = false; idx<ubyte> detframe; // frame returned by detection thread uint frame_id = 0; svector<midx<t_net> > all_samples, samples; // extracted samples bboxes all_bbsamples, bbsamples; // boxes corresponding to samples if (conf.exists("nthreads")) nthreads = (std::max)((uint) 1, conf.get_uint("nthreads")); list<detection_thread<t_net>*> threads; list<detection_thread<t_net>*>::iterator ithreads; idx<uint> total_saved(nthreads); idx_clear(total_saved); mout << "Initializing " << nthreads << " detection threads." << endl; for (uint i = 0; i < nthreads; ++i) { detection_thread<t_net> *dt = new detection_thread<t_net>(conf, &out_mutex, NULL, NULL, sync); threads.push_back(dt); dt->start(); } // image search can be configured with a search pattern const char *fpattern = IMAGE_PATTERN_MAT; if (conf.exists("file_pattern")) fpattern = conf.get_cstring("file_pattern"); // initialize camera (opencv, directory, shmem or video) idx<ubyte> frame(std::max(height, 1), std::max(width, 1), 3); camera<ubyte> *cam = NULL, *cam2 = NULL; if (!strcmp(cam_type.c_str(), "directory")) { string dir; if (argc >= 3) // read input dir from command line dir = argv[2]; else if (conf.exists("input_dir")) dir = conf.get_string("input_dir"); // given list list<string> files; if (conf.exists("input_list")) { files = string_to_stringlist(conf.get_string("input_list")); cam = new camera_directory<ubyte>(dir.c_str(), height, width, input_random, npasses, mout, merr, fpattern, &files); } else // given directory only cam = new camera_directory<ubyte>(dir.c_str(), height, width, input_random, npasses, mout, merr, fpattern, &files); } else if (!strcmp(cam_type.c_str(), "opencv")) cam = new camera_opencv<ubyte>(-1, height, width); #ifdef __LINUX__ else if (!strcmp(cam_type.c_str(), "v4l2")) cam = new camera_v4l2<ubyte>(conf.get_cstring("device"), height, width, conf.exists_true("camera_grayscale"), conf.exists_true("camera_rgb")); else if (!strcmp(cam_type.c_str(), "mac")) cam = new camera_mac<ubyte>(conf.get_cstring("device"), height, width, conf.exists_true("camera_grayscale"), conf.exists_true("camera_rgb")); else if (!strcmp(cam_type.c_str(), "mcams")) { vector<string> devices = conf.get_all_strings("device"); cam = new camera_mcams<ubyte>(conf, devices, height, width, conf.exists_true("camera_grayscale"), conf.exists_true("camera_rgb")); } #endif #ifdef __KINECT__ else if (!strcmp(cam_type.c_str(), "kinect")) cam = new camera_kinect<ubyte>(height, width); #endif else if (!strcmp(cam_type.c_str(), "shmem")) cam = new camera_shmem<ubyte>("shared-mem", height, width); else if (!strcmp(cam_type.c_str(), "video")) { if (argc >= 3) cam = new camera_video<ubyte> (argv[2], height, width, conf.get_uint("input_video_sstep"), conf.get_uint("input_video_max_duration")); else eblerror("expected 2nd argument"); } else if (!strcmp(cam_type.c_str(), "datasource")) { cam = new camera_datasource<ubyte,int>(conf); } else eblerror("unknown camera type, set \"camera\" in your .conf"); // a camera directory may be used first, then switching to regular cam if (conf.exists_true("precamera")) cam2 = new camera_directory<ubyte>(conf.get_cstring("precamdir"), height, width, input_random, npasses, mout, merr, fpattern); if (conf.exists_true("camera_grayscale")) cam->set_grayscale(); if (conf.exists_true("silent")) cam->set_silent(); // answer variables & initializations bboxes bb; // gui #ifdef __GUI__ bool bkey_msg = false; // display key message bool display = conf.exists_bool("display"); bool show_parts = conf.exists_true("show_parts"); bool bbox_show_conf = !conf.exists_false("bbox_show_conf"); bool bbox_show_class = !conf.exists_false("bbox_show_class"); // mindisplay = conf.exists_bool("minimal_display"); uint display_sleep = 0; if (conf.exists("display_sleep")) display_sleep = conf.get_uint("display_sleep"); // display_states = conf.exists_bool("display_states"); // uint qstep1 = 0, qheight1 = 0, qwidth1 = 0, // qheight2 = 0, qwidth2 = 0, qstep2 = 0; // if (conf.exists_bool("queue1")) { // qstep1 = conf.get_uint("qstep1"); // qheight1 = conf.get_uint("qheight1"); // qwidth1 = conf.get_uint("qwidth1"); } // if (conf.exists_bool("queue2")) { // qstep2 = conf.get_uint("qstep2"); // qheight2 = conf.get_uint("qheight2"); // qwidth2 = conf.get_uint("qwidth2"); } // wid_states = display_states ? new_window("network states"):0; // night_mode(); uint wid = display ? new_window("eblearn object recognition") : 0; night_mode(); float display_transp = 0.0; if (conf.exists("display_bb_transparency")) display_transp = conf.get_float("display_bb_transparency"); detector_gui<t_net> dgui(conf.exists_true("show_extracted")); #endif // timing variables timer tpass, toverall, tstop; uint cnt = 0; bool stop = false, finished = false; // loop toverall.start(); while (!finished) { // check for results and send new image for each thread uint i = 0; finished = true; for (ithreads = threads.begin(); ithreads != threads.end(); ++ithreads, ++i) { // do nothing if thread is finished already if ((*ithreads)->finished()) continue ; finished = false; // a thread is not finished string processed_fname; uint processed_id = 0; // retrieve new data if present bool skipped = false; updated = (*ithreads)->get_data (bb, detframe, *(total_saved.idx_ptr() + i), processed_fname, &processed_id, &samples, &bbsamples, &skipped); if (skipped) cnt++; // a new skipped frame was received // save bounding boxes if (updated) { idxdim d(detframe); if (boot.activated()) bb.clear(); if (bbsaving != bbox_none) { if (!silent) mout << "Adding " << bb.size() << " boxes into new group: " << processed_fname << " with id " << processed_id << endl; boxes.new_group(d, &processed_fname, processed_id); boxes.add(bb, d, &processed_fname, processed_id); if (cnt % save_bbox_period == 0) boxes.save(); // avoid sample accumulation if not using bootstrapping if (boot.activated()) mout << "Received " << samples.size() << " bootstrapping samples." << endl; } if (conf.exists_true("bootstrapping_save")) { all_samples.push_back_new(samples); all_bbsamples.push_back_new(bbsamples); } // datasource mode, check and log answers if (dynamic_cast<camera_datasource<ubyte,int>*>(cam)) { camera_datasource<ubyte,int>* dscam = (camera_datasource<ubyte,int>*) cam; dscam->log_answers(bb); } cnt++; // display processed frame #ifdef __GUI__ if (display) { select_window(wid); disable_window_updates(); clear_resize_window(); set_window_title(processed_fname.c_str()); uint h = 0, w = 0; // display frame with resulting boxes dgui.display_minimal (detframe, bb, ((*ithreads)->pdetect ? (*ithreads)->pdetect->get_labels() : sclasses), h, w, 1, 0, 255, wid, show_parts, display_transp, bbox_show_class, bbox_show_conf, &bbsamples); // display extracted samples if (boot.activated()) { dgui.display_preprocessed (samples, bbsamples, ((*ithreads)->pdetect ? (*ithreads)->pdetect->get_labels() : sclasses), h, w, 1, -1, 1); } enable_window_updates(); if (save_video && display) { string fname; fname << viddir << processed_fname; save_window(fname.c_str()); if (!silent) mout << "saved " << fname << endl; } } // sleep display if (display_sleep > 0) { mout << "sleeping for " << display_sleep << "ms." << endl; millisleep(display_sleep); } #endif if (!silent) { // output info uint k = cnt, tot = cam->size() - cnt; // progress variables if (conf.exists("save_max")) tot = conf.get_uint("save_max"); if (!silent) { if (save_detections) { mout << "total_saved=" << idx_sum(total_saved); if (conf.exists("save_max")) mout << " / " << tot; mout << endl; } } if (boot.activated()) mout << "total_bootstrapping=" << all_samples.size() << endl; mout << "remaining=" << (cam->size() - cnt) << " elapsed=" << toverall.elapsed(); if (cam->size() > 0) mout << " ETA=" << toverall.eta(cnt, cam->size()); if (conf.exists("save_max") && save_detections) { k = idx_sum(total_saved); mout << " save_max_ETA=" << toverall.eta(k, tot); } mout << endl; mout << "i=" << cnt << " processing: " << tpass.elapsed_ms() << " fps: " << cam->fps() << endl; // save progress if (!conf.exists_false("save_progress")) job::write_progress(k, tot); } } // check if ready if ((*ithreads)->available()) { if (stop) (*ithreads)->ask_stop(); // stop but let thread finish else { // grab a new frame if available if (cam->empty()) { stop = true; tstop.start(); // start countdown timer (*ithreads)->ask_stop(); // ask this thread to stop millisleep(50); } else { #ifdef __GUI__ int key = gui.pop_key_pressed(); // if thread has already received data, wait for next key if ((*ithreads)->fed() && next_on_key) { if ((int)next_on_key != key && (int)next_on_key != key + 32) { if (!bkey_msg) mout << "Press " << next_on_key << " to process next frame." << endl; bkey_msg = true; continue ; // pause until key is pressed } else { mout << "Key pressed (" << key << ") allowing next frame to process." << endl; bkey_msg = false; tpass.restart(); } } #endif bool frame_grabbed = false; frame_id = cam->frame_id(); // if the pre-camera is defined use it until empty if (cam2 && !cam2->empty()) frame = cam2->grab(); else { // empty pre-camera, use regular camera if (skip_frames > 0) cam->skip(skip_frames); // skip frames if skip_frames > 0 if (cam->empty()) continue ; if (precomputed_boxes && !save_video) cam->next(); // move to next frame but without grabbing else if (dynamic_cast<camera_directory<ubyte>*>(cam)) { cam->grab_filename(); // just get the filename, no data } else { // actually grab the frame frame = cam->grab(); frame_grabbed = true; // cropping if (crop.nelements() > crop.order()) { cout << "cropping frame from " << frame; for (uint i = 0; i < crop.order(); ++i) if (crop.dim(i) > 1) frame = frame.narrow(i, crop.dim(i), 0); cout << " to " << frame << endl; } } } // send new frame to this thread string ffname = cam->frame_fullname(); string fname = cam->frame_name(); if (frame_grabbed) { while (!(*ithreads)->set_data(frame, ffname, fname, frame_id)) millisleep(5); } else { while (!(*ithreads)->set_data(ffname, fname, frame_id)) millisleep(5); } // we just sent a new frame tpass.restart(); } } } } if ((conf.exists("save_max") && !stop && idx_sum(total_saved) > conf.get_uint("save_max")) || (boot.activated() && (intg) all_samples.size() > boot.max_size())) { mout << "Reached max number of detections, exiting." << endl; stop = true; // limit number of detection saves tstop.start(); // start countdown timer } // sleep a bit between each iteration millisleep(5); // check if stop countdown reached 0 if (stop && tstop.elapsed_minutes() >= 20) { cerr << "threads did not all return 20 min after request, stopping" << endl; break ; // program too long to stop, force exit } } // saving boxes if (bbsaving != bbox_none) boxes.save(); mout << "Execution time: " << toverall.elapsed() << endl; if (save_video) cam->stop_recording(conf.exists_bool("use_original_fps") ? cam->fps() : conf.get_uint("save_video_fps"), outdir.c_str()); // saving bootstrapping if (conf.exists_true("bootstrapping_save") && boot.activated()) boot.save_dataset(all_samples, all_bbsamples, outdir, classes); // free variables if (cam) delete cam; for (ithreads = threads.begin(); ithreads != threads.end(); ++ithreads) { if (!(*ithreads)->finished()) (*ithreads)->stop(); // stop thread without waiting delete *ithreads; } #ifdef __GUI__ if (!conf.exists_true("no_gui_quit") && !conf.exists("next_on_key")) { mout << "Closing windows..." << endl; quit_gui(); // close all windows mout << "Windows closed." << endl; } #endif job::write_finished(); // declare job finished mout << "Detection finished." << endl; // evaluation of bbox if (conf.exists_true("evaluate") && conf.exists("evaluate_cmd")) { string cmd; cmd << "cd " << outdir << " && " << conf.get_string("evaluate_cmd"); int res = std::system(cmd.c_str()); if (res != 0) cerr << "bbox evaluation failed with command " << cmd << endl; } } eblcatcherror(); return 0; }