cv::warpPerspective() 函数的问题

issue with cv::warpPerspective() function

本文关键字:问题 函数 warpPerspective cv      更新时间:2023-10-16

我想通过使用warpPerspective使用haarcascade分类器将图像叠加在先前检测到的项上。图像似乎缩放正确,但图像的其余部分变为黑色。

我试图修改源和目标图像的透明度,但我不知道它是否成功。

没有扭曲透视的图像

带有扭曲透视的图像

Rect r = boundingRects.carRects.at(i).rect; // points of the object in the image.
vector<Point2d> imagePoints;
imagePoints.push_back(Point2d(r.x, r.y));
imagePoints.push_back(Point2d(r.x + r.width, r.y));
imagePoints.push_back(Point2d(r.x + r.width, r.y+ r.height));
imagePoints.push_back(Point2d(r.x, r.y + r.height));
dimensions.push_back(Point2d(0, 0)); // dimensions of the source image
dimensions.push_back(Point2d(899, 0));
dimensions.push_back(Point2d(899, 539));
dimensions.push_back(Point2d(0, 539));
H = findHomography(carAlertObject.dimensions, imagePoints); // get homography matrix
warpPerspective(carAlertObject.img, img, H,img.size()); // carAlertObject contains the source image and dimensions, img is the destination image

问题是我必须使用遮罩图像来应用 warpPerspective 函数,然后对该图像和目标图像进行总和以获得正确的结果。