Opencv错误:assePion在wrapPerspective中失败

时间:2017-09-24 19:32:11

标签: c++ opencv

我正在尝试制作AR应用程序,使用aruco和Opencv(我是新手)。它检测aruco标记,并在其上放置图像。我试过使用wrapPerstective()函数,但是somethig是错误的,它在wrapPerspective中返回Opencv错误断言失败((m0.type()== cv_32f m0.type()== cv_64f)。请给我一个解决方法它

int main() {
    cv::VideoCapture inputVideo;
    inputVideo.open("gal.mp4");
    cv::Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_50);

    cv::Mat sq = imread("zhuz.jpg", CV_LOAD_IMAGE_UNCHANGED);

    while (inputVideo.grab()) {

        vector<Point2f> sqPoints;
        vector<Point2f> p;

        sqPoints.push_back(Point2f(0, 0));
        sqPoints.push_back(Point2f(sq.cols, 0));
        sqPoints.push_back(Point2f(sq.cols, sq.rows));
        sqPoints.push_back(Point2f(0, sq.rows));

        cv::Mat image, warp_matrix;
        inputVideo.retrieve(image);

        Mat cpy_img(image.rows, image.cols, image.type());
        Mat neg_img(image.rows, image.cols, image.type());
        Mat gray;
        Mat blank(sq.rows, sq.cols, sq.type());

        std::vector<int> ids;
        std::vector<std::vector<cv::Point2f>> corners;

        cv::aruco::detectMarkers(image, dictionary, corners, ids);

        if (ids.size() > 0) {
            p.push_back(corners[0][0]);
            p.push_back(corners[0][1]);
            p.push_back(corners[0][2]);
            p.push_back(corners[0][3]);


            Mat wrap_matrix = getPerspectiveTransform(sqPoints, p);

            blank = Scalar(0);
            neg_img = Scalar(0);        // Image is white when pixel values are zero
            cpy_img = Scalar(0);        // Image is white when pixel values are zero

            bitwise_not(blank, blank);

            warpPerspective(sq, neg_img, warp_matrix, Size(neg_img.cols, neg_img.rows)); // Transform overlay Image to the position - [ITEM1]
            warpPerspective(blank, cpy_img, warp_matrix, Size(cpy_img.cols, neg_img.rows));  // Transform a blank overlay image to position 
            bitwise_not(cpy_img, cpy_img);       // Invert the copy paper image from white to black
            bitwise_and(cpy_img, image, cpy_img);      // Create a "hole" in the Image to create a "clipping" mask - [ITEM2]      
            bitwise_or(cpy_img, neg_img, image);      // Finally merge both items [ITEM1 & ITEM2]
        }

        cv::imshow("out", image);
    }
}

0 个答案:

没有答案