opencv getRectSubPix()函数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27278957/article/details/88873066

函数作用

从原图像中提取一个感兴趣的矩形区域图像。

函数原型

C++: void getRectSubPix(InputArray image, Size patchSize, Point2f center, OutputArray dst, int patchType=-1 )

参数解释

InputArray image:输入图像

Size patchSize:获取感兴趣区域矩形的大小

Point2f center:感兴趣区域矩形在原图像中的位置(即感兴趣区域矩形的中心点坐标)

OutputArray patch:输出的图像

int patchType=-1 :表示输出图像的深度。默认-1 ,深度不变

官方介绍 

getRectSubPix

Retrieves a pixel rectangle from an image with sub-pixel accuracy.

C++: void getRectSubPix(InputArray image, Size patchSize, Point2f center, OutputArray dst, int patchType=-1 )

Parameters:
  • src – Source image.
  • patchSize – Size of the extracted patch.
  • center – Floating point coordinates of the center of the extracted rectangle within the source image. The center must be inside the image.
  • dst – Extracted patch that has the size patchSize and the same number of channels as src .
  • patchType – Depth of the extracted pixels. By default, they have the same depth as src .

The function getRectSubPix extracts pixels from src :

dst(x, y) = src(x +  \texttt{center.x} - ( \texttt{dst.cols} -1)*0.5, y +  \texttt{center.y} - ( \texttt{dst.rows} -1)*0.5)

where the values of the pixels at non-integer coordinates are retrieved using bilinear interpolation. Every channel of multi-channel images is processed independently. While the center of the rectangle must be inside the image, parts of the rectangle may be outside. In this case, the replication border mode (see borderInterpolate() ) is used to extrapolate the pixel values outside of the image.

示例

代码:

#include <iostream>
#include <opencv.hpp>

using namespace cv;
using namespace std;

int main()
{
	Mat srcImg = imread("HanJiaRen1.jpg");
	Mat dstImg;
	getRectSubPix(srcImg, Size(srcImg.cols / 2, srcImg.rows / 2), Point2f(srcImg.cols / 2, srcImg.rows / 2), dstImg, -1);

	imshow("srcImg", srcImg);
	imshow("dstImg", dstImg);
	waitKey(0);
	return 0;
}

结果显示:

 

猜你喜欢

转载自blog.csdn.net/qq_27278957/article/details/88873066