Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object OpenCVUtils {
- def togglify[A, B, F[_]: Applicative](f: A => B => F[B]): Boolean => A => B => F[B] = {
- toggle =>
- if (toggle)
- f
- else
- a => b => b.pure[F]
- }
- def colorSpace(colorSpace: => Int)(input: Mat): Future[Mat] = {
- delay {
- val colorTransformed = new Mat
- Imgproc.cvtColor(input, colorTransformed, colorSpace)
- colorTransformed
- }
- }
- def blur(size: Size)(input: Mat): Future[Mat] = {
- delay {
- val blurredMat = new Mat
- Imgproc.blur(input, blurredMat, size)
- blurredMat
- }
- }
- def chop(height: => Int, width: => Int)(input: Mat): Future[Mat] = {
- delay {
- new Mat(input, new Range(1, height), new Range(1, width))
- }
- }
- }
- class ImageSource {
- val videoCapture: VideoCapture = new VideoCapture(0)
- def takeImage: Mat = {
- val image = new Mat()
- while (!videoCapture.read(image)) {}
- image
- }
- def sourceMat: Future[Mat] =
- delay {
- assert(videoCapture.isOpened)
- if (videoCapture.grab) {
- takeImage
- } else
- throw new RuntimeException("Couldn't grab image!")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement