-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDemoDetector02.kt
85 lines (74 loc) · 3.18 KB
/
DemoDetector02.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.colorBuffer
import org.openrndr.draw.isolated
import org.openrndr.ffmpeg.VideoPlayerConfiguration
import org.openrndr.ffmpeg.loadVideoDevice
import org.openrndr.shape.IntRectangle
import kotlin.math.max
fun main() = application {
configure {
width = 1000
height = 1000
}
program {
val video = loadVideoDevice()
video.play()
val detector = BlazePoseDetector.load()
val landmarks = BlazePoseLandmarks.upperBody()
val longestVideoAxis = max(video.width, video.height)
val videoImage = colorBuffer(longestVideoAxis, longestVideoAxis)
video.ended.listen {
video.restart()
}
video.newFrame.listen {
val xOffset = (longestVideoAxis - it.frame.width) / 2
val yOffset = (longestVideoAxis - it.frame.height) / 2
it.frame.copyTo(videoImage,
sourceRectangle = IntRectangle(0, 0, it.frame.width, it.frame.height),
targetRectangle = IntRectangle(xOffset, videoImage.height - yOffset, it.frame.width, -it.frame.height))
}
extend {
video.draw(drawer, blind = true)
drawer.image(videoImage)
val regions = detector.detect(videoImage)
for (region in regions) {
computeRoi(region)
drawer.fill = null
drawer.rectangle(region.rectangle.x * 640.0, region.rectangle.y * 640.0, region.rectangle.width * 640.0, region.rectangle.height * 640.0)
for ((index, key) in region.keys.withIndex()) {
if (index == 0) {
drawer.fill = ColorRGBa.PINK
}
if (index == 1) {
drawer.fill = ColorRGBa.RED
}
drawer.circle(key * 640.0, 10.0)
}
drawer.isolated {
drawer.strokeWeight = 2.0
drawer.stroke = ColorRGBa.GREEN
drawer.lineSegment(region.keys[0] * 640.0, region.keys[1] * 640.0)
}
drawer.fill = ColorRGBa.GREEN
for (coord in region.roi_coord) {
drawer.circle(coord * 640.0, 10.0)
}
drawer.lineSegment(region.roi_coord[0] * 640.0, region.roi_coord[1] * 640.0)
drawer.lineSegment(region.roi_coord[1] * 640.0, region.roi_coord[2] * 640.0)
drawer.lineSegment(region.roi_coord[2] * 640.0, region.roi_coord[3] * 640.0)
drawer.lineSegment(region.roi_coord[3] * 640.0, region.roi_coord[0] * 640.0)
val lms = landmarks.extract(drawer, region, videoImage)
val ti = region.transform
drawer.image(landmarks.landmarkImage.colorBuffer(0))
for (lm in lms) {
drawer.fill = ColorRGBa.GREEN
drawer.circle(lm.imagePosition,10.0 )
}
drawer.defaults()
drawer.translate(400.0, 0.0)
drawer.image(detector.inputImage)
}
}
}
}