如何在opencv中根据图像的宽度和高度动态绘制矩形?
我想根据图像的宽度和高度在opencv中绘制一个矩形(也就是说,我不想给如何在opencv中根据图像的宽度和高度动态绘制矩形?,c,image-processing,opencv,roi,C,Image Processing,Opencv,Roi,我想根据图像的宽度和高度在opencv中绘制一个矩形(也就是说,我不想给cvRectangle)我想绘制一个覆盖任何大小图像大部分区域的矩形,换句话说,我想在每个图像中绘制最大的矩形,谢谢,是否要使用百分比维度 IplImage *img=cvLoadImage(fileName,CV_LOAD_IMAGE_COLOR); int imageWidth = img->width; int imageHeight = img->height; int imageSize = i
cvRectangle
)我想绘制一个覆盖任何大小图像大部分区域的矩形,换句话说,我想在每个图像中绘制最大的矩形,谢谢,是否要使用百分比维度
IplImage *img=cvLoadImage(fileName,CV_LOAD_IMAGE_COLOR);
int imageWidth = img->width;
int imageHeight = img->height;
int imageSize = img->nSize;
int ratio = 90; // our ROI will be 90% of our input image
int roiWidth = (int)(imageWidth*ratio/100);
int roiHeight = (int)(imageHeight*ratio/100);
// offsets from image borders
int dw = (int) (imageWidth-roiWidth)/2;
int dh = (int) (imageHeight-roiHeight)/2;
cvRectangle(img,
cvPoint(dw,dh), // South-West point
cvPoint(roiWidth+dw, roiHeight+dh), // North-East point
cvScalar(0, 255, 0, 0),
1, 8, 0);
cvSetImageROI(img,cvRect(dw,dh,roiWidth,roiHeight));
因此,现在,如果您将比率设置为90,并且输入图像为1000x1000像素,那么您的ROI将为900x900像素,并且它将位于图像的中心。我已经尝试过了,效果很好
IplImage *img=cvLoadImage(fileName,CV_LOAD_IMAGE_COLOR);
int imageWidth=img->width-150;
int imageHeight=img->height-150;
int imageSize=img->nSize;
cvRectangle(img,cvPoint(imageWidth,imageHeight), cvPoint(50, 50),cvScalar(0, 255, 0, 0),1,8,0);
cvSetImageROI(img,cvRect(50,50,(imageWidth-50),(imageHeight-50)));
你的意思是只需检索图像的宽度和高度,并将它们输入到每个图像的cvRectangle中??好的,谢谢@mathematic.coffee,我已经用相关的答案更新了我的问题。如果你回答了自己的问题,请随意发布答案并接受它。