Not able to create cv::MatIterator_ in visual studio 2015.
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 imagecv::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'
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 .)
No @berak flaotImg variable has image data. the same code works fine in ubuntu.
btw, it should be
begin<Vec3b>
, not float, no ?