opencv怎样用加权平均法做图像融合? 50
在做基于Sift算子的图像融合,已经完成检测出单应矩阵,下一步要做图像融合,不知道怎么做了,求助各位,如何用加权平均法(其他方法也可)做图像融合,代码怎么写?(开发环境:...
在做基于Sift算子的图像融合,已经完成检测出单应矩阵,下一步要做图像融合,不知道怎么做了,求助各位,如何用加权平均法(其他方法也可)做图像融合,代码怎么写?(开发环境:VS2010 opencv2.4.9 C++)
这是检测单应矩阵的代码:
std::vector<uchar> inliers(points1.size(),0);
cv::Mat homography= cv::findHomography(
cv::Mat(points1),cv::Mat(points2), // corresponding points
inliers, // outputed inliers matches
CV_RANSAC, // RANSAC method
1.); // max distance to reprojection point
// Draw the inlier points
std::vector<cv::Point2f>::const_iterator itPts= points1.begin();
std::vector<uchar>::const_iterator itIn= inliers.begin();
while (itPts!=points1.end()) {
// draw a circle at each inlier location
if (*itIn)
cv::circle(image1,*itPts,3,cv::Scalar(255,255,255),2);
++itPts;
++itIn;
}
itPts= points2.begin();
itIn= inliers.begin();
while (itPts!=points2.end()) {
// draw a circle at each inlier location
if (*itIn)
cv::circle(image2,*itPts,3,cv::Scalar(255,255,255),2);
++itPts;
++itIn;
}
// 将单应点显示出来
cv::namedWindow("Image 1 Homography Points");
cv::imshow("Image 1 Homography Points",image1);
cv::namedWindow("Image 2 Homography Points");
cv::imshow("Image 2 Homography Points",image2);
// Warp image 1 to image 2
cv::Mat result;
cv::warpPerspective(image1, // input image
result, // output image
homography, // homography
cv::Size(2*image1.cols,image1.rows)); // size of output image
//复制图1到整个图像的前半部分
cv::Mat half(result,cv::Rect(0,0,image2.cols,image2.rows));
image2.copyTo(half);
// Display the warp image
cv::namedWindow("After warping");
cv::imshow("After warping",result); 展开
这是检测单应矩阵的代码:
std::vector<uchar> inliers(points1.size(),0);
cv::Mat homography= cv::findHomography(
cv::Mat(points1),cv::Mat(points2), // corresponding points
inliers, // outputed inliers matches
CV_RANSAC, // RANSAC method
1.); // max distance to reprojection point
// Draw the inlier points
std::vector<cv::Point2f>::const_iterator itPts= points1.begin();
std::vector<uchar>::const_iterator itIn= inliers.begin();
while (itPts!=points1.end()) {
// draw a circle at each inlier location
if (*itIn)
cv::circle(image1,*itPts,3,cv::Scalar(255,255,255),2);
++itPts;
++itIn;
}
itPts= points2.begin();
itIn= inliers.begin();
while (itPts!=points2.end()) {
// draw a circle at each inlier location
if (*itIn)
cv::circle(image2,*itPts,3,cv::Scalar(255,255,255),2);
++itPts;
++itIn;
}
// 将单应点显示出来
cv::namedWindow("Image 1 Homography Points");
cv::imshow("Image 1 Homography Points",image1);
cv::namedWindow("Image 2 Homography Points");
cv::imshow("Image 2 Homography Points",image2);
// Warp image 1 to image 2
cv::Mat result;
cv::warpPerspective(image1, // input image
result, // output image
homography, // homography
cv::Size(2*image1.cols,image1.rows)); // size of output image
//复制图1到整个图像的前半部分
cv::Mat half(result,cv::Rect(0,0,image2.cols,image2.rows));
image2.copyTo(half);
// Display the warp image
cv::namedWindow("After warping");
cv::imshow("After warping",result); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询