Exemplo n.º 1
0
main()
{
	int set = 1;
	int a, b, i, sc, sr;


	while (1)
	{
		cin >> c >> r >> o;

		if (c + r + o == 0)
			break;

		for (i = 0; i < c; i++)
			cin >> cops[i].x >> cops[i].y;
		for (i = 0; i < r; i++)
			cin >> robbers[i].x >> robbers[i].y;
		for (i = 0; i < o; i++)
			cin >> other[i].x >> other[i].y;
		if (c >= 3)
			convexHull(cops, c, CH, sc);
		if (r >= 3)
		convexHull(robbers, r, RH, sr);

		cout << "Data set " << set++ << ":" << endl;
		for (i = 0; i < o; i++)
		{
			cout << "     Citizen at (";
			cout << other[i].x << "," << other[i].y << ") is ";
			if (c >= 3)
				a = inside(CH, sc, other[i].x, other[i].y);
			else
				a = 0;
			if (r >= 3)
				b = inside(RH, sr, other[i].x, other[i].y);
			else
				b = 0;

			if (a)
				cout << "safe";
			else {
				if (b)
					cout << "robbed";
				else
					cout << "neither";
			}

			cout << "." << endl;
		}
		cout << endl;
	}


	return 0;
}
Exemplo n.º 2
0
Bleb::Bleb(vector<Point> &bunch, Point2f &centroid, int &BIN)
{
    //bleb size
    size = bunch.size();

    //bleb center
    vector<Point> hull;
    convexHull(bunch, hull);
    Moments mu = moments(hull);
    Point2f blebCtr = Point2f(mu.m10/mu.m00, mu.m01/mu.m00);
    center.x = blebCtr.x;
    center.y = blebCtr.y;

    // bleb bunch in polar coordinates
    double theta = 0;
    for(unsigned int n = 0; n < bunch.size(); n++){
        polarPoint pt = cartesianToPolar1(bunch[n], centroid);
        bunch_polar.push_back(pt);
        theta += pt.theta;
    }
    theta /= bunch.size();
    bin = theta/(3.1415926*2/BIN)+BIN/2;


    // bleb bounding ellipse
    roughArea =  fitEllipse(Mat(bunch));

}
Exemplo n.º 3
0
void Solver605C::run()
{
    int64_t n, p, q;
    cin >> n >> p >> q;
    std::vector<Point> points;
    for (int i = 0; i < n; ++i)
    {
        int64_t a, b;
        cin >> a >> b;
        points.push_back(Point({ a, b }));
        points.push_back(Point({ a, 0 }));
        points.push_back(Point({ 0, b }));
    }

    auto hullPoints = convexHull(points);
    
    Point target({ p, q });
    for (size_t i = 0; i < hullPoints.size() - 1; ++i)
    {
        auto ptCurr = hullPoints[i];
        auto ptNext = hullPoints[i + 1];
        if (det(ptCurr, target) < 0 && det(ptNext, target) >= 0)
        {
            double diff = double(det(ptNext, target) - det(ptCurr, target));
            double t = (0.0 - det(ptCurr, target)) / diff;
            double pp = (1 - t) * ptCurr[0] + t * ptNext[0];
            std::cout << std::setprecision(15) << std::fixed << p / pp;
            return;
        }
    }
}
Exemplo n.º 4
0
Arquivo: h.cpp Projeto: Neverous/team
int main(void)
{
	scanf("%d", &tests);
	for(int t = 0; t < tests; ++ t)
	{
		scanf("%d", &points);
		point.resize(points);
		for(int p = 0; p < points; ++ p)
			scanf("%d %d", &point[p].first, &point[p].second);

		if(points < 3)
		{
			puts("0.00");
			continue;
		}

		convexHull(point, convex);
		res = 1000000000L;
		for(unsigned int c = 0; c < convex.size(); ++ c)
		{
			act = 0;
			for(unsigned int p = 0; p < convex.size(); ++ p)
				act = MAX(act, 1.0 * cross(convex[c], convex[(c + 1) % convex.size()], convex[p]) * 1.0 / dist(convex[c], convex[(c + 1) % convex.size()]));

			res = MIN(res, act);
		}

		printf("%.2Lf\n", res);
	}

	return 0;
}
Exemplo n.º 5
0
 std::vector<int> convexHull(const project_t &project, iter_t beg, iter_t end, size_t size_hint = 0) {
   std::vector<carve::geom2d::P2> proj;
   if (size_hint) proj.reserve(size_hint);
   for (; beg != end; ++beg) {
     proj.push_back(project(*beg));
   }
   return convexHull(proj);
 }
Exemplo n.º 6
0
 std::vector<int> convexHull(const project_t &project, const polygon_container_t &points) {
   std::vector<carve::geom2d::P2> proj;
   proj.reserve(points.size());
   for (typename polygon_container_t::const_iterator i = points.begin(); i != points.end(); ++i) {
     proj.push_back(project(*i));
   }
   return convexHull(proj);
 }
Exemplo n.º 7
0
//qucikHull algorithm based on algorithm based on http://www.ahristov.com/tutorial/geometry-games/convex-hull.html java implimentation
vector<City> quickHull(vector<City> points_in){
	vector<City> convexHull(0);
	if(points_in.size() < 3){			//if our set is 3 point our hull is this set
							//		City A = points_in[0];	//Add the first point to the end so that we connect
							//		points_in.push_back(A);
		return points_in; 
	}
	int minCity = -1;
	int maxCity = -1; 
	int minX = INT_MAX; 
	int maxX = INT_MIN; 
	for (int i = 0; i < points_in.size(); i++){
		if(points_in[i].x() < minX){
			minX = points_in[i].x();
			minCity = i;
		}
	
		if(points_in[i].x() > maxX){
			maxX = points_in[i].x();
			maxCity = i;
		}
	}

	City A = points_in[minCity];
	City B = points_in[maxCity]; 
	convexHull.push_back(A);
	convexHull.push_back(B); 
	points_in.erase(points_in.begin() + minCity);
	points_in.erase(points_in.begin() + maxCity); 
	
	vector<City> left_set;
	vector<City> right_set;

	for (int i = 0; i < points_in.size(); i++) {
		City p = points_in[i]; 	
		if (point_location(A,B,p) == -1){
			left_set.push_back(p); 
		}
		else{ 
			right_set.push_back(p); 
		}
	}
	hull_set(A,B,right_set,convexHull);
	hull_set(B,A,left_set,convexHull);

	points_in.clear();
	for(int i =0; i < right_set.size(); i++){
		//right_set[i].Print("right set"); 
     		points_in.push_back(right_set[i]); 
	}
	      for(int i =0; i < left_set.size(); i++){
		//left_set[i].Print("left set"); 
		points_in.push_back(left_set[i]); 
	}

	return convexHull;
}
Exemplo n.º 8
0
// area of a convex hull of a vector of points
double area(vector <Point> & pts) {
    sort(all(pts));
    pts.erase(unique(all(pts)), pts.end());
    if(sz(pts) <= 2) return 0.0;
    double ar = 0.0;
    vector <Point> hull = convexHull(pts);
    rep(i, sz(hull)) {
        ar += hull[i] ^ hull[(i + 1) % sz(hull)];
    }
    return 0.5 * ar;
}
Exemplo n.º 9
0
PolygonMask::PolygonMask(const std::vector<types::RowCol<double> >& points,
                         const types::RowCol<size_t>& dims,
                         types::RowCol<sys::SSize_T> offset) :
    mMarkMode(MARK_USING_POINTS),
    mDims(dims)
{
    // Determine intersections
    if (points.empty())
    {
        mDims.row = 0;
    }
    else
    {
        // Need to get the convex hull of the input points,
        // because the code currently cannot handle more
        // than two intersections (left and right) per row.
        std::vector<types::RowCol<double> > rawPoints = points;
        std::vector<types::RowCol<double> > convexHullPoints;
        math::ConvexHull<double> convexHull(rawPoints, convexHullPoints);
            
        const Intersections<double>
                intersections(convexHullPoints, mDims, offset);
        mRanges.reset(new types::Range[mDims.row]);

        std::vector<Intersections<double>::Intersection> intersectionsVec;
        for (size_t row = 0; row < mDims.row; ++row)
        {
            // We know we have a convex polygon
            intersections.get(row, intersectionsVec);
            if (intersectionsVec.empty())
            {
                mRanges[row] = types::Range(); // Empty range
            }
            else if (intersectionsVec.size() == 1)
            {
                mRanges[row] = types::Range(intersectionsVec[0].first,
                                            intersectionsVec[0].length());
            }
            else
            {
                // We are using a convex polygon so this should never
                // happen.
                std::ostringstream ostr;
                ostr << "Requires a convex polygon but these points produced "
                     << intersectionsVec.size() << " intersections for row "
                     << row;
                throw except::Exception(Ctxt(ostr.str()));
            }
        }

        checkForAllTrueOrFalseRanges();
    }
}
Exemplo n.º 10
0
// find contours of segmented hand and count fingers
int Kinect::KinectZoom::DetectContour( )
{
	int numFingers = 0;
	cv::Mat drawing = cv::Mat::zeros( mask.size(), CV_8UC3 );
	cv::vector<cv::vector<cv::Point> > contours;
	cv::vector<cv::Vec4i> hierarchy;

	findContours( mask,contours, hierarchy, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE, cv::Point() );

	if ( contours.size()>0 ) {
		cv::vector<std::vector<int> >hull( contours.size() );
		cv::vector<cv::vector<cv::Vec4i> > convDef( contours.size() );
		cv::vector<cv::vector<cv::Point> > hull_points( contours.size() );
		cv::vector<cv::vector<cv::Point> > defect_points( contours.size() );

		for ( size_t i = 0; i < contours.size(); i++ ) {
			if ( contourArea( contours[i] )>500 ) {
				convexHull( contours[i], hull[i], false );
				convexityDefects( contours[i],hull[i], convDef[i] );

				for ( size_t k=0; k<hull[i].size(); k++ ) {
					int ind=hull[i][k];
					hull_points[i].push_back( contours[i][ind] );
				}

				for ( size_t k=0; k<convDef[i].size(); k++ ) {
					if ( convDef[i][k][3]>20*256 ) { // filter defects by depth
						numFingers++;
						int ind_0=convDef[i][k][0];
						int ind_1=convDef[i][k][1];
						int ind_2=convDef[i][k][2];
						defect_points[i].push_back( contours[i][ind_2] );
						cv::circle( drawing,contours[i][ind_0],5,cv::Scalar( 0,255,0 ),-1 );
						cv::circle( drawing,contours[i][ind_1],5,cv::Scalar( 0,255,0 ),-1 );
						cv::circle( drawing,contours[i][ind_2],5,cv::Scalar( 0,0,255 ),-1 );
						cv::line( drawing,contours[i][ind_2],contours[i][ind_0],cv::Scalar( 0,0,255 ),1 );
						cv::line( drawing,contours[i][ind_2],contours[i][ind_1],cv::Scalar( 0,0,255 ),1 );
					}
				}
				// draw results
				drawContours( drawing, contours, i, cv::Scalar( 0,255,0 ), 1, 8, cv::vector<cv::Vec4i>(), 0, cv::Point() );
				drawContours( drawing, hull_points, i, cv::Scalar( 255,0,0 ), 1, 8, cv::vector<cv::Vec4i>(), 0, cv::Point() );
			}
		}
	}
#ifdef QT_DEBUG
	// imshow( "Hull", drawing );
#endif

	return numFingers;
}
Rect FindContourAndGetMaxRect(Mat frame)
{
  //add find contours
  Rect maxRect(0,0,1,1);
  int Max = 0,MaxIndex = 0;

  Mat temp = frame.clone();    
  vector<vector<Point> > contours;
  vector<Vec4i> hierarchy;

  findContours( temp, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);

  /// Draw contours
  vector<vector<Point> > hull( contours.size() );
  for( int i = 0; i < contours.size(); i++ )
    convexHull( Mat(contours[i]), hull[i], false );
  Mat drawing = Mat::zeros( temp.size(), CV_8UC1 );

  // double biggest_area  = contourArea( hull[0],false); 
  int most_important_area = 0;
  int max = 0;
  // cout <<"hull.size()" << hull.size() << endl;

  for( int i = 0; i < hull.size(); i++ )
  {
    // approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
    drawContours( drawing, hull, i, Scalar(255,255,255), CV_FILLED, 8, hierarchy);
    // //find the biggest size
    // double contourarea = contourArea(contours[i],false);
    // if(biggest_area < contourarea){
    //   biggest_area = contourarea;
    //   // cout << "biggest_area" << biggest_area << endl;
    //   max = i;
    // }
    int temp_sum_pixels = SumAllPixelsInRect(frame, boundingRect(hull[i]));
    if(most_important_area < temp_sum_pixels)
    { 
      most_important_area = temp_sum_pixels;
      max = i;
    }
  }
  if(hull.size() != 0){ 
    maxRect  = boundingRect(hull[max]);
    rectangle(drawing, maxRect.tl(), maxRect.br(), Scalar(255, 255, 255), 2);  
    cout << "max rect " << maxRect << endl;
  }
  imshow("convex-hull",drawing);
  return maxRect;
  // return maxRect;
}
Exemplo n.º 12
0
// create a convex hull
dgMeshEffect::dgMeshEffect (dgMemoryAllocator* const allocator, const dgFloat64* const vertexCloud, dgInt32 count, dgInt32 strideInByte, dgFloat64 distTol)
	:dgPolyhedra(allocator)
{
	Init();
	if (count >= 4) {
		dgConvexHull3d convexHull (allocator, vertexCloud, strideInByte, count, distTol);
		if (convexHull.GetCount()) {

			dgInt32 vertexCount = convexHull.GetVertexCount();
			dgStack<dgVector> pointsPool (convexHull.GetVertexCount());
			dgVector* const points = &pointsPool[0];
			for (dgInt32 i = 0; i < vertexCount; i ++) {
				points[i] = convexHull.GetVertex(i);
			}
			dgVector uv(dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));
			dgVector normal (dgFloat32 (0.0f), dgFloat32 (1.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));

			dgInt32 triangleCount = convexHull.GetCount();
			dgStack<dgInt32> faceCountPool (triangleCount);
			dgStack<dgInt32> materialsPool (triangleCount);
			dgStack<dgInt32> vertexIndexListPool (triangleCount * 3);
			dgStack<dgInt32> normalIndexListPool (triangleCount * 3);


			memset (&materialsPool[0], 0, triangleCount * sizeof (dgInt32));
			memset (&normalIndexListPool[0], 0, 3 * triangleCount * sizeof (dgInt32));

			dgInt32 index = 0;
			dgInt32* const faceCount = &faceCountPool[0];
			dgInt32* const vertexIndexList = &vertexIndexListPool[0];
			for (dgConvexHull3d::dgListNode* faceNode = convexHull.GetFirst(); faceNode; faceNode = faceNode->GetNext()) {
				dgConvexHull3DFace& face = faceNode->GetInfo();
				faceCount[index] = 3;
				vertexIndexList[index * 3 + 0] = face.m_index[0]; 
				vertexIndexList[index * 3 + 1] = face.m_index[1]; 
				vertexIndexList[index * 3 + 2] = face.m_index[2]; 
				index ++;
			}

			BuildFromVertexListIndexList(triangleCount, faceCount, &materialsPool[0], 
				&points[0].m_x, sizeof (dgVector), vertexIndexList,
				&normal.m_x, sizeof (dgVector), &normalIndexListPool[0],
				&uv.m_x, sizeof (dgVector), &normalIndexListPool[0],
				&uv.m_x, sizeof (dgVector), &normalIndexListPool[0]);

            RepairTJoints ();
		}
	}
}
Exemplo n.º 13
0
int main() {
  Point p(1, 0);
  Line l(1, 0, 2);

  Polygon pol;
  pol.add_point(Point(-1, -1));
  pol.add_point(Point(1, -1));
  pol.add_point(Point(0, 0));
  pol.add_point(Point(1, 1));
  pol.add_point(Point(-1, 1));

  Polygon c = convexHull(pol);
  for (size_t i = 0; i < c.size(); ++i)
    printf("%f %f\n", c[i].x, c[i].y);
}
Exemplo n.º 14
0
void Jive::findKeyPoints(vector<cv::Point> &contour, vector<int> &hulls, vector<int> &defects, int depth)
{  
   vector<Vec4i> convDef;

   hulls.clear();
   defects.clear();   
   convexHull(Mat(contour), hulls, false ); 
   convexityDefects(contour, hulls, convDef);
   for (int k=1; k<convDef.size(); k++) {  // first defect is false  
      if (convDef[k][3] > depth*256) {
         int ind = convDef[k][2];
         defects.push_back(ind);
      }
   }
}
Exemplo n.º 15
0
/* if returning true, check contains true if cubic's hull collapsed, making the cubic linear
   if returning false, check contains true if the the cubic pair have only the end point in common
*/
bool SkDCubic::hullIntersects(const SkDPoint* pts, int ptCount, bool* isLinear) const {
    bool linear = true;
    char hullOrder[4];
    int hullCount = convexHull(hullOrder);
    int end1 = hullOrder[0];
    int hullIndex = 0;
    const SkDPoint* endPt[2];
    endPt[0] = &fPts[end1];
    do {
        hullIndex = (hullIndex + 1) % hullCount;
        int end2 = hullOrder[hullIndex];
        endPt[1] = &fPts[end2];
        double origX = endPt[0]->fX;
        double origY = endPt[0]->fY;
        double adj = endPt[1]->fX - origX;
        double opp = endPt[1]->fY - origY;
        int oddManMask = other_two(end1, end2);
        int oddMan = end1 ^ oddManMask;
        double sign = (fPts[oddMan].fY - origY) * adj - (fPts[oddMan].fX - origX) * opp;
        int oddMan2 = end2 ^ oddManMask;
        double sign2 = (fPts[oddMan2].fY - origY) * adj - (fPts[oddMan2].fX - origX) * opp;
        if (sign * sign2 < 0) {
            continue;
        }
        if (approximately_zero(sign)) {
            sign = sign2;
            if (approximately_zero(sign)) {
                continue;
            }
        }
        linear = false;
        bool foundOutlier = false;
        for (int n = 0; n < ptCount; ++n) {
            double test = (pts[n].fY - origY) * adj - (pts[n].fX - origX) * opp;
            if (test * sign > 0 && !precisely_zero(test)) {
                foundOutlier = true;
                break;
            }
        }
        if (!foundOutlier) {
            return false;
        }
        endPt[0] = endPt[1];
        end1 = end2;
    } while (hullIndex);
    *isLinear = linear;
    return true;
}
Exemplo n.º 16
0
void convexHullOfMask(CMat &mask1u, PointSeti &hullPnts)
{
	const int H = mask1u.rows - 1, W = mask1u.cols - 1;
	PointSeti pntSet;
	pntSet.reserve(H*W);
	for (int r = 1; r < H; r++){
		const byte* m = mask1u.ptr<byte>(r);
		for (int c = 1; c < W; c++){
			if (m[c] < 200)
				continue;
			if (m[c-1] < 200 || m[c + 1] < 200 || mask1u.at<byte>(r-1, c) < 200 || mask1u.at<byte>(r+1, c) < 200)
				pntSet.push_back(Point(c, r));
		}
	}
	convexHull(pntSet, hullPnts);
}
Exemplo n.º 17
0
int main(int argc, const char * argv[]) {
    point pointSet[10000];
    int count = 0;
    
    while (1) {
        scanf("%d %d", &pointSet[count].x, &pointSet[count].y);
        if (!pointSet[count].x && !pointSet[count].y) {
            break;
        }
        count++;
    }
    
    convexHull(pointSet, count);
    
    return 0;
}
	void findGoodCorners2(const Mat &grayFrame, const SoccerPitchData &data, Mat &currToKeyTrans, Mat &keyToTopTrans) {
		Mat topToCurrTrans;
		invert(keyToTopTrans * currToKeyTrans, topToCurrTrans);
		vector<Point2f> imagePitchOuterContour;
		perspectiveTransform(data.pitchOuterPoints, imagePitchOuterContour, topToCurrTrans);

		vector<Point2f> hull;
		convexHull(imagePitchOuterContour, hull);

		Mat mask = Mat::zeros(frameSize, CV_8UC1);
		fillConvexPoly(mask, vector<Point>(hull.begin(), hull.end()), Scalar(1, 0, 0));

		dilate(mask, mask, getStructuringElement(MORPH_ELLIPSE, Size(3, 3)));

		Mat bin;
		adaptiveThreshold(grayFrame, bin, 255, ADAPTIVE_THRESH_MEAN_C , THRESH_BINARY, 5, -10);
		
		vector<Point2f> candidateCorners;
		goodFeaturesToTrack(bin, candidateCorners, 100, 0.01, 24, mask);

		cornerSubPix(bin, candidateCorners, Size(5, 5), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS & CV_TERMCRIT_ITER, 40, 0.001));

		vector<Point2f> goodPoints;
		for (Point2f corner : candidateCorners) {
			if (goodCornerCheck(corner, bin) && !closeToBoundary(corner))
				goodPoints.push_back(corner);
		}

		if (goodPoints.size() > 0) {
			vector<Point2f> reprojGoodPoints;
			perspectiveTransform(goodPoints, reprojGoodPoints, keyToTopTrans * currToKeyTrans);
			// try to add these new corners into the relocatedCorners
			for (int i = 0; i < reprojGoodPoints.size(); i++) {
				// if does not exists already and coincide with reproj of 28 points
				bool exists = hasSimilarPoint(relocatedPitchPoints, reprojGoodPoints[i], 10) ;
				int minId = findClosestPoint(data.pitchPoints, reprojGoodPoints[i]);
				double minDist = norm(reprojGoodPoints[i] - data.pitchPoints[minId]);
				if ((!exists ) && (minDist < 16) && (minDist < reprojErr[minId])) {
					relocatedCorners.push_back(goodPoints[i]);
					relocatedPitchPoints.push_back(data.pitchPoints[minId]);
					reprojErr[minId] = minDist;
				}
			}
		}

		cout<<relocatedCorners.size()<<" points relocated"<<endl;
	}
Exemplo n.º 19
0
cv::RotatedRect cv::minAreaRect( InputArray _points )
{
    Mat hull;
    Point2f out[3];
    RotatedRect box;

    convexHull(_points, hull, true, true);

    if( hull.depth() != CV_32F )
    {
        Mat temp;
        hull.convertTo(temp, CV_32F);
        hull = temp;
    }

    int n = hull.checkVector(2);
    const Point2f* hpoints = hull.ptr<Point2f>();

    if( n > 2 )
    {
        rotatingCalipers( hpoints, n, CALIPERS_MINAREARECT, (float*)out );
        box.center.x = out[0].x + (out[1].x + out[2].x)*0.5f;
        box.center.y = out[0].y + (out[1].y + out[2].y)*0.5f;
        box.size.width = (float)std::sqrt((double)out[1].x*out[1].x + (double)out[1].y*out[1].y);
        box.size.height = (float)std::sqrt((double)out[2].x*out[2].x + (double)out[2].y*out[2].y);
        box.angle = (float)atan2( (double)out[1].y, (double)out[1].x );
    }
    else if( n == 2 )
    {
        box.center.x = (hpoints[0].x + hpoints[1].x)*0.5f;
        box.center.y = (hpoints[0].y + hpoints[1].y)*0.5f;
        double dx = hpoints[1].x - hpoints[0].x;
        double dy = hpoints[1].y - hpoints[0].y;
        box.size.width = (float)std::sqrt(dx*dx + dy*dy);
        box.size.height = 0;
        box.angle = (float)atan2( dy, dx );
    }
    else
    {
        if( n == 1 )
            box.center = hpoints[0];
    }

    box.angle = (float)(box.angle*180/CV_PI);
    return box;
}
pcl::PointCloud<pcl::PointXYZ>::Ptr DoorHandleDetectionNode::createPlanePC(const pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud, const pcl::PointIndices::Ptr inliers, pcl::ModelCoefficients::Ptr coefficients)
{
  pcl::PointCloud<pcl::PointXYZ>::Ptr plane(new pcl::PointCloud<pcl::PointXYZ>);
  pcl::PointCloud<pcl::PointXYZ>::Ptr convexHull(new pcl::PointCloud<pcl::PointXYZ>);

  //Object for retrieving the convex hull.
  pcl::ConvexHull<pcl::PointXYZ> hull;
  hull.setInputCloud(plane);
  hull.reconstruct(*convexHull);

  //Create the point cloud to display the plane segmented
  pcl::ProjectInliers<pcl::PointXYZ> proj;
  proj.setModelType (pcl::SACMODEL_PLANE);
  proj.setInputCloud (cloud);
  proj.setModelCoefficients (coefficients);
  proj.filter (*plane);

  return plane;
}
Exemplo n.º 21
0
void Feature::calcGeometryFeature(const Region& region)
{
    circularity = 0;
    squareness = 0;
    aspectRatio = 0;
    roughness = 0;
    double mysq = 0;   
    double len = 0;
    const vector<ContourInfo*>& contours = region.contours;
    for (vector<ContourInfo*>::const_iterator it = contours.begin(); it != contours.end(); it++) {
        const vector<Point>& contour = (*it)->contour;
        double area = (*it)->area;
        
        double perimeter = arcLength(contour, true);
        RotatedRect minRect = minAreaRect(Mat(contour));
	Rect myrect = boundingRect(Mat(contour));
        vector<Point> hull;
        convexHull(contour, hull);
        double perimeterHull = arcLength(hull, true);
        double width = minRect.size.width, height = minRect.size.height;
        
        circularity += area * (4 * M_PI * area / (perimeter * perimeter));
        squareness  += area * (area / (width * height));
	mysq += area * (area / (myrect.width * myrect.height));
        len = perimeter / (width * height);
	aspectRatio += area * (1.0 * min(width, height) / max(width, height));
        roughness   += area * (perimeterHull / perimeter);
    }
    
    circularity /= mArea;
    squareness  /= mArea;
    mysq /= mArea;
    aspectRatio /= mArea;
    roughness   /= mArea;
	#ifdef DEBUG_OUTPUT
    cout << "circularity ==== " << circularity << endl;
    cout << "squareness ==== " << squareness << endl;
    cout << "mysq ==== " << mysq << endl;
    cout << "len === " << len << endl;
    cout << "aspectRatio ==== " << aspectRatio << endl;
    cout << "roughness ==== " << roughness << endl;
	#endif
}
Exemplo n.º 22
0
vector<vector<int>> Detect::getConvexHulls(vector<vector<Point>>& polyCurves)
{
    vector<vector<int>> hullIndices;

    for (int i = 0; i < polyCurves.size(); ++i) {
        vector<int> hullIndex;
        if (polyCurves[i].size() > 0) {
            convexHull(polyCurves[i], hullIndex);
            if(hullIndex.size() > 2){
                hullIndices.push_back(hullIndex);  
            }
            else {
                polyCurves.erase(polyCurves.begin() + i);
                --i;
            }
        }
    }

    return hullIndices;
}
Exemplo n.º 23
0
vector<Point> convexHullExtraction(Mat src) {
    Mat src_gray;
    cvtColor(src, src_gray, CV_BGR2GRAY);
    blur(src_gray, src_gray, Size(3, 3));

    // Convex Hull implementation
    Mat src_copy = src.clone();
    Mat dst;
    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;

    // Find contours
    threshold(src_gray, dst, 200, 255, THRESH_BINARY);
    findContours(dst, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));

    // Find the convex hull object for each contour
    vector<vector<Point> >hull(1);
    convexHull(Mat(contours[1]), hull[0], false);


    // Draw contours + hull results
    if (convexShow) {
        RNG rng;
        Mat drawing = Mat::zeros(dst.size(), CV_8UC3);
        for (int i = 0; i< contours.size(); i++)
        {
            if (i == 1)
                drawContours(drawing, contours, i, Scalar(255, 255, 0), 1, 8, vector<Vec4i>(), 0, Point());
            if (i == 0)
                drawContours(drawing, hull, i, Scalar(255, 255, 255), 1, 8, vector<Vec4i>(), 0, Point());
        }
        // Show in a window
        namedWindow("Hull demo", CV_WINDOW_AUTOSIZE);
        imshow("Hull demo", drawing);
        if (save)
            imwrite("Hull.jpg", drawing);
        waitKey(0);
    }

    return hull[0];
}
Rect MotionDetection::FindContourAndGetMaxRect(Mat frame)
{
  //add find contours
  Rect maxRect(0,0,1,1);
  int Max = 0,MaxIndex = 0;

  Mat temp = frame.clone();    
  vector<vector<Point> > contours;
  vector<Vec4i> hierarchy;

  findContours( temp, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);

  /// Draw contours
  vector<vector<Point> > hull( contours.size() );
  for( int i = 0; i < contours.size(); i++ )
    convexHull( Mat(contours[i]), hull[i], false );
  Mat drawing = Mat::zeros( temp.size(), temp.type() );
  // double smallest_area  = contourArea( contours[0],false); 
  for( int i = 0; i< contours.size(); i++ )
  {
    // approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
    //drawContours( drawing, contours, i, Scalar(255,255,255), CV_FILLED, 8, hierarchy);
    drawContours( drawing, hull, i, Scalar(255,255,255), CV_FILLED, 8, hierarchy);
    Rect rect  = boundingRect(hull[i]);
    rectangle(drawing, rect.tl(), rect.br(), Scalar(255, 255, 255), 1);
    int tempInt = SumAllPixelsInRect(frame,rect);
    if(tempInt > Max){
      Max = tempInt;
      MaxIndex = i;
    }
  
  }
  //imshow(WINDOW_CONTOUR, drawing); 
  if(contours.size() != 0){   
    maxRect = boundingRect(hull[MaxIndex]);
  }
  return maxRect;
  // return maxRect;
}
Exemplo n.º 25
0
	// this should be replaced by c++ 2.0 api style code once available
	vector<cv::Vec4i> convexityDefects(const vector<cv::Point>& contour) {
		vector<int> hullIndices;
		convexHull(Mat(contour), hullIndices, false, false);
		vector<cv::Vec4i> convexityDefects;
		if(hullIndices.size() > 0 && contour.size() > 0) {		
			CvMat contourMat = cvMat(1, contour.size(), CV_32SC2, (void*) &contour[0]);
			CvMat hullMat = cvMat(1, hullIndices.size(), CV_32SC1, (void*) &hullIndices[0]);
			CvMemStorage* storage = cvCreateMemStorage(0);
			CvSeq* defects = cvConvexityDefects(&contourMat, &hullMat, storage);
			for(int i = 0; i < defects->total; i++){
				CvConvexityDefect* cur = (CvConvexityDefect*) cvGetSeqElem(defects, i);
				cv::Vec4i defect;
				defect[0] = cur->depth_point->x;
				defect[1] = cur->depth_point->y;
				defect[2] = (cur->start->x + cur->end->x) / 2;
				defect[3] = (cur->start->y + cur->end->y) / 2;
				convexityDefects.push_back(defect);
			}
			cvReleaseMemStorage(&storage);
		}
		return convexityDefects;
	}
Exemplo n.º 26
0
Mat fillConvexHulls(Mat bwImage) {
    vector<vector<Point> > contours, onlyContours(1);
    vector<Vec4i> hierarchy;
    
    findContours( bwImage.clone(), contours, hierarchy,
                 CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE );
    
    // Find the convex hull object for each contour
    vector<vector<Point> >hull( contours.size() );
    for( int i = 0; i < contours.size(); i++ )
    {
        convexHull( Mat(contours[i]), hull[i], false );
    }
    
    Mat drawing = Mat::zeros( bwImage.size(), CV_8UC1 );
    for( int i = 0; i< contours.size(); i++ )
    {
        drawContours(drawing, contours, i, Scalar(255), CV_FILLED);
        drawContours( drawing, hull, i, Scalar(255), CV_FILLED);
    }

    return drawing;
}
Exemplo n.º 27
0
std::vector<cv::Mat> ObjectSelector::getObjects(cv::Mat * src, cv::Point2f p)
{
    std::vector<std::vector<cv::Point> > contours;
    std::vector<cv::Vec4i> hierarchy;
    cv::Mat canny_output;
    cv::Mat src_gray;
    cvtColor( *src, src_gray, CV_BGR2GRAY );
    blur( src_gray, src_gray, cv::Size(3,3) );


    /// Detect edges using canny
    Canny( src_gray, canny_output, thresh, thresh*2, 3 );
    /// Find contours
    findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0) );

    std::priority_queue<TestedContour> results;

    for( int i = 0; i< contours.size(); i++ )
        results.push(TestedContour(i,-pointPolygonTest(contours[i],p,true)));

    std::vector<cv::Mat> retVal;

    for(int i = 0; i < maxRet && !results.empty(); i++)
    {
        TestedContour c = results.top(); results.pop();
        cv::Rect br = boundingRect( contours[c.Id()] );
        cv::Mat mask = cv::Mat::zeros(src->size(), CV_8UC1);
        std::vector<std::vector<cv::Point> > hull;
        hull.push_back(std::vector<cv::Point>());
        convexHull(contours[c.Id()],hull[0],1,true);
        drawContours( mask, hull, 0, cv::Scalar(255), CV_FILLED );
        cv::Mat tmp = cv::Mat::zeros(br.size(), CV_8UC3);
        src->copyTo(tmp, mask);
        retVal.push_back(cv::Mat(tmp,br));
    }
    return retVal;
}
void dgCollisionDeformableSolidMesh::DebugCollision (const dgMatrix& matrix, dgCollision::OnDebugCollisionMeshCallback callback, void* const userData) const
{
	dgCollisionDeformableMesh::DebugCollision (matrix, callback, userData);
	if (m_onDebugDisplay) {
		dgStack<dgBigVector> points (m_particles.m_count);
		for (dgInt32 k = 0; k < m_clustersCount; k ++) {

			dgInt32 vertexCount = 0;
			for (dgInt32 i = 0; (i < m_particles.m_count); i ++) {
				const dgInt32 start = m_clusterPositStart[i];
				const dgInt32 count = m_clusterPositStart[i + 1] - start;
				for (dgInt32 j = 0; j < count; j ++) {
					dgInt32 index = m_clusterPosit[start + j];
					if (index == k) {
						points[vertexCount] = m_posit[i] + m_basePosit;
						vertexCount ++;
						break;
					}
				}
			}

			dgConvexHull3d convexHull (GetAllocator(), &points[0].m_x, sizeof (dgBigVector), vertexCount, dgFloat32 (0.0f));
			for (dgConvexHull3d::dgListNode* faceNode = convexHull.GetFirst(); faceNode; faceNode = faceNode->GetNext()) {
				const dgConvexHull3DFace& face = faceNode->GetInfo();

				dgTriplex points[3];
				for (dgInt32 l = 0; l < 3; l ++) {
					dgVector p (convexHull.GetVertex(face.m_index[l]));
					points[l].m_x = p.m_x;
					points[l].m_y = p.m_y;
					points[l].m_z = p.m_z;
				}
				m_onDebugDisplay (userData, 3, &points[0].m_x, k);
			}
		}
	}
}
Exemplo n.º 29
0
ConvexHull Hexagon::getConvexHull()
{
    ConvexHull convexHull(6);

    if (style == FlatTopped)
    {
        convexHull[0] = (*vertexSource)[vertexOffset + 1].position;
        convexHull[1] = (*vertexSource)[vertexOffset + 3].position;
        convexHull[2] = (*vertexSource)[vertexOffset + 5].position;
        convexHull[3] = (*vertexSource)[vertexOffset + 6].position;
        convexHull[4] = (*vertexSource)[vertexOffset + 4].position;
        convexHull[5] = (*vertexSource)[vertexOffset + 2].position;
    }
    else
    {
        convexHull[0] = (*vertexSource)[vertexOffset + 2].position;
        convexHull[1] = (*vertexSource)[vertexOffset + 1].position;
        convexHull[2] = (*vertexSource)[vertexOffset + 3].position;
        convexHull[3] = (*vertexSource)[vertexOffset + 5].position;
        convexHull[4] = (*vertexSource)[vertexOffset + 6].position;
        convexHull[5] = (*vertexSource)[vertexOffset + 4].position;
    }
    return convexHull;
}
Exemplo n.º 30
0
void Render::run(void) {
    ExCom ex;
    
    do {
        ex = cmdq->consome();
        if(buffer == NULL)
        {
             msleep(100);
             continue;
        }
        switch(ex.cmd)
        {
            case NENHUM:
                msleep(100);
                continue;
            case INCZOOM:
                incZoom();
                break;
            case DECZOOM:
                decZoom();
                break;
            case INCX:
                incX();
                break;
            case DECX:
                decX();
                break;
            case INCY:
                incY();
                break;
            case DECY:
                decY();
                break;
            case PONTOS:
                mostraPonto = !mostraPonto;
                renderizaFront();
                break;
            case ARESTAS:
                mostraAresta = !mostraAresta;
                renderizaFront();
                break;
            case FACES:
                mostraFace = !mostraFace;
                renderizaFront();
                break;
            case SELECT:
                if(sel == NULL)
                    sel = new QPoint();
                sel->setX(ex.x);
                sel->setY(ex.y);
                click();
                break;
            case CONVHULL:
                convexHull();
                break;
        case EXTERN:
                externa();
                break;
        }
        atualizaScreen();
    } while (true);

}