国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

opencv 基本繪圖函數總結

2019-11-06 06:28:39
字體:
來源:轉載
供稿:網友
#include "opencv2/calib3d/calib3d.hpp"  #include "opencv2/highgui/highgui.hpp"  #include "opencv2/imgPRoc/imgproc.hpp"   using namespace cv;using namespace std;void DrawTransRec(Mat mat, int x, int y, int width, int height, CvScalar color, double alpha);void DrawTransRec(Mat mat, int x, int y, int width, int height, CvScalar color, double alpha){	iplImage * img = &(IplImage)mat;	IplImage * rec = cvCreateImage(cvSize(width, height), img->depth, img->nChannels);	//if(x>0&&y>0&&x<mat.cols&&y<mat.){  	cv::Rect roi = cv::Rect(x, y, width, height) & cv::Rect(0, 0, mat.cols, mat.rows);	if (roi.area() != width*height)return;	cvRectangle(rec, cvPoint(0, 0), cvPoint(width, height), color, -1);	cvSetImageROI(img, cvRect(roi.x, roi.y, roi.width, roi.height));	cvAddWeighted(img, alpha, rec, 1 - alpha, 0.0, img);	cvResetImageROI(img);	cvReleaseImage( &rec);}int main(int argc, char** argv){	Mat picture(500, 500, CV_8UC3, Scalar(255, 255, 255, 0.5));	// 畫箭頭	Point point1 = Point(0, 0);	Point point2 = Point(100, 100);  // 2表示線寬  8 表示線型  0 暫時不清楚  0.1表示箭頭的長度	arrowedLine(picture, point1, point2, Scalar(0, 255, 0), 2,8,0,0.1);	//畫直線	point1 = Point(0, 100);	point2 = Point(100, 200); // 2表示線寬  8 表示線型	line(picture, point1, point2, Scalar(0, 0, 255), 2, 8, 0);	//畫圓	int r = 50;//半徑  	Point center = Point(150, 50);  //其中2改為-1 表示填充	circle(picture, center, r, Scalar(123, 21, 32), 2,8,0);  	//畫矩形	Rect rec(300,300,150,150);	rectangle(picture, rec, Scalar(123, 21, 32), 2, 8, 0);	//clipLine的作用是剪切圖像矩形區域內部的直線	point1 = Point(250, 250);	point2 = Point(450, 450);	line(picture, point1, point2, Scalar(0, 255, 0), 2, 8, 0);	clipLine(rec, point1, point2);	line(picture, point1, point2, Scalar(0, 0, 255), 2, 8, 0);	//輸入文字	Point textPt(210, 50);	String text = "drawtext";	int fontFace = FONT_HERSHEY_PLAIN;	double fontScale = 2;	int thickness = 2;	putText(picture, text, textPt, fontFace, fontScale, Scalar(0, 111, 255), thickness);	//getTextSize()返回一個指定字體以及大小的String所占的空間	int baseline = 0;	Size textSize = getTextSize(text, fontFace,fontScale, thickness, &baseline);	rectangle(picture, Point(textPt.x, textPt.y - textSize.height), Point(textPt.x + textSize.width, textPt.y + thickness/2), Scalar(0, 255, 0, 1), 1);	//畫標記  	//目前支持六種標記	//MARKER_TILTED_CROSS,MARKER_STAR, MARKER_DIAMOND, MARKER_SQUARE ,MARKER_TRIANGLE_UP, MARKER_TRIANGLE_DOWN 	drawMarker(picture, Point(480, 50), Scalar(0, 0, 255), MARKER_TILTED_CROSS);	//畫橢圓	Size 軸(20, 50);//軸線長度,橫著20,豎著50  	ellipse(picture, Point(50, 150), 軸, 20.0, 0.0, 300.0, Scalar(55, 123, 222), -1);	//參數說明,axes表示軸,20.0表示整個橢圓旋轉20度,從0開始畫到300度  	//重載函數利用了RotatedRect,表示在一個旋轉矩形里畫最大橢圓  	RotatedRect box1(Point(150, 150), Size(40, 100), -20);//負的為逆時針  	ellipse(picture, box1, Scalar(122, 122, 122));	vector<Point> pointstest;	ellipse2Poly(Point(50, 150), 軸, 20.0, 0.0, 300.0, 1, pointstest);	//畫多邊形	Point points[2][20];	points[0][0] = Point(300, 100);	points[0][1] = Point(400, 100);	points[0][2] = Point(450, 200);	points[0][3] = Point(350, 250);	points[0][4] = Point(250, 200);	points[1][0] = Point(300, 100) + Point(-200, +150);	points[1][1] = Point(400, 100) + Point(-200, +150);	points[1][2] = Point(450, 200) + Point(-200, +150);	points[1][3] = Point(350, 250) + Point(-200, +150);	points[1][4] = Point(250, 200) + Point(-200, +150);	const Point* pt[2] = { points[0], points[1] };	int npt[2] = { 5,5 };	polylines(picture, pt, npt, 2, 1, Scalar(0, 0, 255), 3);	fillPoly(picture, pt, npt, 1, Scalar(250, 255, 0), 8);		//繪制半透明矩形	DrawTransRec(picture, 50, 320, 400, 100, Scalar(255, 122, 122), 0.2);	imshow("show", picture);	waitKey(0);	return 0;}
上一篇:Lucky Number

下一篇:單鏈表C實例

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 从化市| 永胜县| 英吉沙县| 会东县| 涡阳县| 靖边县| 湖南省| 芜湖县| 巴彦县| 本溪市| 东海县| 申扎县| 汨罗市| 辽宁省| 平顶山市| 吉安市| 五台县| 镇沅| 谢通门县| 丹江口市| 德兴市| 榕江县| 纳雍县| 北宁市| 徐闻县| 乌恰县| 汾西县| 保亭| 二连浩特市| 江都市| 河间市| 桐乡市| 民勤县| 封丘县| 海盐县| 乐山市| 淳化县| 隆子县| 屏东县| 兴文县| 临澧县|