代码:
#include
#include
usingnamespacestd;
usingnamespacecv;
intmain()
{
char*imageSrc ="I:\\OpenCV Learning\\picture\\sumpalace.jpg";
Mat matImage = imread(imageSrc,-1);
IplImage *iplImage = cvLoadImage(imageSrc,-1);
if(matImage.data==0||iplImage->imageData ==0)
{
cout<
return-1;
}
cv::rectangle(matImage,cvPoint(20,200),cvPoint(200,300),Scalar(255,0,0),1,1,0);
//Rect(int a,int b,int c,int d)a,b为矩形的左上角坐标,c,d为矩形的长和宽
cv::rectangle(matImage,Rect(100,300,20,200),Scalar(0,0,255),1,1,0);
cvRectangle(iplImage,cvPoint(20,200),cvPoint(200,300),Scalar(0,255,255),1,1,0);
imshow("matImage",matImage);
cvShowImage("IplImage",iplImage);
waitKey();
return0;
}
#include
#include
using namespace std;
using namespace cv;
int main()
{
char *imageSrc = "I:\\OpenCV Learning\\picture\\sumpalace.jpg";
Mat matImage = imread(imageSrc,-1);
IplImage *iplImage = cvLoadImage(imageSrc,-1);
if(matImage.data==0||iplImage->imageData ==0)
{
cout<
return -1;
}
cv::rectangle(matImage,cvPoint(20,200),cvPoint(200,300),Scalar(255,0,0),1,1,0);
//Rect(int a,int b,int c,int d)a,b为矩形的左上角坐标,c,d为矩形的长和宽
cv::rectangle(matImage,Rect(100,300,20,200),Scalar(0,0,255),1,1,0);
cvRectangle(iplImage,cvPoint(20,200),cvPoint(200,300),Scalar(0,255,255),1,1,0);
imshow("matImage",matImage);
cvShowImage("IplImage",iplImage);
waitKey();
return 0;
}
结果:
如果需要在Mat类型的图上绘制矩形,选择cv::trctangle()
在IplImage*类型的图上绘制矩形,选择cvRectangle()