将 Java 中的 OpenCV Mat 转换为 Scala 中的 NumPy 数组
Convert OpenCV Mat in Java to NumPy Array in Scala
我在 Scala 中有一个示例代码库,我在其中使用 OpenCV 和 ScalaPy 进行一些图像分类。这是代码位:
def loadImage(imagePath: String): Image = {
// 0. Load the image and extract class label where a path to the image is assumed to be
// /path/to/dataset/{class}/{image}.jpg
val matrix: Mat = imread(imagePath)
val label = imagePath.split("")
// 1. Run the loaded image through the preprocessors, resulting in a feature vector
//val preProcessedImagesWithLabels = Seq(new ImageResizePreProcessor(appCfg)).map(preProcessor => (preProcessor.preProcess(matrix), label))
val preProcessedImagesWithLabels = Seq(new ImageResizePreProcessor(appCfg)).map(preProcessor => preProcessor.preProcess(matrix))
np.asarray(preProcessedImagesWithLabels)
}
但是失败了,因为它找不到 NumPy 的隐式转换器:
[error] /home/joesan/Projects/Private/ml-projects/object-classifier/src/main/scala/com/bigelectrons/animalclassifier/ImageLoader.scala:10:34: not found: type NumPy
[error] val np = py.module("numpy").as[NumPy]
除了导入之外还有什么期望?
"me.shadaj" %% "scalapy-numpy" % "0.1.0",
"me.shadaj" %% "scalapy-core" % "0.5.0",
尝试使用最新的“开发”版本的 scalapy-numpy:0.1.0+6-14ca0424
因此更改 sbt 构建:
libraryDependencies += "me.shadaj" %% "scalapy-numpy" % "0.1.0+6-14ca0424"
我在菊石中尝试这个脚本:
import me.shadaj.scalapy.numpy.NumPy
import me.shadaj.scalapy.py
val np = py.module("numpy").as[NumPy]
似乎按预期找到了 NumPy
我在 Scala 中有一个示例代码库,我在其中使用 OpenCV 和 ScalaPy 进行一些图像分类。这是代码位:
def loadImage(imagePath: String): Image = {
// 0. Load the image and extract class label where a path to the image is assumed to be
// /path/to/dataset/{class}/{image}.jpg
val matrix: Mat = imread(imagePath)
val label = imagePath.split("")
// 1. Run the loaded image through the preprocessors, resulting in a feature vector
//val preProcessedImagesWithLabels = Seq(new ImageResizePreProcessor(appCfg)).map(preProcessor => (preProcessor.preProcess(matrix), label))
val preProcessedImagesWithLabels = Seq(new ImageResizePreProcessor(appCfg)).map(preProcessor => preProcessor.preProcess(matrix))
np.asarray(preProcessedImagesWithLabels)
}
但是失败了,因为它找不到 NumPy 的隐式转换器:
[error] /home/joesan/Projects/Private/ml-projects/object-classifier/src/main/scala/com/bigelectrons/animalclassifier/ImageLoader.scala:10:34: not found: type NumPy
[error] val np = py.module("numpy").as[NumPy]
除了导入之外还有什么期望?
"me.shadaj" %% "scalapy-numpy" % "0.1.0",
"me.shadaj" %% "scalapy-core" % "0.5.0",
尝试使用最新的“开发”版本的 scalapy-numpy:0.1.0+6-14ca0424
因此更改 sbt 构建:
libraryDependencies += "me.shadaj" %% "scalapy-numpy" % "0.1.0+6-14ca0424"
我在菊石中尝试这个脚本:
import me.shadaj.scalapy.numpy.NumPy
import me.shadaj.scalapy.py
val np = py.module("numpy").as[NumPy]
似乎按预期找到了 NumPy