2

I'm using this library to explore OpenCV: https://github.com/bytedeco/javacv

I'm trying to understand how I could get the shape of my Matrix. In Python, this would be something like:

import cv2
image = cv2.imread("example.png")
print(image.shape)

I do not see an equivalent function in the Mat class that would give me the shape of the loaded Matrix. Here is the Java equivalent:

val matrix: Mat = imread("data/Pixel_Artistry.jpeg")
joesan
  • 13,963
  • 27
  • 95
  • 232

2 Answers2

2

There seems to be no in-built function, but this could be just done like this:

println(s"[${matrix.rows} ${matrix.cols()} ${matrix.channels()}]")
joesan
  • 13,963
  • 27
  • 95
  • 232
0

Above does not work in general: if matrix is multi dimensional (>2) then rows and cols will be -1. Especially in those cases you would like to have something like the python 'shape'. Sorry but I'm also looking for a solution so I dont have a good answer.

guest
  • 1