openCV 画矩形框或填充矩形
2017-04-04 23:56
323 查看
目录(?)[+]
rectangle:画矩形
Draws a simple, thick, or filled up-right rectangle.画一个简单或填充的矩形
C++: void rectangle(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8,int shift=0)函数原型一
C++: void rectangle(Mat& img, Rect r, const Scalar& color, int thickness=1, int lineType=8, int shift=0)函数原型二
Python: cv2.rectangle(img, pt1, pt2, color[,
thickness[, lineType[, shift ]]])! None
C: void cvRectangle(CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int line Type=8, int shift=0 )函数原型三
Python: cv.Rectangle(img, pt1, pt2, color, thickness=1, lineType=8, shift=0) !None
Parameters参数
img – Image.
pt1 – Vertex of the rectangle.
pt2 – Vertex of the recangle opposite to pt1 .
r – Alternative specification of the drawn rectangle.
color – Rectangle color or brightness (grayscale image).
thickness – Thickness of lines that make up the rectangle. Negative values, like CV_FILLED
, mean that the function has to draw a filled rectangle.
lineType – Type of the line. See the line() description.
shift – Number of fractional bits in the point coordinates.
The function rectangle draws a rectangle outline or a filled rectangle whose two opposite corners are pt1 and pt2,
or r.tl() and r.br()-Point(1,1).
plain copy
#include "stdafx.h"
#include <string>
#include <opencv2\opencv.hpp>
#include "cv.h"
#include "highgui.h"
using namespace cv;
using namespace std;
int main()
{
IplImage* img = cvLoadImage( "lena.jpg" );
// cvRectangle函数参数: 图片, 左上角, 右下角, 颜色, 线条粗细, 线条类型,点类型
cvRectangle( img, cvPoint(100, 100), cvPoint(200, 200), cvScalar(0, 0, 255), 3, 4, 0 );
cvNamedWindow( "donkeyaime", CV_WINDOW_AUTOSIZE );
cvShowImage( "donkeyaime", img );
cvWaitKey(0);
cvReleaseImage( &img );
}
plain copy
#include <string>
#include <opencv2\opencv.hpp>
#include "cv.h"
#include "highgui.h"
using namespace cv;
using namespace std;
Rect select;//声明矩形
Point pt1;//点坐标1
Point pt2;//点坐标2
int main()
{
string imagename = "lena.jpg"; //此处需要填写绝对地址,我测试时使用相对地址出错。
Mat img = imread(imagename);//读入图像
select.x = 50;
select.y = 50;
select.width =100;
select.height =100;
pt1.x = 200;
pt1.y = 200;
pt2.x = 250;
pt2.y = 250;
rectangle(img,select,Scalar(0,0,255),3,8,0);//用矩形画矩形窗
rectangle(img,pt1,pt2,Scalar(0,0,255),3,8,0);//用点画矩形窗
namedWindow("image",1);
imshow("image", img);
waitKey(0);
}
顶
1
踩
rectangle:画矩形
Draws a simple, thick, or filled up-right rectangle.画一个简单或填充的矩形
C++: void rectangle(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8,int shift=0)函数原型一
C++: void rectangle(Mat& img, Rect r, const Scalar& color, int thickness=1, int lineType=8, int shift=0)函数原型二
Python: cv2.rectangle(img, pt1, pt2, color[,
thickness[, lineType[, shift ]]])! None
C: void cvRectangle(CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int line Type=8, int shift=0 )函数原型三
Python: cv.Rectangle(img, pt1, pt2, color, thickness=1, lineType=8, shift=0) !None
Parameters参数
img – Image.
pt1 – Vertex of the rectangle.
pt2 – Vertex of the recangle opposite to pt1 .
r – Alternative specification of the drawn rectangle.
color – Rectangle color or brightness (grayscale image).
thickness – Thickness of lines that make up the rectangle. Negative values, like CV_FILLED
, mean that the function has to draw a filled rectangle.
lineType – Type of the line. See the line() description.
shift – Number of fractional bits in the point coordinates.
The function rectangle draws a rectangle outline or a filled rectangle whose two opposite corners are pt1 and pt2,
or r.tl() and r.br()-Point(1,1).
方法一:
[cpp] viewplain copy
#include "stdafx.h"
#include <string>
#include <opencv2\opencv.hpp>
#include "cv.h"
#include "highgui.h"
using namespace cv;
using namespace std;
int main()
{
IplImage* img = cvLoadImage( "lena.jpg" );
// cvRectangle函数参数: 图片, 左上角, 右下角, 颜色, 线条粗细, 线条类型,点类型
cvRectangle( img, cvPoint(100, 100), cvPoint(200, 200), cvScalar(0, 0, 255), 3, 4, 0 );
cvNamedWindow( "donkeyaime", CV_WINDOW_AUTOSIZE );
cvShowImage( "donkeyaime", img );
cvWaitKey(0);
cvReleaseImage( &img );
}
方法二:
[cpp] viewplain copy
#include <string>
#include <opencv2\opencv.hpp>
#include "cv.h"
#include "highgui.h"
using namespace cv;
using namespace std;
Rect select;//声明矩形
Point pt1;//点坐标1
Point pt2;//点坐标2
int main()
{
string imagename = "lena.jpg"; //此处需要填写绝对地址,我测试时使用相对地址出错。
Mat img = imread(imagename);//读入图像
select.x = 50;
select.y = 50;
select.width =100;
select.height =100;
pt1.x = 200;
pt1.y = 200;
pt2.x = 250;
pt2.y = 250;
rectangle(img,select,Scalar(0,0,255),3,8,0);//用矩形画矩形窗
rectangle(img,pt1,pt2,Scalar(0,0,255),3,8,0);//用点画矩形窗
namedWindow("image",1);
imshow("image", img);
waitKey(0);
}
顶
1
踩
相关文章推荐
- openCV 画矩形框或填充矩形
- openCV 画矩形框或填充矩形
- opencv 3.0 填充矩形 填充多边形 fillPoly
- opencv-线,椭圆,长方形(矩形),圆,填充多边形绘制
- OpenCV学习九:绘制直线、矩形、椭圆、原型、填充任意图形
- opencv_tutorial_code学习——画椭圆、圆、填充矩形、直线
- OpenCV在图像上画线、矩形、椭圆、多边形、填充的多边形、圆、显示文字
- opencv在图片指定区域内填充矩形,并在图片中显示矩形的轮廓
- opencv 填充矩形 填充多边形
- opencv 3.0 填充矩形 填充多边形 fillPoly
- j2me学习笔记【13】——创建矩形框、圆角矩形以及填充颜色小例子
- 【opencv的学习】直线,矩形,圆,文字显示的初步尝试
- OpenCV图象孔洞内轮廓填充
- 使用opencv实现matlab中的imfill填充孔洞功能
- 基础学习笔记之opencv(5):实现鼠标选定矩形框
- Canvas---Canvas版画图、圆角矩形、圆形、矩形、图形填充、mvc模式重新整合代码版
- opencv-- 使用鼠标绘制矩形并截取和保存矩形区域图像
- [Cocoa]_[初级]_[画一个矩形框,并在里面填充数据]
- opencv识别正方形(矩形)代码
- opencv——通过面积筛选最大轮廓,并求凸包矩形的长和宽