Ask Your Question
0

write a Mat to txt file

asked 2018-01-29 09:56:19 -0600

julian403 gravatar image

Hello All.

I got a border image using Canny function. What Im trying to do is detect a movement using a high pass filter. So applying that filter the border which has a fast changes will still be present. I will read all pixel and find which its "white" (non zero)

image description

That image I got using Canny function.

For for debug it, I means to check that after apply the filter I get white pixel and I have to read that pixel and check the value I do:

    for(int y=0;y<480;y++)
{
    for(int x=0;x<680; x++)
    {
    fprintf(archivo, "%c\t", edges.at<uchar>(x,y));
    }
    fprintf(archivo, "\n");

}

But that doesnt work. Any help here?

Thanks in advance.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-01-29 10:18:27 -0600

berak gravatar image

updated 2018-01-29 12:35:52 -0600

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();
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-01-29 09:56:19 -0600

Seen: 4,809 times

Last updated: Jan 29 '18