QCamera + QCameraViewfinder: how to mirror the the image displayed in the viewfinder?
-
I need the live view image from the camera being displayed in the
QCameraViewfinderto be mirrored (flipped horizontally). What are my options for doing this? -
Please don't tell me it's not possible...
-
Hi,
I don't remember that option but that doesn't mean it doesn't exists. What is your use case ?
-
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!
-
@SGaist, no, I never used QML and don't intend to ever use it. How would that help?
-
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
QCameraViewFinderclass. What'svideoSurfacePropertyin your answer?
I can getQCameraViewFinderSettingsfromQCamera, but that doesn't appear to be what you're referring to. I've looked at theQCameraViewFinderSettingssource 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.
-
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.
-
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.
@SGaist, thanks. I, too, can't find a way to get it from
QViewFinder(which is aQVideoWidget). Looks like I needQMediaServiceto getQVideoRenderControlfrom it. -
QMediaService *mediaService = viewFinder->mediaObject()->service(); QVideoRendererControl *rendererControl = mediaService->requestControl<QVideoRendererControl *>(); rendererControl->setSurface(myVideoSurface);Don't forget to add the necessary checks.
-
QMediaService *mediaService = viewFinder->mediaObject()->service(); QVideoRendererControl *rendererControl = mediaService->requestControl<QVideoRendererControl *>(); rendererControl->setSurface(myVideoSurface);Don't forget to add the necessary checks.
@SGaist
No such luck :(viewFinder->mediaObject()isnullptr.
IS there a restriction on when I should callmediaObject()relative to, say,show()or any other lifecycle-related method of the view finder? -
Did you set the viewFinder on the camera before calling mediaObject ?
-
@SGaist
Nope, i was doing it just before that. So, now I put this code right aftersetViewfinder, andmediaServiceis not null, butmediaService->requestControl<QVideoRendererControl *>()returnsnullptr. -
What OS are you running ? It might be that the backend doesn't provide that control.
-
Windows 10.