Created
May 31, 2018 20:26
-
-
Save duanebester/895a7c11cbd4c67838a1a668324feca0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bufferedImageToMat = Flow[BufferedImage].map(bi => { | |
val mat = new Mat(bi.getHeight, bi.getWidth, CV_8UC(3)) | |
val indexer:UByteRawIndexer = mat.createIndexer() | |
for (y <- 0 until bi.getHeight()) { | |
for (x <- 0 until bi.getWidth()) { | |
val rgb = bi.getRGB(x, y) | |
indexer.put(y, x, 0, (rgb >> 0) & 0xFF) | |
indexer.put(y, x, 1, (rgb >> 8) & 0xFF) | |
indexer.put(y, x, 2, (rgb >> 16) & 0xFF) | |
} | |
} | |
indexer.release() | |
mat | |
}) | |
def matToBufferedImage = Flow[Mat].map(mat => { | |
Java2DFrameUtils.toBufferedImage(mat) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment