0

I want to check the details of some Mat matrices in my OpenCV Codes (within Qt). An easy way, to my knowledge, to check the data matrix is to load it in Matlab. So, I want to save these data into a file that can be loaded in Matlab. Anyone has the experience to do so? A concrete example will be greatly helpful!!

jwm
  • 4,832
  • 10
  • 46
  • 78

2 Answers2

1

OpenCV provides a straightforward example here using imwrite. And Matlab can then open the jpg files with imread.

bitbangs
  • 506
  • 3
  • 6
  • Using imwrite may not save the data as they are. Some negative values be reset to zero or larger values truncated due to the range of image type? – jwm Apr 27 '19 at 22:56
  • You can always [normalize](https://docs.opencv.org/ref/master/d2/de8/group__core__array.html#ga87eef7ee3970f86906d69a92cbf064bd) as needed. – bitbangs Apr 27 '19 at 23:00
  • But what I need is to check the original data generated during running opencv codes? Is there better way to do that? – jwm Apr 27 '19 at 23:02
  • 1
    Check [this post](https://stackoverflow.com/questions/16312904/how-to-write-a-float-mat-to-a-file-in-opencv) out. – bitbangs Apr 27 '19 at 23:03
1

The opencv Mat file can be saved to a csv file using cv::format() (writeCSV), which can be read in Matlab using csvread.m.

jwm
  • 4,832
  • 10
  • 46
  • 78