python - OpenCV 和 NumPy 集成的编译错误
问题描述
我正在尝试使用 ScalaPy 库将 OpenCV 矩阵加载为 NumPy 数组,但看起来它缺少将 Matrx 转换为 NumPy 数组的隐式编写器。这是示例代码:
首先我的进口:
import me.shadaj.scalapy.numpy.NumPy
import me.shadaj.scalapy.py
import org.bytedeco.opencv.global.opencv_imgcodecs.imread
import org.bytedeco.opencv.opencv_core.Mat
val np: NumPy = py.module("numpy").as[NumPy]
def loadImage(imagePath: String) = {
// 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) // Fails here as expected
}
这是我面临的错误:
[error] /home/joesan/Projects/Private/ml-projects/object-classifier/src/main/scala/com/bigelectrons/animalclassifier/ImageLoader.scala:22:7: Symbol 'type me.shadaj.scalapy.py.Writer' is missing from the classpath
[error] This symbol is required by 'value me.shadaj.scalapy.numpy.NumPy.writer'.
[error] Make sure that type Writer is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'NumPy.class' was compiled against an incompatible version of me.shadaj.scalapy.py.
[error] np.asarray(preProcessedImagesWithLabels)
[error] ^
[error] /home/joesan/Projects/Private/ml-projects/object-classifier/src/main/scala/com/bigelectrons/animalclassifier/ImageLoader.scala:22:17: could not find implicit value for parameter writer: me.shadaj.scalapy.py.Writer[org.bytedeco.opencv.opencv_core.Mat]
[error] np.asarray(preProcessedImagesWithLabels)
[error] ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 5 s, completed Nov 1, 2021 9:40:45 AM
我面临两个错误。我是否应该有一个知道如何将 Mat 转换为 NumPy 数组的隐式编写器实现?有任何想法吗?
解决方案
推荐阅读
- c# - 为什么在 C# UWP 中为一个内容保留两个变量?
- java - java函数返回多个变量-调用
- linux - rdtsc 的 VMX 性能问题(没有 rdtsc 退出,使用 rdtsc 偏移)
- python - csv python:从csv中的行生成元组列表
- html - 为什么我的 Angular 5 应用程序在使用 setTimeout()、Observable.timer 或 Observable.interval() 时会阻塞 UI?
- azure - Github 中 Azure 服务的持续集成和持续部署
- awk - 如何获得两个不同输入的一些输出(sed 和 nawk
- android - FirebaseRecycleAdapter 不显示 Firebase 数据库中的数据
- grails - 用于保存的 Grails GORM 域类关系
- qt - 如何通过 Qt 设计器在 mainLayout 中放置 QChartView?