本文介绍了如何计算cv :: Mat的步幅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何计算cv:Mat的步幅;

I would like to know how would I calculate the stride of a cv:Mat;

我已经更新了代码,需要计算步幅,我不知道计算投影变换有什么问题.我得到一个cv :: Mat,然后将其复制到unsigned int数组,然后对其进行转换,然后取回一个cv :: Mat进行显示.

I have updated the code, where I need to calculate the stride, I don't know what's wrong to calculate the projective transformation.I get a cv::Mat then copy it to unsigned int array, then do the transformation on it, then get back a cv::Mat to be shown.

  cv::Mat3b  srcIm;
        srcIm = imread("15016889798859437.jpg");


    cv::Mat3b  srcIm, edges;
    srcIm = imread("Lenna.png");


    image_t src, dst;
    int n_bytes_for_each_row = srcIm.step;

    src.width = srcIm.rows;
    src.height = srcIm.cols;

    src.stride = n_bytes_for_each_row;

    dst.width = 350;
    dst.height = 350;
    dst.stride = n_bytes_for_each_row;
    dst.pixels = new unsigned int[350*350];


    std::unique_ptr<unsigned int[]> videoFrame(new unsigned int[srcIm.rows * srcIm.cols]);

    std::transform(srcIm.begin(), srcIm.end(), videoFrame.get()
        , [](cv::Vec3b const& v) {
        return v[0] | (v[1] << 8) | (v[2] << 16);
    });

    vertex_t vert[4];
    vert[0].u = 0;
    vert[0].v = 0;
    vert[0].x = 0;
    vert[0].y = 0;

    vert[1].u = 50;
    vert[1].v = 0;
    vert[1].x = 350;
    vert[1].y = 0;
    //
    vert[2].u = 150;
    vert[2].v = 350;
    vert[2].x = 350;
    vert[2].y = 350;
    //
    vert[3].u = 0;
    vert[3].v = 50;
    vert[3].x = 0;
    vert[3].y = 350;

    src.pixels = videoFrame.get();
    perspective_transform(&src, &dst, vert);



    cv::Mat videoFrameMat(350, 350, CV_32S, dst.pixels);

    double min;
    double max;
    cv::minMaxIdx(videoFrameMat, &min, &max);
    cv::Mat adjMap;
    cv::convertScaleAbs(videoFrameMat, adjMap, 255 / max);
    cv::imshow("Out", adjMap);


    cv::waitKey();

推荐答案

您可以使用步骤:

int n_bytes_for_each_row = mat.step;

这篇关于如何计算cv :: Mat的步幅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 23:17