c_cpp 从图片中提取平行四边形区域以将其重新映射为矩形。没有描述
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 从图片中提取平行四边形区域以将其重新映射为矩形。没有描述相关的知识,希望对你有一定的参考价值。
Mat * extractImageSelection(Mat &src, Point2i paramUpperLeft, Point2i paramUpperRight, Point2i paramLowerLeft)
{
//get Src image informations
int localWidth = src.cols;
int localHeight = src.rows;
//compute dest image information
int localDestWidth = (int) sqrt(pow(paramUpperRight.x - paramUpperLeft.x, 2) + pow(paramUpperRight.y - paramUpperLeft.y, 2));
int localDestHeight = (int) sqrt(pow(paramLowerLeft.x - paramUpperLeft.x, 2) + pow(paramLowerLeft.y - paramUpperLeft.y, 2));
//create a new image to contain the selection from the source image
Mat * localDestImage = new Mat(localDestHeight, localDestWidth, src.type());
//compute slection's upper side steep for x in function of y and left side steep for y in function of x
double localDeltaX = (double) (paramUpperRight.y - paramUpperLeft.y) / (paramUpperRight.x - paramUpperLeft.x);
double localDeltaY = (double) (paramLowerLeft.x - paramUpperLeft.x) / (paramLowerLeft.y - paramUpperLeft.y);
//compute x and y increments ratio between dest and source
double localXRatio = (double) 1 / sqrt(pow(localDeltaX, 2) + 1);
double localYRatio = (double) 1 / sqrt(pow(localDeltaY, 2) + 1);
//position conversion from dest points to source points
for (int localDestY = 0; localDestY < localDestHeight; localDestY++) {
for (int localDestX = 0; localDestX < localDestWidth; localDestX++) {
int localXSrc = paramUpperLeft.x + localDestY * localYRatio * localDeltaY + localDestX * localXRatio;
int localYSrc = paramUpperLeft.y + localDestX * localXRatio * localDeltaX + localDestY * localYRatio;
if (localXSrc < 0 || localYSrc < 0 || localXSrc >= localWidth || localYSrc >= localHeight)
continue;
uchar* localSrcPixel = &src.ptr<uchar>(localYSrc)[localXSrc];
uchar* localDestPixel = &localDestImage->ptr<uchar>(localDestY)[localDestX];
*localDestPixel = *localSrcPixel;
}
}
return localDestImage;
}
以上是关于c_cpp 从图片中提取平行四边形区域以将其重新映射为矩形。没有描述的主要内容,如果未能解决你的问题,请参考以下文章
如何把视频提取照片
如何从 WebFlux 中的 Mono<List<T>> 中提取内容以将其传递到调用链中
从周围的边界框中提取车牌平行四边形?
从视频中提取图片,对图片做人脸检测并截取人脸区域
平行拟合和旋转两个 3D 网格节点
Java解析truetype字体以将每个字符提取为图像及其代码