c++ - Bad pointers by blurring Mat from std::vector<int>: cv::Exception -
i new opencv , have experimented several hours without success hope can give me advice. trying detect circle centers in images described here: https://solarianprogrammer.com/2015/05/08/detect-red-circles-image-using-opencv/
i using c++ in visual studio 10 on windows xp , opencv 2.2.0.
my images come in std::shared_ptr<cimg<double>>
format showing black dots on white background. convert them std::vector<int> vecimagepx
of length 65536 (256 rows/columns) data values between 0 , 255. have verified ok.
next, convert vector mat, done correctly. know looking @ jpg-file, pointers datastart , dataend , data not shown bad pointers according visual studio 2010 seem have valid adresses. also, mat not empty:
//[...] #include <opencv2\opencv.hpp> #include <opencv2\highgui\highgui.hpp> #include <opencv2\core\core.hpp> //[...] using namespace cv; [...] mat tmpimage= mat(vecimagepx, false).reshape(1, 256); imwrite( "image_0.jpg", tmpimage ); // works fine bool emptyimg=tmpimage.empty(); // returns "false"
as soon, apply filter or threshold, errors:
medianblur(tmpimage, tmpimage, 3); // give error threshold(tmpimage, tmpimage, 128, 255, thresh_binary); // give error
error message: unhandled exception @ 0x7c812fd3 in modulatedimaging.exe: microsoft c++ exception: cv::exception @ memory location 0x0011bc14.. additionally, pointers data, dataend etc. 0.0000 <bad ptr.>
according visual studio.
however, creating mat random values, using same methods, works pretty fine. nevertheless, assigning tmpimage
r2
gives same error described above:
mat r2 = mat(256, 256, cv_8uc1); randu(r2, scalar::all(0), scalar::all(255)); medianblur(r2, r2, 3); // works fine threshold(r2, r2, 128, 255, thresh_binary); // works fine mat tmpimage= mat(vecimagepx, false).reshape(1, 256); // works fine imwrite( "image_0.jpg", tmpimage ); // works fine r2=tmpimage; // works fine medianblur(r2, r2, 3); // gives error threshold(r2, r2, 128, 255, thresh_binary); // gives error
i have e.g. tried following conversion std::vector<int>
mat
, there jpg.-image results in wrong stripes , filters not work well:
cv::mat tmpimage(256,256,cv_8uc1,&vecimagepx.front()); // results in wrong stripes
what can avoid error messages?
in meantime, found solution: data type of mat tmpimage
not correct using described filters! using int type=tmpimage.type();
, table below found out type of tmpimage mat
cv_8uc3. however, type of r2
cv_8u1.
converting data type of tmpimage
cv_8u1 using tmpimage.convertto(tmpimage,cv_8uc1);
solved problems!
this table used assign type integer data type:
*+--------+----+----+----+----+------+------+------+------+ | | c1 | c2 | c3 | c4 | c(5) | c(6) | c(7) | c(8) | +--------+----+----+----+----+------+------+------+------+ | cv_8u | 0 | 8 | 16 | 24 | 32 | 40 | 48 | 56 | | cv_8s | 1 | 9 | 17 | 25 | 33 | 41 | 49 | 57 | | cv_16u | 2 | 10 | 18 | 26 | 34 | 42 | 50 | 58 | | cv_16s | 3 | 11 | 19 | 27 | 35 | 43 | 51 | 59 | | cv_32s | 4 | 12 | 20 | 28 | 36 | 44 | 52 | 60 | | cv_32f | 5 | 13 | 21 | 29 | 37 | 45 | 53 | 61 | | cv_64f | 6 | 14 | 22 | 30 | 38 | 46 | 54 | 62 | +--------+----+----+----+----+------+------+------+------+
Comments
Post a Comment