File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
visualization/src/androidMain/kotlin/org/jetbrains/kotlinx/dl/visualization Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2022 JetBrains s.r.o. and Kotlin Deep Learning project contributors. All Rights Reserved.
3
+ * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4
+ */
5
+
6
+ package org.jetbrains.kotlinx.dl.visualization
7
+
8
+ import android.content.Context
9
+ import android.graphics.Canvas
10
+ import android.util.AttributeSet
11
+ import android.view.View
12
+
13
+ /* *
14
+ * Base class for [View] implementations which visualize detected results on top of the image preview.
15
+ * Derived classes should implement [drawDetection] method to perform actual drawing.
16
+ */
17
+ abstract class DetectorViewBase <T >(context : Context , attrs : AttributeSet ) : View(context, attrs) {
18
+ /* *
19
+ * Detection result to visualize
20
+ */
21
+ var detection: T ? = null
22
+ set(value) {
23
+ synchronized(this ) {
24
+ field = value
25
+ postInvalidate()
26
+ }
27
+ }
28
+
29
+ /* *
30
+ * Draw given detection result on the [Canvas].
31
+ */
32
+ abstract fun Canvas.drawDetection (detection : T )
33
+
34
+ override fun onDraw (canvas : Canvas ) {
35
+ super .onDraw(canvas)
36
+
37
+ synchronized(this ) {
38
+ val detection = detection
39
+ if (detection != null ) {
40
+ canvas.drawDetection(detection)
41
+ }
42
+ }
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments