static void test_values(void) { int i; gpr_timespec x = gpr_time_0(GPR_CLOCK_REALTIME); GPR_ASSERT(x.tv_sec == 0 && x.tv_nsec == 0); x = gpr_inf_future(GPR_CLOCK_REALTIME); fprintf(stderr, "far future "); i_to_s(x.tv_sec, 16, 16, &to_fp, stderr); fprintf(stderr, "\n"); GPR_ASSERT(x.tv_sec == INT64_MAX); fprintf(stderr, "far future "); ts_to_s(x, &to_fp, stderr); fprintf(stderr, "\n"); x = gpr_inf_past(GPR_CLOCK_REALTIME); fprintf(stderr, "far past "); i_to_s(x.tv_sec, 16, 16, &to_fp, stderr); fprintf(stderr, "\n"); GPR_ASSERT(x.tv_sec == INT64_MIN); fprintf(stderr, "far past "); ts_to_s(x, &to_fp, stderr); fprintf(stderr, "\n"); for (i = 1; i != 1000 * 1000 * 1000; i *= 10) { x = gpr_time_from_micros(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec == i / GPR_US_PER_SEC && x.tv_nsec == (i % GPR_US_PER_SEC) * GPR_NS_PER_US); x = gpr_time_from_nanos(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec == i / GPR_NS_PER_SEC && x.tv_nsec == (i % GPR_NS_PER_SEC)); x = gpr_time_from_millis(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec == i / GPR_MS_PER_SEC && x.tv_nsec == (i % GPR_MS_PER_SEC) * GPR_NS_PER_MS); } /* Test possible overflow in conversion of -ve values. */ x = gpr_time_from_micros(-(LONG_MAX - 999997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); x = gpr_time_from_nanos(-(LONG_MAX - 999999997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); x = gpr_time_from_millis(-(LONG_MAX - 997), GPR_TIMESPAN); GPR_ASSERT(x.tv_sec < 0); GPR_ASSERT(x.tv_nsec >= 0 && x.tv_nsec < GPR_NS_PER_SEC); /* Test general -ve values. */ for (i = -1; i > -1000 * 1000 * 1000; i *= 7) { x = gpr_time_from_micros(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec * GPR_US_PER_SEC + x.tv_nsec / GPR_NS_PER_US == i); x = gpr_time_from_nanos(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec * GPR_NS_PER_SEC + x.tv_nsec == i); x = gpr_time_from_millis(i, GPR_TIMESPAN); GPR_ASSERT(x.tv_sec * GPR_MS_PER_SEC + x.tv_nsec / GPR_NS_PER_MS == i); } }
/* Convert ts to ascii, and write with (*writer)(arg, ...). */ static void ts_to_s(gpr_timespec t, void (*writer)(void *arg, const char *buf, size_t len), void *arg) { if (t.tv_sec < 0 && t.tv_nsec != 0) { t.tv_sec++; t.tv_nsec = GPR_NS_PER_SEC - t.tv_nsec; } i_to_s(t.tv_sec, 10, 0, writer, arg); (*writer)(arg, ".", 1); i_to_s(t.tv_nsec, 10, 9, writer, arg); }
/* @Core */ Mat PDCounter::detect(Mat& input) { string log1("Begin detecting...\n"); Mat output = input.clone(); for (vector<PDDetector>::iterator it = Detectors.begin(); it != Detectors.end(); it++) { (*it).detect(output, Trackers);// NO parallel } string log2("All areas are detected...\n"); string lost = i_to_s(Trackers.tracking(output)); // NO parallel string log3("Tracking completed...\nThe trackers lost " + lost + " pedestrians in this frame.\n"); if (showPedestrian) { drawFounds(output, Trackers.getCurrRects(), PEDESTRIAN_COLOR); } if (showArea) { for (vector<PDDetector>::iterator it = Detectors.begin(); it != Detectors.end(); it++) { drawArea(output, (*it).getArea(), AREA_COLOR); } } if (showTrajectory) { for (int i = 0; i < Trackers.getSize(); i++) { drawTrajectory(output, Trackers[i].getTrajectory(), Trajectory_COLOR); } } string log4("Drawing completed"); lastLog = log1 + log2 + log3 + log4; return output; }
bool PDCounter::delAreaByClick(Mat& frame) { ////////////Pending to write.///////////////// Mat show_frame; Point choose; for (vector<PDDetector>::iterator it = Detectors.begin(); it != Detectors.end(); it++) { drawArea(show_frame, show_frame, (*it).getArea(), AREA_COLOR); } pic_manipulator painter(show_frame); painter.get_click_info(); choose = painter.getPoint(); for (vector<PDDetector>::iterator it = Detectors.begin(); it != Detectors.end(); it++) { if (choose.inside((*it).getArea())) { int ID = (*it).getID(); (*it).boom(); Detectors.erase(it); // if (it == Detectors.end()) { // break; // } lastLog.assign("Successfully delete the " + i_to_s(ID) + " zone."); return true; } } lastLog.assign("Where you click is no zones."); return false; }
bool PDCounter::delArea(Mat& frame, int ID) { for (vector<PDDetector>::iterator it = Detectors.begin(); it != Detectors.end(); it++) { if ((*it).getID() == ID) { (*it).boom(); Detectors.erase(it); // if (it == Detectors.end()) { // break; // } lastLog.assign("Successfully delete the " + i_to_s(ID) + " zone."); // areaID--; return true; } } lastLog.assign("There is no zone identified with the ID " + i_to_s(ID)); return false; }
bool PDCounter::addArea(Mat& frame) { if (areaID > MAX_AREA_NUM) { lastLog.assign("Up to the limits. You cannot use zones more zhan " + i_to_s(MAX_AREA_NUM) + ". You can delete some zones to change your selection"); return false; } Rect temp; PDDetector td(frame, areaID++); Rect newArea = td.getArea(); for (vector<PDDetector>::iterator it = Detectors.begin(); it != Detectors.end(); it++) { temp = newArea & (*it).getArea(); if (temp.area() > 0) { lastLog.assign("Overlap error. Please choose choose new zone to detect."); return false; } } Detectors.push_back(td); lastLog.assign("Successfully created new zone to detect."); return true; }
string PDCounter::stop() { int num = (int)Trackers.boom(); return "The main module was stopped, it has detected " + i_to_s(num) + " pedestrians in last run."; }