user2822174
user2822174

Reputation: 21

How to save a Mat (OpenCV) to Array

I wrote:

 Mat sobel = new Mat();
 Imgproc.Sobel(threshold,sobel, sobel.depth(), 1, 0);
 Highgui.imwrite("Sobel.jpg", sobel); 
 sobel.create( sobel.height(),sobel.width(), CvType.CV_8UC(2));    
 System.out.println(sobel.dump());

 //display matrix

Then I tried to get an array from sobel. But I confused how to get value from Mat and put in Array.

Upvotes: 2

Views: 3418

Answers (1)

berak
berak

Reputation: 39796

image filters like canny or sobel just binarize / highlight the image.

if all you wanted was to access the pixels:

byte [] pixels = new byte[ sobel.height() * sobel.width() ];
sobel.get(0,0,pixels);

if you wanted a list of points / contours, you'd have to use http://docs.opencv.org/java/org/opencv/imgproc/Imgproc.html#findContours(org.opencv.core.Mat,%20java.util.List,%20org.opencv.core.Mat,%20int,%20int)

Upvotes: 3

Related Questions