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);
Error
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);
That doesn’t give you a pointer to
object, reinterpreted asIplImage; instead, it creates a temporaryIplImagefromobject, gives you a pointer to that, and then destroys the temporary, leavingtemp_objectpointing to nothing valid. Usingtemp_objectafterwards will give undefined behaviour.I’m not familiar with the library, but perhaps you want a pointer to
object(ifIplImageis a subtype of whatever typeobjectis):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: