scalacv.graphs

package scalacv.graphs

Members list

Type members

Classlikes

object Animation

Animation — a drawing that is a function of the frame number, rendered to a video.

Animation — a drawing that is a function of the frame number, rendered to a video.

The natural extension of a composable Picture: describe frame i as frame(i), and record draws every frame onto a fresh canvas and writes them out through a Recorder. Creative coding, a rendered data animation, a synthetic test clip — all fall out of the same graphics vocabulary.

// `.avi`, not `.mp4`: the default codec is MJPG, which opens only in an AVI container — see [[Codec.Mjpg]].
Animation.record("spin.avi", frames = 60, width = 320, height = 240) { i =>
 Picture.regularPolygon(Point(160, 120), sides = 5, radius = 80, rotation = i * 6)
   .strokeColor(Color.hsl(i * 6, 0.8, 0.6)).strokeWidth(3)
}

Attributes

Source
Animation.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Animation.type
final case class Bounds(minX: Double, minY: Double, maxX: Double, maxY: Double)

The axis-aligned bounding box of a Picture — what the layout combinators (Picture.beside, Picture.above) measure to place pictures next to each other.

The axis-aligned bounding box of a Picture — what the layout combinators (Picture.beside, Picture.above) measure to place pictures next to each other.

Attributes

Source
Picture.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Chart

Minimal data visualisation, built from Picture — proof that the graphics layer composes into charts, and a handy way to overlay a plot on an image (a histogram beside a detection, a signal on a frame).

Minimal data visualisation, built from Picture — proof that the graphics layer composes into charts, and a handy way to overlay a plot on an image (a histogram beside a detection, a signal on a frame).

Each returns a Picture sized to a width×height box with its origin at the top-left, so it composes and transforms like any other picture: Chart.bars(counts, 200, 80).at(Point(10, 10)) drops a chart into a corner.

Attributes

Source
Chart.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Chart.type
object Color

Attributes

Companion
class
Source
Color.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Color.type
final case class Color(red: Int, green: Int, blue: Int, alpha: Int = ...)

A colour with an alpha channel — the palette for Picture graphics.

A colour with an alpha channel — the palette for Picture graphics.

Doodle-inspired: colours are values you build and transform (.lighten, .fadeOut, .blend) rather than raw BGR triples. Stored as RGBA in [0, 255]; the renderer converts to OpenCV's BGR at the boundary, and alpha drives per-shape transparency when a picture is drawn over an image.

Attributes

Companion
object
Source
Color.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Dash

Attributes

Companion
class
Source
Picture.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Dash.type
final case class Dash(on: Int, off: Int)

A stroke dash pattern — alternating on/off run lengths in pixels. OpenCV has no dashed line, so Picture draws them by hand from this.

A stroke dash pattern — alternating on/off run lengths in pixels. OpenCV has no dashed line, so Picture draws them by hand from this.

Attributes

Companion
object
Source
Picture.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

The OpenCV image backend. Rendering consumes the input Image exactly as image.draw does; the returned Image is owned by the caller. Shape construction and geometry need no native loading.

The OpenCV image backend. Rendering consumes the input Image exactly as image.draw does; the returned Image is owned by the caller. Shape construction and geometry need no native loading.

Attributes

Source
Graphics.scala
Supertypes
class Object
trait Matchable
class Any
Self type
sealed trait Picture

An immutable, composable 2D drawing — the graphics layer, inspired by Doodle and adapted to image space.

An immutable, composable 2D drawing — the graphics layer, inspired by Doodle and adapted to image space.

A Picture is a value: build primitives, style them, compose them, and only then render onto an image. Because it composes, the same vocabulary annotates a detection, draws a chart, or makes generative art.

import scalacv.*
import scalacv.graphs.*
OpenCv.load()

// A dashed green box with a label — an overlay for a detected face:
val overlay =
 Picture.rectangle(face.box).strokeColor(Color.Green).strokeWidth(2).dashed
   .on(Picture.text("face", Point(face.box.x, face.box.y - 6)).strokeColor(Color.Green))

image.draw(overlay) // draw it on

Coordinates are image pixels (origin top-left, y down). Styling is contextual: a style set on a group is the default its members inherit unless they set their own. Alpha in a Color gives real transparency when drawn over an image.

Attributes

Companion
object
Source
Picture.scala
Supertypes
class Object
trait Matchable
class Any
object Picture

Attributes

Companion
trait
Source
Picture.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Picture.type
final class PictureLayout(val textMeasurer: TextMeasurer)

Geometry and layout with explicitly chosen text metrics. Shape-only measurement never calls the measurer; text remains axis-aligned at its transformed anchor. Bounds describe geometry, not ink.

Geometry and layout with explicitly chosen text metrics. Shape-only measurement never calls the measurer; text remains axis-aligned at its transformed anchor. Bounds describe geometry, not ink.

Attributes

Companion
object
Source
PictureLayout.scala
Supertypes
class Object
trait Matchable
class Any
object PictureLayout

Attributes

Companion
class
Source
PictureLayout.scala
Supertypes
class Object
trait Matchable
class Any
Self type
final case class PictureStyle(strokeColor: Option[Color] = ..., strokeWidth: Int = ..., dash: Option[Dash] = ..., fill: Option[Color] = ..., font: Font = ..., fontScale: Double = ..., antialias: Boolean = ...)

The resolved style a renderer receives. Stroke widths remain in pixels under scene transforms; only circle radii and text scales scale with the geometry.

The resolved style a renderer receives. Stroke widths remain in pixels under scene transforms; only circle radii and text scales scale with the geometry.

Attributes

Source
Picture.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Backend-neutral drawing commands in image coordinates. Transforms have already been applied; text stays axis-aligned at its transformed baseline anchor, as in the original Picture API.

Backend-neutral drawing commands in image coordinates. Transforms have already been applied; text stays axis-aligned at its transformed baseline anchor, as in the original Picture API.

Attributes

Source
Renderer.scala
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
trait Renderer

A destination-bound renderer. Implement draw for a raster, an SVG sink, or a command recorder; the library supplies scene traversal, transform composition and contextual style resolution. The implementation owns its destination's lifetime. No native type or flag is required by this contract.

A destination-bound renderer. Implement draw for a raster, an SVG sink, or a command recorder; the library supplies scene traversal, transform composition and contextual style resolution. The implementation owns its destination's lifetime. No native type or flag is required by this contract.

Attributes

Source
Renderer.scala
Supertypes
class Object
trait Matchable
class Any
object TextMeasurer

Attributes

Companion
trait
Source
PictureLayout.scala
Supertypes
class Object
trait Matchable
class Any
Self type
trait TextMeasurer

Backend-controlled text measurement. The result includes the descender baseline, as in Draw.textSize. Measurement deliberately uses the historical one-pixel glyph metrics, independently of stroke width.

Backend-controlled text measurement. The result includes the descender baseline, as in Draw.textSize. Measurement deliberately uses the historical one-pixel glyph metrics, independently of stroke width.

Attributes

Companion
object
Source
PictureLayout.scala
Supertypes
class Object
trait Matchable
class Any

Extensions

Extensions

extension (img: Image)
def draw(picture: Picture): Image

Draws a composable Picture onto the image — the high-level graphics layer (shapes, dashed strokes, text, transforms, transparency). Consumes this image and returns the annotated one.

Draws a composable Picture onto the image — the high-level graphics layer (shapes, dashed strokes, text, transforms, transparency). Consumes this image and returns the annotated one.

Attributes

Source
Graphics.scala
extension (self: Scalar)
def toColor: Color

The reverse of Color.toBgrScalar: read an OpenCV BGR Scalar into the RGBA Color palette, for handing an OpenCV colour to the Picture graphics layer. Channels are rounded and clamped to [0, 255]; the result is fully opaque (a Scalar's fourth channel is not a reliable alpha, so it is not carried over). An extension rather than a method on Scalar so the core Scalar type stays free of any dependency on this graphics-layer palette.

The reverse of Color.toBgrScalar: read an OpenCV BGR Scalar into the RGBA Color palette, for handing an OpenCV colour to the Picture graphics layer. Channels are rounded and clamped to [0, 255]; the result is fully opaque (a Scalar's fourth channel is not a reliable alpha, so it is not carried over). An extension rather than a method on Scalar so the core Scalar type stays free of any dependency on this graphics-layer palette.

Attributes

Source
Color.scala