WrapPerspective没有正确解露

时间:2017-08-14 14:59:49

标签: c++ opencv

std::vector<std::pair<cv::Point, cv::Point>> tempEndPoints的一些程序之后,我将获得以下firstsecond参数:

first: [139, 113][201, 310][223, 339][297, 437][323, 472][381, 465][408, 413][484, 291][505, 151]
second: [139, 210][201, 692][223, 664][297, 550][323, 523][381, 544][408, 580][484, 699][505, 254]

现在我被wrapPerspective困住了。每个&#34;角落&#34; points会创建一个小图像,它具有单独的大小(之前由textureImage创建)。一切都存储,这也很好。但是现在我想把所有这些&#34;小图像&#34;在这些点之内,我之前提到过。

for (int i = 0; i < tempEndPoints.size() - 1; i++) {    
    //do some stuff...
    cv::Vec3b zero(0, 0, 0);

    cv::Mat_<cv::Vec3b> dewrapped(textureImage.rows, textureImage.cols, zero);

    cv::Point2f srcPts[] = {
        Point2f(tempEndPoints[i].first),
            Point2f(tempEndPoints[i + 1].first),
            Point2f(tempEndPoints[i + 1].second),
            Point2f(tempEndPoints[i].second) };

    std::cout << "srcPoints: " << tempEndPoints[i].first << ", " << tempEndPoints[i + 1].first
        << ", " << tempEndPoints[i + 1].second << ", " << tempEndPoints[i].second << "\n";

    const cv::Point2f dstPts[] = {
        cv::Point2f(tempEndPoints[i].first),
        cv::Point2f(tempEndPoints[i + 1].first.x, tempEndPoints[i].first.y),
        cv::Point2f(tempEndPoints[i + 1].second.x, tempEndPoints[i].second.y),
        cv::Point2f(tempEndPoints[i].second)};

    std::cout << "dstPoints: " << tempEndPoints[i].first << ", " << tempEndPoints[i + 1].first.x << "-" << tempEndPoints[i].first.y
        << ", " << tempEndPoints[i + 1].second.x << "-" << tempEndPoints[i].second.y << ", " << tempEndPoints[i].second << "\n";

    cv::Mat homography_matrix = cv::getPerspectiveTransform(srcPts, dstPts);

    cv::warpPerspective(textureImage, dewrapped, homography_matrix, textureImage.size());
    cv::imshow("dewrap", dewrapped);

跟随this blog似乎没有发生任何事情 - 好吧,我只是得到一张黑色图片。 srcPtsdstPts中点数的顺序为:

1---2
|   |
4---3

this question,我尝试了另一个订单,但我也得到了一张黑色图片。所以现在我在博客中有这个订单,我之前提到过。我的代码中我做错了什么?

[编辑:] srcPtdstPt的输出为:

srcPts: [20, 54], [123, 83], [123, 188], [20, 65]
dstPts: [20, 54], [123, 54], [123, 65], [20, 65]
srcPts: [123, 83], [181, 362], [181, 718], [123, 188]
dstPts: [123, 83], [181, 83], [181, 188], [123, 188]
srcPts: [181, 362], [278, 412], [278, 569], [181, 718]
dstPts: [181, 362], [278, 362], [278, 718], [181, 718]
srcPts: [278, 412], [290, 428], [290, 557], [278, 569]
dstPts: [278, 412], [290, 412], [290, 569], [278, 569]
srcPts: [290, 428], [321, 469], [321, 525], [290, 557]
dstPts: [290, 428], [321, 428], [321, 557], [290, 557]
srcPts: [321, 469], [373, 476], [373, 534], [321, 525]
dstPts: [321, 469], [373, 469], [373, 525], [321, 525]
srcPts: [373, 476], [387, 447], [387, 552], [373, 534]
dstPts: [373, 476], [387, 476], [387, 534], [373, 534]
srcPts: [387, 447], [407, 415], [407, 579], [387, 552]
dstPts: [387, 447], [407, 447], [407, 552], [387, 552]
srcPts: [407, 415], [421, 392], [421, 597], [407, 579]
dstPts: [407, 415], [421, 415], [421, 579], [407, 579]
srcPts: [421, 392], [531, 90], [531, 212], [421, 597]
dstPts: [421, 392], [531, 392], [531, 597], [421, 597]

0 个答案:

没有答案