如何在Scala中调用cvLoadImage?

时间:2015-12-05 22:11:15

标签: scala javacv

我想在Scala中使用javaCV,并根据此处给出的指令编写了build.sbt https://github.com/bytedeco/javacv)。我正在尝试运行样本平滑器的Scala版本,并写了:

import org.bytedeco.javacpp.opencv_core._
import org.bytedeco.javacpp.opencv_imgproc._
import org.bytedeco.javacpp.opencv_imgcodecs._

object Face{

    def main(args: Array[String]){
       //IplImage image = cvLoadImage("test.jpg")
       //if(image == null){ 
           println("hello")
       //}
   }
}

仅导入语句不会导致任何错误。但是,当我取消注释时,由于错误我无法编译。我的代码是否正确?或者在使用我无法尊重的Java代码时有一些技巧吗?我还发现有人提到他们无法初始化课程https://github.com/bytedeco/javacpp/issues/1(这个问题应该已经修复)。

[error] /Users/developer/Desktop/scala/face/face.scala:9: value image is not a member of object org.bytedeco.javacpp.opencv_core.IplImage
[error]         IplImage image = cvLoadImage("test.jpg")
[error]                  ^
[error] /Users/developer/Desktop/scala/face/face.scala:10: not found: value image
[error]         if(image == null){ 
[error]            ^
[error] two errors found
[error] (compile:compileIncremental) Compilation failed

2 个答案:

答案 0 :(得分:4)

这是一个scala语法错误。在Scala中,使用val(对于不可变值)或var(对于可变值)声明一个值("变量"),然后是名称,然后可选的类型,所以你的行:

IplImage image = cvLoadImage("test.jpg") // Java declaration syntax

变为:

val image: IplImage = cvLoadImage("test.jpg") // full Scala syntax

或只是:

val image = cvLoadImage("test.jpg") // typically sufficient Scala syntax

答案 1 :(得分:0)

  

var element = '<div class="popup-box chat-popup" id="'+ id +'">'; element += '<div class="popup-head">'; element += '<div class="popup-head-left">'+ name +'</div>'; element += '<div class="popup-head-right"><a href="javascript:close_popup(\''+ id +'\');">&#10005;</a></div>'; element += '<div style="clear: both"></div></div><div>; class="popup-messages" id="popup-message"></div></div>';

这不是你在Scala中声明变量的方式。它应该是IplImage image = cvLoadImage("test.jpg")val image = ...