当前位置: 首页>>代码示例>>C++>>正文


C++ RotatedRect类代码示例

本文整理汇总了C++中RotatedRect的典型用法代码示例。如果您正苦于以下问题:C++ RotatedRect类的具体用法?C++ RotatedRect怎么用?C++ RotatedRect使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了RotatedRect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: A_encloses_B

bool Num_Extract::A_encloses_B(RotatedRect A, RotatedRect B){
	Point2f ptsA[4];
	Point2f ptsB[4];
	A.points(ptsA);
	B.points(ptsB);
	bool encloses = true;
	Point2f p1,p2,p3,p4;
	double m = 0;
	double indicator = 0;
	double test_val = 0;
	for(int i = 0 ; i < 4 ; i++){
		p1 = ptsA[i];
		p2 = ptsA[(i+1)%4];
		p3 = ptsA[(i+2)%4];
		m = (p2.y-p1.y)/(p2.x-p1.x);
		indicator = (p3.y-p1.y)-m*(p3.x-p1.x);
		for(int j = 0 ; j<4 ; j++){
			p4 = ptsB[j];
			test_val = (p4.y-p1.y)-m*(p4.x-p1.x);
			if(test_val*indicator<0){
				encloses = false;
				break;
			}
		}
		if(!encloses) break;
	}
	return encloses;
}
开发者ID:Mohit-Chachada,项目名称:no_detect,代码行数:28,代码来源:num_extract.cpp

示例2: checkRotatedRectangle

void checkRotatedRectangle()
{
	RNG rng(getTickCount());
	Mat filledRect = Mat::zeros(sz, CV_8UC1);

	Point center(rng.uniform(sz.width/4, sz.width*3/4),
				 rng.uniform(sz.height/4, sz.height*3/4));
	Size rect_size(rng.uniform(sz.width/8, sz.width/6),
				   rng.uniform(sz.height/8, sz.height/6));
	float angle = rng.uniform(0, 360);

	Point2f vertices[4];

	RotatedRect rRect = RotatedRect(center, rect_size, angle);

	rRect.points(vertices);
	for (int i = 0; i < 4; i++)
	{
		line(filledRect, vertices[i], vertices[(i + 1) % 4], Scalar(255), 3);
	}

	vector<Vec4i> lines;
	Ptr<LineSegmentDetector> ls = createLineSegmentDetectorPtr(LSD_REFINE_ADV);
	ls->detect(filledRect, lines);

    Mat drawnLines = Mat::zeros(filledRect.size(), CV_8UC1);
    ls->drawSegments(drawnLines, lines);
    imshow("checkRotatedRectangle", drawnLines);

	std::cout << "Check Rectangle- Number of lines: " << lines.size() << " - >= 4 Wanted." << std::endl;
}
开发者ID:23pointsNorth,项目名称:lsd_opencv,代码行数:31,代码来源:accuracy_test.cpp

示例3: Point2d

void Brushstroke::draw(Mat& alphaMap, Mat& mask,
                       double spacing, double jitter)
{
    Point2d normal = Point2d(cos(angle), sin(angle));

    Point2d point1 = normal * length1;
    Point2d point2 = normal * -length2;

    point1 += anchor;
    point2 += anchor;

    Point2d texCenter;
    RotatedRect maskRect;
    double texAngle;
    Size_<double> maskSize = mask.size();
    double ratio = (width + 2.0) / maskSize.width;

    Mat scaledMask;
    resize(mask, scaledMask, Size(), ratio, ratio, INTER_CUBIC);
    maskSize = scaledMask.size();

    RNG rng(0xFFFFFFFF);

    for(double dist = -length2; dist < length1; dist += spacing) {
        texCenter = anchor + normal * dist;
        texAngle = angle + jitter * rng.uniform(-1.0, 1.0);

        maskRect = RotatedRect(texCenter, maskSize, texAngle);
        Rect2d boundingRect = maskRect.boundingRect();

        renderTexture(alphaMap, scaledMask, maskRect);
    }
}
开发者ID:csbuja,项目名称:vango,代码行数:33,代码来源:Brushstroke.cpp

示例4: processImage

// Define trackbar callback functon. This function find contours,
// draw it and approximate it by ellipses.
void processImage(int /*h*/, void*)
{
    vector<vector<Point> > contours;
    Mat bimage = image >= sliderPos;
    
    findContours(bimage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);

    Mat cimage = Mat::zeros(bimage.size(), CV_8UC3);

    for(size_t i = 0; i < contours.size(); i++)
    {
        size_t count = contours[i].size();
        if( count < 6 )
            continue;
        
        Mat pointsf;
        Mat(contours[i]).convertTo(pointsf, CV_32F);
        RotatedRect box = fitEllipse(pointsf);
        
        if( MAX(box.size.width, box.size.height) > MIN(box.size.width, box.size.height)*30 )
            continue;
        drawContours(cimage, contours, (int)i, Scalar::all(255), 1, 8);

        ellipse(cimage, box, Scalar(0,0,255), 1, CV_AA);
        ellipse(cimage, box.center, box.size*0.5f, box.angle, 0, 360, Scalar(0,255,255), 1, CV_AA);
        Point2f vtx[4];
        box.points(vtx);
        for( int j = 0; j < 4; j++ )
            line(cimage, vtx[j], vtx[(j+1)%4], Scalar(0,255,0), 1, CV_AA);
    }

    imshow("result", cimage);
}
开发者ID:ljw3351639,项目名称:college-work,代码行数:35,代码来源:fitellipse.cpp

示例5: get_skew_angle

double get_skew_angle(Mat img)
{
  // Binarize
  threshold(img, img, 225, 255, THRESH_BINARY);
 
  // Invert colors
  bitwise_not(img, img);
  Mat element = getStructuringElement(MORPH_RECT, Size(5, 3));
  erode(img, img, element);

  vector<Point> points;
  Mat_<uchar>::iterator it = img.begin<uchar>();
  Mat_<uchar>::iterator end = img.end<uchar>();

  for (; it != end; ++it)
    if (*it)
      points.push_back(it.pos());

  RotatedRect box = minAreaRect(Mat(points));
  double angle = box.angle;

  if (angle < -45.)
    angle += 90.;

  Point2f vertices[4];
  box.points(vertices);

  for(int i = 0; i < 4; ++i)
    line(img, vertices[i], vertices[(i + 1) % 4], Scalar(255, 0, 0), 1, CV_AA);
 
return angle; 
}
开发者ID:Ghatage,项目名称:fractal,代码行数:32,代码来源:preprocessing.cpp

示例6: camshift

void camshift(	Mat &frame,
		Mat &hue_roi,
		Mat &mask_roi,
		Mat &backproj,
		Mat &thresh_img,
		Point2i &resol,
		Point2i &shift,
		Rect &searchwin,
		struct intrinsics *intrins,
		struct pose *body,
		ofstream& file	)
{

	Mat hsv, hue, mask;
	hue.create( resol.y, resol.x, CV_8UC1);
	mask.create(resol.y, resol.x, CV_8UC3);
	int ch[] = {0,0};

	float theta;
	RotatedRect orient;
	Point2f vertices[4];

	bool inframe = false;

	cvtColor( frame, hsv, COLOR_BGR2HSV );

	//Ignore pixels in HSV space with too high/low saturation and a high value:
	hv_threshold( hsv, mask );

	//Extract single channel Hue frames from HSV frames
	//Usage of ch[] means copying from channel 0 of source to channel 0 of destination
	mixChannels( &hsv, 1, &hue, 1, ch, 1 );

	//Compute backprojected frames:
	backprojection( binsize, hue_roi, hue, backproj, mask_roi, thresh_img );

	double res = 1;

	moment(thresh_img, res, searchwin, theta, inframe, shift);

	orient = RotatedRect(Point2f(searchwin.x, searchwin.y), Size2f(searchwin.width, searchwin.height), theta);
	orient.points(vertices);

	for (int i = 0; i < 4; i++){
	   	line(frame, vertices[i], vertices[(i+1)%4], Scalar(0,255,0), 2);
	}

	Rect brect = orient.boundingRect();
	rectangle( frame, brect, Scalar(0,0,255), 2 ); 
	
	imshow( "Source Stream", frame ) ; 

	
	if (inframe){
		simulate(inframe, searchwin, intrins, file); 
	}

}
开发者ID:Ragesam,项目名称:Thesis,代码行数:58,代码来源:camshift.cpp

示例7: refineSegments

static void refineSegments(const Mat& img, Mat& mask, Mat& dst)
{
    int niters = 3;

    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;

    Mat temp;

    dilate(mask, temp, Mat(), Point(-1,-1), niters);
    erode(temp, temp, Mat(), Point(-1,-1), niters*2);
    dilate(temp, temp, Mat(), Point(-1,-1), niters);

    findContours( temp, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE );

    dst = Mat::zeros(img.size(), CV_8UC3);

    if( contours.size() == 0 ) {
        return;
    }

    // iterate through all the top-level contours,
    // draw each connected component with its own random color
    /*
    int idx = 0, largestComp = 0;
    double maxArea = 0;

    for( ; idx >= 0; idx = hierarchy[idx][0] )
    {
        const vector<Point>& c = contours[idx];
        double area = fabs(contourArea(Mat(c)));
        if( area > maxArea )
        {
            maxArea = area;
            largestComp = idx;
        }
    }
    Scalar color( 255, 255, 255 );
    drawContours( dst, contours, largestComp, color, FILLED, LINE_8, hierarchy );
    //drawContours( img, contours, largestComp, color, FILLED, LINE_8, hierarchy );
    */
    RNG& rng = theRNG();
    for (int x = 0; x < contours.size(); x++ ) {
        Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
        drawContours(dst, contours, x, color, FILLED, LINE_8, hierarchy, 0, Point());
    }

    vector<Rect> boundRect(contours.size());
    for (int x = 0; x < contours.size(); x++) {
        RotatedRect box = minAreaRect(contours[x]);
        Point2f vertex[4];
        box.points(vertex);
        for (int y = 0; y < 4; y++) {
            line(img, vertex[y], vertex[(y+1)%4], Scalar(0, 255, 0), 2, LINE_AA);
        }
    }
}
开发者ID:ZH8000,项目名称:FlyCamera,代码行数:57,代码来源:segment_objects.cpp

示例8: main

int main(  )
{
	//改变console字体颜色
	system("color 1F"); 

	//显示帮助文字
	ShowHelpText();

	//初始化变量和随机值
	Mat image(600, 600, CV_8UC3);
	RNG& rng = theRNG();

	//循环,按下ESC,Q,q键程序退出,否则有键按下便一直更新
	while(1)
	{
		//参数初始化
		int count = rng.uniform(3, 103);//随机生成点的数量
		vector<Point> points;//点值

		//随机生成点坐标
		for(int  i = 0; i < count; i++ )
		{

			Point point;
			point.x = rng.uniform(image.cols/4, image.cols*3/4);
			point.y = rng.uniform(image.rows/4, image.rows*3/4);

			points.push_back(point);
		}

		//对给定的 2D 点集,寻找最小面积的包围矩形
		RotatedRect box = minAreaRect(Mat(points));
		Point2f vertex[4];
		box.points(vertex);

		//绘制出随机颜色的点
		image = Scalar::all(0);
		for( int i = 0; i < count; i++ )
			circle( image, points[i], 3, Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)), CV_FILLED, CV_AA );


		//绘制出最小面积的包围矩形
		for( int i = 0; i < 4; i++ )
			line(image, vertex[i], vertex[(i+1)%4], Scalar(100, 200, 211), 2, CV_AA);

		//显示窗口
		imshow( "矩形包围示例", image );

		//按下ESC,Q,或者q,程序退出
		char key = (char)waitKey();
		if( key == 27 || key == 'q' || key == 'Q' ) // 'ESC'
			break;
	}

	return 0;
}
开发者ID:BigCreatation,项目名称:OpenCV3-Intro-Book-Src,代码行数:56,代码来源:73_minAreaRect.cpp

示例9: main

int main(int argc, char** argv) {

	Mat media, variancia;
	Mat fundo, quadroAnterior;
	Mat rastro;
	VideoCapture vid(argv[1]);
	vector<Rastro> rastros;
	RotatedRect conjuntoDasVagas = RotatedRect(Point2f(550, 150), Size2f(200,70), 70);
	int cont = 0;

	

	MediaVariancia(1, argv[1], media, variancia);
	media.copyTo(rastro);

	Point2f vertices[4];
	conjuntoDasVagas.points(vertices);

	for (int i = 0; i < 4; i++)
		line(rastro, vertices[i], vertices[(i + 1) % 4], Scalar(0, 255, 0));

	while (vid.isOpened()) {
		Mat quadro;
		if (!vid.read(quadro)) {
			break;
		}
		else {
			Mat D;
			rectangle(quadro, Point2f(250, 140), Point2f(400, 500), Scalar(0, 0, 0), -1);
			if (!quadroAnterior.empty()) {
				D = Diferenca(quadro, quadroAnterior, 1, atoi(argv[2]));
				//Se os quadros não forem exatamente iguais atualiza o rastro
				if (contaZeros(D)>0) {
					Mat estrut;
					estrut = Mat::ones(6, 6, CV_8UC1);
					dilate(D, D, estrut, Point(-1, -1), 5);
					Mat dBranca = Branco3Canais(D);
					erode(dBranca, dBranca, Mat::ones(3, 3, CV_8UC1), Point(-1, -1), 1);
					Kalman(dBranca, rastro, rastros);

				}
				//imshow("Dilatada", D);
				imshow("rastro", rastro);
				imshow("Video", quadro);
				//imshow("Anterior", quadroAnterior);

				waitKey(1);
			}

			quadro.copyTo(quadroAnterior);
		}
	}

	return 0;
}
开发者ID:Vitor-Lacerda,项目名称:TCC-OpenCV,代码行数:55,代码来源:RastreamentoKalman.cpp

示例10: fitEllipse_check

static Rect fitEllipse_check( vector<Point> contour )
{
    Mat pointsf;
    Mat(contour).convertTo(pointsf, CV_32F);
    RotatedRect box = fitEllipse(pointsf);
    //cout << box.size << "  " << box.size <<endl;
    return box.boundingRect();
    if( MAX(box.size.width, box.size.height) > MIN(box.size.width, box.size.height)*2 )
        return Rect(-1,-1,0,0);
    else
        return box.boundingRect();
}
开发者ID:sturkmen72,项目名称:opencv_samples,代码行数:12,代码来源:CrossAndCircleDetectionDemo.cpp

示例11: getStructuringElement

/*******************************************************************************
* Function:      thresholdByAreaRatioVar  
* Description:   thresholds the FG targets by area, aspect ratio and variance
* Arguments:
	minArea       -   minimum area to preserve
	maxArea       -   maximum area to preserve
	dilateSESize  -   structuring element size for dilation
	erodeSESize   -   structuring element size for erosion
	minAspRatio   -   minimum aspect ratio
	maxAspRatio   -   maximum aspect ratio
	varThresh     -   value of variance threshold
	
* Returns:       void
* Comments:
* Revision: 
*******************************************************************************/
void
FGExtraction::thresholdByAreaRatioVar(double minArea, double maxArea, 
                                          int dilateSESize, int erodeSESize, 
                                          double minAspRatio, double maxAspRatio, int varThresh)
{
	bool passArea, passRatio, passVar;
	vector<vector<Point> > contours;

	// connect separate parts before finding connected components
	Mat dilateSE = getStructuringElement(MORPH_ELLIPSE, Size(dilateSESize, dilateSESize));
	Mat erodeSE = getStructuringElement(MORPH_ELLIPSE, Size(erodeSESize, erodeSESize));
	dilate(_fgImg, _fgImg, dilateSE);
	erode(_fgImg, _fgImg, erodeSE);

	// extract contours of targets
    Mat tempImg = _fgImg.clone();
    findContours(tempImg, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE, Point());
    tempImg.release();

	for(size_t i = 0; i < contours.size(); ++i){
		passArea = passRatio = passVar = false;
		double area = contourArea(contours[i]);
		
		// check if the area is within the desired range
		if (contours[i][0].y > 0.35*_fgImg.rows && contours[i][0].y < 0.68*_fgImg.rows && area > 0.1*minArea && area < maxArea
			|| area > minArea && area < maxArea) 
			passArea = true;
		

		// check if the aspect ratio is within the desired range
		RotatedRect orientedRect = orientedBoundingBox(contours[i]);
		Point2f rectPoints [4]; orientedRect.points(rectPoints);
		double rectWidth = norm(rectPoints[0] - rectPoints[1]);
		double rectHeight = norm(rectPoints[1] - rectPoints[2]);
		double aspRatio = max(rectWidth / rectHeight, rectHeight / rectWidth);
		if (aspRatio > minAspRatio && aspRatio < maxAspRatio) passRatio = true;

		// check if the variance of pixel exceeds the threshold
		// TODO ...
		passVar = true;

		// remove the target if any of the tests fails
		if(!passArea || !passRatio || !passVar){
			//Rect uprightRect = boundingRect(Mat(contours[i]));
			//rectangle(_fgImg, uprightRect, Scalar(0), -1);
			drawContours(_fgImg, contours, i, Scalar(0), -1);
		}
	}

	/*namedWindow("fgImg", 0);
	imshow("fgImg", _fgImg);
	waitKey(0);*/
}
开发者ID:Kitware,项目名称:VIAME,代码行数:69,代码来源:FGExtraction.cpp

示例12: main

/**
 * This is a (modified) test program written by Michael Young
 * (https://github.com/ayoungprogrammer/WebcamCodeScanner). It was modified to
 * work with the Raspicam.
 */
int main(int argc, char* argv[])
{
	PiCamera cam; // open the video camera no. 0
	ImageScanner scanner;  
	scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);  

	namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

	while (1)
	{
		Mat frame = cam.Snap();
		Mat grey;
		cvtColor(frame,grey,CV_BGR2GRAY);

		int width = frame.cols;  
		int height = frame.rows;  
		uchar *raw = (uchar *)grey.data;  
		// wrap image data  
		zbar::Image image(width, height, "Y800", raw, width * height);  
		// scan the image for barcodes  
		int n = scanner.scan(image);  
		// extract results  
		for(Image::SymbolIterator symbol = image.symbol_begin();  
				symbol != image.symbol_end();  
				++symbol) {  
			vector<Point> vp;  
			// do something useful with results  
			cout << "decoded " << symbol->get_type_name()  << " symbol \"" << symbol->get_data() << '"' <<" "<< endl;  
			int n = symbol->get_location_size();  
			for(int i=0;i<n;i++){  
				vp.push_back(Point(symbol->get_location_x(i),symbol->get_location_y(i))); 
			}  
			RotatedRect r = minAreaRect(vp);  
			Point2f pts[4];  
			r.points(pts);  
			for(int i=0;i<4;i++){  
				line(frame,pts[i],pts[(i+1)%4],Scalar(255,0,0),3);  
			}  
		}  

		imshow("MyVideo", frame); //show the frame in "MyVideo" window

		if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
		{
			cout << "esc key is pressed by user" << endl;
			break; 
		}
	}
	return 0;

}
开发者ID:sawbg,项目名称:chip-chip-array,代码行数:56,代码来源:net_qr_test.cpp

示例13: get_min_box

void get_min_box(vector<Point> r, RotatedRect box) {

	if ((box.size.width < 500) && (box.size.width < 500)) {
		if (min_rect.size() == 0)	{		// first rect
			min_rect.push_back(box);
			min_r.push_back(r);
		}
		else {							// every other rect
			bool is_inside = true;
			for (int i = 0; i < int(min_rect.size()); ++i) {
				if (box.boundingRect().contains(min_rect[i].center)) { 	// if hierachical boxes break; else add box
					is_inside = true;
					break;
				}
				else {
					is_inside = false;
				}
			}
			if (is_inside == false) {
				min_rect.push_back(box);
				min_r.push_back(r);
			}
		}				
	}
}
开发者ID:JassiO,项目名称:opencv-touch,代码行数:25,代码来源:stream_or_pictures.cpp

示例14: contains

bool contains(RotatedRect rect, Point pt)
{
	Point2f vertices[4];
	rect.points(vertices);

	bool chk = true;

	for (int i = 0; i < 4; ++i)
	{
		float m = (vertices[i].y - vertices[(i+1) % 4].y)/(vertices[i].x - vertices[(i+1) % 4].x);
		float c = vertices[i].y - m*vertices[i].x;

		float val_pt = pt.y - m*pt.x - c;
		float val_center = rect.center.y - m*rect.center.x - c;

		if (val_pt * val_center > 0)
			chk = true;
		else
		{
			chk = false;
			break;
		}
	}

	return chk;
}
开发者ID:Innovation-Cell,项目名称:final_code_RISE,代码行数:26,代码来源:lane_detect.cpp

示例15: drawRotatedRect

void drawRotatedRect(Mat* img, RotatedRect rect, Scalar color, int thickness)
{
  Point2f rect_points[4];
  rect.points( rect_points );
  for( int j = 0; j < 4; j++ )
    line( *img, rect_points[j], rect_points[(j+1)%4], color, thickness, 8 );
}
开发者ID:JeremiahWill29,项目名称:openalpr,代码行数:7,代码来源:utility.cpp


注:本文中的RotatedRect类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。