QCamera + QCameraViewfinder: how to mirror the the image displayed in the viewfinder?
-
I have a car PC, and I've written a program to display the image from the rear view camera (connected through a USB video capture card). But the image from the camera has to be mirrored, hence my question.
-
Ok good.
Did you consider QML ?
-
This post is deleted!
-
You can do some post-processing more easily with QML.
-
Okay then, would it be possible to write my own viewfinder widget that mirrors the image without actually implementing the whole viewfinder by hand myself?
I suppose it's hypothetically possible to make the viewfinder invisible,
grab()
it on timer (or render it toQPixmap
, or whatever), manipulate the image and then draw that image in another, visible widget. But I have serious doubts about performance of this solution. It must work on an Intel Atom PC, and should produce minimal CPU load, too. -
One thing you can try:
- Get the video surface format of your QCameraViewFinder
- Call
videoSurfaceProperty.setProperty("mirrored", true)
- Then set it on again.
-
Sorry, but I can't find anything related to video surface format in the
QCameraViewFinder
class. What'svideoSurfaceProperty
in your answer?
I can getQCameraViewFinderSettings
fromQCamera
, but that doesn't appear to be what you're referring to. I've looked at theQCameraViewFinderSettings
source file and there's no mention of the "mirrored" property. -
No, it's the QVideoRendererControl that you must first retrieve first.
The mirrored property I stumbled upon while checking something unrelated in QtMultimedia's sources.
-
QMediaService *mediaService = viewFinder->mediaObject()->service(); QVideoRendererControl *rendererControl = mediaService->requestControl<QVideoRendererControl *>(); rendererControl->setSurface(myVideoSurface);
Don't forget to add the necessary checks.
-
Did you set the viewFinder on the camera before calling mediaObject ?
-
What OS are you running ? It might be that the backend doesn't provide that control.
-
Windows 10.
-
how to mirror the the image displayed in the viewfinder?
+1
Actually
+1000This is a very good question!
I also want to mirror the image (flip it left to right)!PS:
I'm using Debian Testing, which requires these packages, to get QCamera working: qt5-default, libqt5multimedia5, libqt5multimedia5-plugins, libqt5multimediaquick-p5, libqt5multimediawidgets5, qml-module-qtmultimedia, qtmultimedia5-dbg, qtmultimedia5-dev -
Just a quick update:
QVideoRendererControl *rendererControl = camera.service()->requestControl<QVideoRendererControl *>(); if (rendererControl) { QAbstractVideoSurface *surface = rendererControl->surface(); QVideoSurfaceFormat format = surface->surfaceFormat(); format.setProperty("mirrored", true); surface->stop(); surface->start(format); } else { qDebug() << "Backend doesn't provide a video renderer control"; }
-
Thanks, but still no.
rendererControl
is null, and I tried executing your snippet both before and aftercamera.start()
call.