Advertisement
Guest User

Untitled

a guest
Apr 15th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.15 KB | None | 0 0
  1. object OpenCVUtils {
  2.  
  3.   def togglify[A, B, F[_]: Applicative](f: A => B => F[B]): Boolean => A => B => F[B] = {
  4.     toggle =>
  5.       if (toggle)
  6.         f
  7.       else
  8.         a => b => b.pure[F]
  9.   }
  10.  
  11.   def colorSpace(colorSpace: => Int)(input: Mat): Future[Mat] = {
  12.     delay {
  13.       val colorTransformed = new Mat
  14.       Imgproc.cvtColor(input, colorTransformed, colorSpace)
  15.       colorTransformed
  16.     }
  17.   }
  18.  
  19.   def blur(size: Size)(input: Mat): Future[Mat] = {
  20.     delay {
  21.       val blurredMat = new Mat
  22.       Imgproc.blur(input, blurredMat, size)
  23.       blurredMat
  24.     }
  25.   }
  26.  
  27.   def chop(height: => Int, width: => Int)(input: Mat): Future[Mat] = {
  28.     delay {
  29.       new Mat(input, new Range(1, height), new Range(1, width))
  30.     }
  31.   }
  32. }
  33.  
  34. class ImageSource {
  35.  
  36.   val videoCapture: VideoCapture = new VideoCapture(0)
  37.  
  38.   def takeImage: Mat = {
  39.     val image = new Mat()
  40.     while (!videoCapture.read(image)) {}
  41.     image
  42.   }
  43.  
  44.   def sourceMat: Future[Mat] =
  45.     delay {
  46.       assert(videoCapture.isOpened)
  47.       if (videoCapture.grab) {
  48.         takeImage
  49.       } else
  50.         throw new RuntimeException("Couldn't grab image!")
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement