iplimage 到 mat 32 位转换错误

发布于 2025-01-03 19:38:36 字数 261 浏览 0 评论 0原文

我想将 iplimage 转换为 cv::mat (不是 CvMat)。使用此代码,值主题将溢出...

IplImage mhi32f = cvCreateImage(cvSize(draw_rect.width,draw_rect.height), IPL_DEPTH_32F, 1);
cv::Mat mhi32_mat(mhi32f);
mhi32_mat.convertTo(mhi32_mat,CV_32FC1);

有什么建议吗?

I want to convert an iplimage to a cv::mat (not CvMat). With this code the values themes to be overflowed...

IplImage mhi32f = cvCreateImage(cvSize(draw_rect.width,draw_rect.height), IPL_DEPTH_32F, 1);
cv::Mat mhi32_mat(mhi32f);
mhi32_mat.convertTo(mhi32_mat,CV_32FC1);

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞎闹 2025-01-10 19:38:36

正如这里所解释的,你只需要这样做

Mat imgMat(iplimg);  //Construct an Mat image "img" out of an IplImage

as explained here, you just have to do that

Mat imgMat(iplimg);  //Construct an Mat image "img" out of an IplImage
笙痞 2025-01-10 19:38:36

首先,IplImage mhi32f = ... 应该是 IplImage* mhi32f = ...,但我认为这是您的拼写错误。

您的示例很好,只是您不需要 convertTo 调用。如果要将 IplImage 数据复制到 Mat 对象,只需将 true 作为第二个参数传递给构造函数,如下所示 这里

这是一个示例,显示类型已经是 CV_32FC1

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    IplImage* mhi32f = cvCreateImage(cvSize(320, 240), IPL_DEPTH_32F, 1);
    cv::Mat mhi32_mat(mhi32f);

    assert(mhi32_mat.type() == CV_32FC1);

    cout << "Already a CV_32FC1 matrix..." << endl;

    return 0;
}

希望有帮助。

First off, IplImage mhi32f = ... should be IplImage* mhi32f = ..., but I'll assume that was a typo on your part.

Your example is fine except that you don't need the convertTo call. If you want to copy the IplImage data to the Mat object simply pass true as the second argument to the constructor as shown here.

Here is an example showing that the type is already CV_32FC1:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    IplImage* mhi32f = cvCreateImage(cvSize(320, 240), IPL_DEPTH_32F, 1);
    cv::Mat mhi32_mat(mhi32f);

    assert(mhi32_mat.type() == CV_32FC1);

    cout << "Already a CV_32FC1 matrix..." << endl;

    return 0;
}

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文