Skip to content

Instantly share code, notes, and snippets.

@katzchang katzchang/MSE.scala
Last active Aug 29, 2015

What would you like to do?
gen: mse
cat $(d)/result.txt
$(SBT) 'runMain mse.MSE $(d)'
package mse
import org.bytedeco.javacpp.helper.opencv_core.AbstractCvMat
import org.bytedeco.javacpp.opencv_core._
import org.bytedeco.javacpp.opencv_highgui._
object MSE {
def main(args: Array[String]) {
val ms =
new File(args(0))
val stream = new FileOutputStream(args(0) + "/result.txt")
val out = new PrintStream(stream)
val mses = {
p =>
for {
i1 <- load(p._1)
i2 <- load(p._2)
} yield out.println(
List(p._2.getName.substring(23,31), apply(i1, i2))
def load(file: File, flags: Int = CV_LOAD_IMAGE_COLOR): Option[CvMat] =
Option(cvLoadImageM(file.getAbsolutePath, flags))
* see
def apply(mat1: CvMat, mat2: CvMat): Double = {
val s1: CvMat = AbstractCvMat.create(mat1.rows(), mat1.cols(), mat1.depth(), mat1.nChannels())
cvAbsDiff(mat1, mat2, s1)
val s1Squared: CvMat = cvCreateMat(s1.rows(), s1.cols(), CV_32FC3)
cvMul(s1, s1, s1Squared, 1)
val scalar: CvScalar = cvSum(s1Squared)
val sse: Double = scalar.getVal(0) + scalar.getVal(1) + scalar.getVal(2)
val mse: Double = sse / (s1.channels() *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.