Not able to create cv::MatIterator_ in visual studio 2015.

asked 2019-05-02 08:03:42 -0600

iamM gravatar image

updated 2019-05-02 22:49:51 -0600

I am working on a simple example using visual studio 2015 with opencv 4.1.0. i am not able to set value for iterator from cv::Mat sample code is shown below.

cv::Mat inputImg = cv::imread(argv[1]);
//convert to float image

cv::Mat flaotImg;

inputImg.convertTo(flaotImg, CV_32FC3, 2.0 / 255.0, -1.0);

cv::MatIterator_<float> it;
try { // ... Contents of your main
it = (flaotImg.begin<float>()); //Problem
} catch (cv::Exception & e) { cerr << e.msg << endl; // output exception message }

Error:

OpenCV(4.1.0) Error: Assertion failed (elemSize() == sizeof(_Tp)) in cv::Mat::begin, file c:\opencv\opencv\build\include\opencv2\core\mat.inl.hpp, line 1273 OpenCV(4.1.0) c:\opencv\opencv\build\include\opencv2\core\mat.inl.hpp:1273: error: (-215:Assertion failed) elemSize() == sizeof(_Tp) in function 'cv::Mat::begin'

image description

edit retag flag offensive close merge delete

Comments

i bet a beer, that your original Mat is empty() (it was never read) you have to check EVERY imread() call manually here.

(it should never segfault, though, imho .)

berak gravatar imageberak ( 2019-05-02 08:30:28 -0600 )edit

No @berak flaotImg variable has image data. the same code works fine in ubuntu.

iamM gravatar imageiamM ( 2019-05-02 22:20:28 -0600 )edit

btw, it should be begin<Vec3b> , not float, no ?

berak gravatar imageberak ( 2019-05-03 01:20:59 -0600 )edit