Skip to content

Instantly share code, notes, and snippets.

@turekj
Created March 29, 2019 18:08
Show Gist options
  • Save turekj/17775549aa39eecd003502f2a05781f6 to your computer and use it in GitHub Desktop.
Save turekj/17775549aa39eecd003502f2a05781f6 to your computer and use it in GitHub Desktop.
import org.opencv.core.Core
import org.opencv.core.Mat
import org.opencv.core.MatOfByte
import org.opencv.core.Size
import org.opencv.imgcodecs.Imgcodecs
import org.opencv.imgproc.Imgproc
import org.opencv.videoio.VideoCapture
import java.awt.Dimension
import java.awt.FlowLayout
import java.io.ByteArrayInputStream
import java.io.InputStream
import javax.imageio.ImageIO
import javax.swing.ImageIcon
import javax.swing.JFrame
import javax.swing.JLabel
fun main(args: Array<String>) {
System.load("/usr/local/Cellar/opencv/4.0.1/share/java/opencv4/libopencv_java401.dylib")
val capture = VideoCapture()
capture.open("rtsp://admin:Joannasia1993!@192.168.1.64:554")
val mat = Mat()
val label = JLabel()
val frame = JFrame()
frame.preferredSize = Dimension(1024, 768)
frame.contentPane.layout = FlowLayout()
frame.contentPane.add(label)
frame.pack()
frame.isVisible = true
while (capture.read(mat)) {
val matByte = MatOfByte()
val destination = Mat()
Imgproc.resize(mat, destination, Size(1024.0, 768.0))
Imgcodecs.imencode(".jpg", destination, matByte)
val stream = ByteArrayInputStream(matByte.toArray())
val image = ImageIO.read(stream)
label.icon = ImageIcon(image)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment