//-------------------------- Main function -------------------------- void Tracker::Track(const Mat &next_frame) { CHECK_NOTNULL(detector_); cv::Mat frame = next_frame.clone(); frame = Preprocess(frame); if (bgs_ != nullptr) { // Segment foreground. bgs_->NextFrame(frame); frame = bgs_->GetForeground(); } if (filter_ != nullptr) { // Predict new position and feed it to the detector. filter_->Predict(); Mat predicted_x = filter_->predicted_x(); detector_->set_state(StateMatToRect(predicted_x)); } // Detect new state. detector_->NextFrame(frame); detector_->Detect(); // Get measurement from core tracker. state_ = detector_->state(); if (filter_ != nullptr) { // Feed measurement to Kalman filter and retrieve new state. filter_->Update(StateRectToMat(state_)); state_ = StateMatToRect(filter_->x()); } Postprocess(); }
int main(int argc, char **argv) { ParametersType *Parameters; MatrixDataType *MatrixData; FemStructsType *FemStructs; FemFunctionsType *FemFunctions; FemOtherFunctionsType *FemOtherFunctions; struct timespec Start, End; double Preprocess_Time, Process_Time, Postprocess_Time; /* ******************************************************* Preprocess ****************************************************** */ clock_gettime(CLOCK_MONOTONIC, &Start); Preprocess(argc, argv, &Parameters, &MatrixData, &FemStructs, &FemFunctions, &FemOtherFunctions); clock_gettime(CLOCK_MONOTONIC, &End); Preprocess_Time = End.tv_sec - Start.tv_sec + 1e-9*(End.tv_nsec - Start.tv_nsec); /* ************************************************************************************************************************* */ /* ******************************************************** Process ******************************************************** */ clock_gettime(CLOCK_MONOTONIC, &Start); Process(Parameters, MatrixData, FemStructs, FemFunctions, FemOtherFunctions); clock_gettime(CLOCK_MONOTONIC, &End); Process_Time = End.tv_sec - Start.tv_sec + 1e-9*(End.tv_nsec - Start.tv_nsec); /* ************************************************************************************************************************* */ /* ******************************************************* Postprocess ***************************************************** */ clock_gettime(CLOCK_MONOTONIC, &Start); Postprocess(Parameters, MatrixData, FemStructs, FemFunctions, FemOtherFunctions); clock_gettime(CLOCK_MONOTONIC, &End); Postprocess_Time = End.tv_sec - Start.tv_sec + 1e-9*(End.tv_nsec - Start.tv_nsec); /* ************************************************************************************************************************* */ /* ******************************************************* Total Time ****************************************************** */ calculateTime(Preprocess_Time, Process_Time, Postprocess_Time, Parameters); /* ************************************************************************************************************************* */ free(Parameters); return 0; }
int ConvexClipper<Real>::Clip (const Plane3<Real>& plane) { // Sompute signed distances from vertices to plane. int numPositive = 0, numNegative = 0; const int numVertices = (int)mVertices.size(); for (int v = 0; v < numVertices; ++v) { Vertex& vertex = mVertices[v]; if (vertex.Visible) { vertex.Distance = plane.DistanceTo(vertex.Point); if (vertex.Distance >= mEpsilon) { ++numPositive; } else if (vertex.Distance <= -mEpsilon) { ++numNegative; vertex.Visible = false; } else { // The point is on the plane (within floating point // tolerance). vertex.Distance = (Real)0; } } } if (numPositive == 0) { // Mesh is in negative half-space, fully clipped. return -1; } if (numNegative == 0) { // Mesh is in positive half-space, fully visible. return +1; } // Clip the visible edges. const int numEdges = (int)mEdges.size(); for (int e = 0; e < numEdges; ++e) { Edge& edge = mEdges[e]; if (edge.Visible) { int v0 = edge.Vertex[0]; int v1 = edge.Vertex[1]; int f0 = edge.Face[0]; int f1 = edge.Face[1]; Face& face0 = mFaces[f0]; Face& face1 = mFaces[f1]; Real d0 = mVertices[v0].Distance; Real d1 = mVertices[v1].Distance; if (d0 <= (Real)0 && d1 <= (Real)0) { // The edge is culled. If the edge is exactly on the clip // plane, it is possible that a visible triangle shares it. // The edge will be re-added during the face loop. face0.Edges.erase(e); if (face0.Edges.empty()) { face0.Visible = false; } face1.Edges.erase(e); if (face1.Edges.empty()) { face1.Visible = false; } edge.Visible = false; continue; } if (d0 >= (Real)0 && d1 >= (Real)0) { // Face retains the edge. continue; } // The edge is split by the plane. Compute the point of // intersection. If the old edge is <V0,V1> and I is the // intersection point, the new edge is <V0,I> when d0 > 0 or // <I,V1> when d1 > 0. int vNew = (int)mVertices.size(); mVertices.push_back(Vertex()); Vertex& vertexNew = mVertices[vNew]; Vector3<Real>& point0 = mVertices[v0].Point; Vector3<Real>& point1 = mVertices[v1].Point; vertexNew.Point = point0 + (d0/(d0 - d1))*(point1 - point0); if (d0 > (Real)0) { edge.Vertex[1] = vNew; } else { edge.Vertex[0] = vNew; } } } // The mesh straddles the plane. A new convex polygonal face will be // generated. Add it now and insert edges when they are visited. int fNew = (int)mFaces.size(); mFaces.push_back(Face()); Face& faceNew = mFaces[fNew]; faceNew.Plane = plane; // Process the faces. for (int f = 0; f < fNew; ++f) { Face& face = mFaces[f]; if (face.Visible) { // Determine if the face is on the negative side, the positive // side, or split by the clipping plane. The Occurs members // are set to zero to help find the end points of the polyline // that results from clipping a face. assertion(face.Edges.size() >= 2, "Unexpected condition.\n"); std::set<int>::iterator iter = face.Edges.begin(); std::set<int>::iterator end = face.Edges.end(); while (iter != end) { int e = *iter++; Edge& edge = mEdges[e]; assertion(edge.Visible, "Unexpected condition.\n"); mVertices[edge.Vertex[0]].Occurs = 0; mVertices[edge.Vertex[1]].Occurs = 0; } int vStart, vFinal; if (GetOpenPolyline(face, vStart, vFinal)) { // Polyline is open, close it up. int eNew = (int)mEdges.size(); mEdges.push_back(Edge()); Edge& edgeNew = mEdges[eNew]; edgeNew.Vertex[0] = vStart; edgeNew.Vertex[1] = vFinal; edgeNew.Face[0] = f; edgeNew.Face[1] = fNew; // Add new edge to polygons. face.Edges.insert(eNew); faceNew.Edges.insert(eNew); } } } // Process 'faceNew' to make sure it is a simple polygon (theoretically // convex, but numerically may be slightly not convex). Floating-point // round-off errors can cause the new face from the last loop to be // needle-like with a collapse of two edges into a single edge. This // block guarantees the invariant "face always a simple polygon". Postprocess(fNew, faceNew); if (faceNew.Edges.size() < 3) { // Face is completely degenerate, remove it from mesh. mFaces.pop_back(); } return 0; }