amymc
August 22, 2024, 12:44pm
1
I’m getting video from a regular webcam like this:
program {
val videoPlayer = VideoPlayerFFMPEG.fromDevice()
videoPlayer.play()
}
extend {
videoPlayer.draw(drawer, 0.0, 0.0, 320.0, 240.0)
}
I would like to flip the image horizontally. I see for Kinect cameras there’s a built in mirror property
kinect.depthCamera.mirror = true
Is there something similar for VideoPlayerFFMPEG
or how would you approach it?
Thanks
1 Like
kazik
August 22, 2024, 2:13pm
2
Maybe not the most optimal way, but it should work:
fun main() = application {
program {
val videoPlayer = VideoPlayerFFMPEG.fromDevice()
videoPlayer.play()
val renderTarget = renderTarget(width, height) {
colorBuffer()
}
extend {
drawer.withTarget(renderTarget) {
videoPlayer.draw(drawer)
}
drawer.isolated {
scale(-1.0, 1.0)
translate(-width.toDouble(), 0.0)
image(renderTarget.colorBuffer(0))
}
}
}
}
1 Like
amymc
August 22, 2024, 2:23pm
3
Worked like a charm. Thanks!
abe
August 22, 2024, 2:36pm
4
You can also draw it with negative width:
import org.openrndr.application
import org.openrndr.drawImage
fun main() = application {
program {
val cb = drawImage(400, 400) {
circle(0.0, 0.0, 200.0)
}
extend {
drawer.image(cb, cb.width.toDouble(), 0.0, -cb.width.toDouble(), cb.height.toDouble())
}
}
}
Or… maybe not with videoPlayer.draw
? I’ll try…
Works too (The “:0” part works on Linux for screen grabbing):
import org.openrndr.application
import org.openrndr.ffmpeg.PlayMode
import org.openrndr.ffmpeg.VideoPlayerFFMPEG
fun main() = application {
program {
val videoPlayer = VideoPlayerFFMPEG.fromScreen(":0", PlayMode.VIDEO, 30.0, 640, 480)
videoPlayer.play()
extend {
videoPlayer.draw(drawer, videoPlayer.width.toDouble(), 0.0, -videoPlayer.width.toDouble(), videoPlayer.height.toDouble())
}
}
}
Basically, draw the image where the top right corner should be and use it’s negative width as the width value. Like flipping left the right page of a book.
3 Likes