【转】OpenCV对图片中的RotatedRect进行填充
2017-04-09 13:46
375 查看
函数名:full_rotated_rect
函数参数: image输入图像,rect希望在图像中填充的RotatedRect,color填充的颜色
主要的思路是:先找到RotatedRect的四个顶点,然后画出外框。再利用四个顶点找出其中平行两边的所有点,对相应的两个点进行连接。
函数名:find_all_point
函数参数:start起始点,end结束点,save保存点的容器
主要思路:递归查找两点的中点,直到两点相同。
原图:
填充后:
转自WizardtoH
函数参数: image输入图像,rect希望在图像中填充的RotatedRect,color填充的颜色
主要的思路是:先找到RotatedRect的四个顶点,然后画出外框。再利用四个顶点找出其中平行两边的所有点,对相应的两个点进行连接。
void full_rotated_rect(Mat &image, const RotatedRect &rect, const Scalar &color) { CvPoint2D32f point[4]; Point pt[4]; vector<Point> center1, center2; /*画出外框*/ cvBoxPoints(rect, point); for (int i = 0; i<4; i++) { pt[i].x = (int)point[i].x; pt[i].y = (int)point[i].y; } line(image, pt[0], pt[1], color, 1); line(image, pt[1], pt[2], color, 1); line(image, pt[2], pt[3], color, 1); line(image, pt[3], pt[0], color, 1); /*填充内部*/ find_all_point(pt[0], pt[1], center1); /*找出两点间直线上的所有点*/ find_all_point(pt[3], pt[2], center2); vector<Point>::iterator itor1 = center1.begin(), itor2 = center2.begin(); while (itor1 != center1.end() && itor2 != center2.end()) { line(image, *itor1, *itor2, color, 1); /*连接对应点*/ itor1++; itor2++; } vector<Point>().swap(center1); vector<Point>().swap(center2); }
函数名:find_all_point
函数参数:start起始点,end结束点,save保存点的容器
主要思路:递归查找两点的中点,直到两点相同。
void find_all_point(Point start, Point end, vector<Point> &save) { if (abs(start.x - end.x) <= 1 && abs(start.y - end.y) <= 1) { save.push_back(start); return; /*点重复时返回*/ } Point point_center; point_center.x = (start.x + end.x) / 2; point_center.y = (start.y + end.y) / 2; save.push_back(point_center); /*储存中点*/ find_all_point(start, point_center, save); /*递归*/ find_all_point(point_center, end, save); }
原图:
填充后:
转自WizardtoH
相关文章推荐
- OpenCV对图片中的RotatedRect进行填充
- OpenCV入门系列(5):对图片进行基本的变换
- opencv用图片or视频 进行人脸检测
- 【OpenCV学习】Kmean均值聚类对图片进行减色处理
- opencv 3.0 旋转矩形 RotatedRect
- 获取OpenCV中RotatedRect的绝对角度
- 利用OpenCV通过HSV直方图来进行图片定位
- 【openCV】载入图片过大(大于显示屏的分辨率),进行图片大小修改
- 【OpenCV学习】Kmean均值聚类对图片进行减色处理
- OpenCV RotatedRect angle is wrong
- opencv学习笔记:RotatedRect和CvBox2D的角度疑云
- opencv读取某文件夹下图片并进行归一化
- linux下用python进行opencv开发----简单的图片操作
- opencv 学习第二天 学习opencv(中文版)对一幅图片进行canny边缘检测
- 【OpenCV学习】Kmean均值聚类对图片进行减色处理
- 加载到图片之后,对图片进行等比例填充缩放 分类: 图片等比缩放 加载图片后缩放 图片缩放 2014-04-22 10:41 312人阅读 评论(0) 收藏
- 【OpenCV学习】Kmean均值聚类对图片进行减色处理
- opencv 学习第二天 学习opencv(中文版)对一幅图片进行高斯平滑并缩小一半
- OpenCV读入图片序列进行HOG行人检测并保存为视频
- 使用opencv创建一张纯黑色的图片与其他图片进行合成