opencv - cvCvtColor中的断言失败(dst.data == dst0.data) [英] opencv - Assertion failed (dst.data == dst0.data) in cvCvtColor

查看:2019
本文介绍了opencv - cvCvtColor中的断言失败(dst.data == dst0.data)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码将发布错误消息:

The following code will post the error message:

// object is a color image with type cv::Mat

IplImage* temp_object = &(IplImage)object;
IplImage* ipl_object = cvCreateImage(cvGetSize(temp_object), 8, 3);
assert(temp_object->nChannels ==  3 && temp_object->depth == IPL_DEPTH_8U);
assert(ipl_object->nChannels ==  3 && ipl_object->depth == IPL_DEPTH_8U);
cvCvtColor(ipl_object, temp_object, CV_BGR2GRAY);

错误


OpenCV错误:cvCvtColor中的断言失败(dst.data == dst0.data),文件/ opt / local /var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_graphics_opencv/opencv/ work / OpenCV-2.3.1 / modules / imgproc / src / color.cpp,第3175行
终止称为抛出异常`

OpenCV Error: Assertion failed (dst.data == dst0.data) in cvCvtColor, file /opt/local /var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_graphics_opencv/opencv/work/OpenCV-2.3.1/modules/imgproc/src/color.cpp, line 3175 terminate called throwing an exception`

修改后的更新代码(现在应该可以使用)。感谢您的帮助!

Updated code after modification (it should work now). Thanks for the help!

IplImage temp_object (object);
IplImage* ipl_object = cvCreateImage(cvGetSize(&temp_object), 8, 1);
cvCvtColor(&temp_object, ipl_object, CV_BGR2GRAY);


推荐答案

IplImage* temp_object = &(IplImage)object;

这不会给你一个指向对象的指针,重新解释为 IplImage ;相反,它从对象创建一个临时的 IplImage ,给你一个指针,然后销毁临时的,离开 temp_object 指向无效。之后使用 temp_object 会给出未定义的行为。

That doesn't give you a pointer to object, reinterpreted as IplImage; instead, it creates a temporary IplImage from object, gives you a pointer to that, and then destroys the temporary, leaving temp_object pointing to nothing valid. Using temp_object afterwards will give undefined behaviour.

我不熟悉这个库,但也许你想要一个指向对象的指针(如果 IplImage 对象的子类型 is):

I'm not familiar with the library, but perhaps you want a pointer to object (if IplImage is a subtype of whatever type object is):

IplImage* temp_object = static_cast<IplImage *>(&object);

使用强制转换转换指针(或引用,如果您愿意),而不是对象本身。

using a cast to convert a pointer (or a reference, if you prefer), not the object itself.

或者你想要一个新的(非临时的)对象:

Or maybe you want a new (non-temporary) object:

IplImage temp_object(object);

这篇关于opencv - cvCvtColor中的断言失败(dst.data == dst0.data)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆