首页 > 解决方案 > OpenCV 获取矩阵的形状

问题描述

我正在使用这个库来探索 OpenCV:https ://github.com/bytedeco/javacv

我试图了解如何获得矩阵的形状。在 Python 中,这将类似于:

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

我没有在 Mat 类中看到可以为我提供加载矩阵的形状的等效函数。这是Java等价物:

val matrix: Mat = imread("data/Pixel_Artistry.jpeg")

标签: scalaopencvmatrixbytedeco-javacv

解决方案


似乎没有内置功能,但这可以像这样完成:

println(s"[${matrix.rows} ${matrix.cols()} ${matrix.channels()}]")

推荐阅读