Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

please try to avoid writing for-loops and per-pixel access like that. it's slow and error prone, you already got x and y wrong, and the type is most likely not uchar.

if the type of that Mat is CV_8U or CV_16U (check !) , you can simply save it as an image:

 Mat canny = ...
 imwrite("my.png", canny); // png or tif support 16bit !

 Mat c = imread("my.png", IMREAD_ANYCOLOR);

else, rather use opencv's FileStorage

 // write
 FileStorage fs("canny..yml", FileStorage::WRITE);
 fs << "canny" << canny;
 fs.release();

 // read
 FileStorage fs("canny..yml", FileStorage::READ);
 fs["canny"] >> canny;
 fs.release();

please try to avoid writing for-loops and per-pixel access like that. it's slow and error prone, you already got x and y wrong, and the type is most likely not uchar.

if the type of that Mat is CV_8U or CV_16U (check !) , you can simply save it as an image:

 Mat canny = ...
 imwrite("my.png", canny); // png or tif support 16bit !

 Mat c = imread("my.png", IMREAD_ANYCOLOR);

else, rather use opencv's FileStorage

 // write
 FileStorage fs("canny..yml", fs("canny.yml", FileStorage::WRITE);
 fs << "canny" << canny;
 fs.release();

 // read
 FileStorage fs("canny..yml", fs("canny.yml", FileStorage::READ);
 fs["canny"] >> canny;
 fs.release();