Draw a rectangle on an image with javacv in Scala

The following will draw a high contrast black/white box on an Tmage. this helps where the image may have large black/white spots, and doesn’t rely on color to show a region, to make it easier on colorblind people.

import org.bytedeco.javacpp.opencv_imgcodecs._
import org.bytedeco.javacpp.opencv_core._
import org.bytedeco.javacpp.opencv_imgproc._
 
    val image = imread("example.jpg")
    val pt1 = new Point(10, 10)
    val pt2 = new Point(400, 100)
    val white = new Scalar(255, 255, 255, 0)
    val black = new Scalar(0, 0, 0, 0)
    rectangle(image, pt1, pt2, black, 20, LINE_8, 0)
    rectangle(image, pt1, pt2, white, 3, LINE_8, 0)

Leave a Reply

Your email address will not be published. Required fields are marked *