cv::warpPerspective() 函数的问题

issue with cv::warpPerspective() function

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

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

image without warpPerspective

image with warpPerspective

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 函数,然后对该图像和目标图像求和才能得到正确的结果。