10

While capturing data from Front camera I am always getting Mirror image, how can I get what I am seeing in my preview window. I have set videoMirrored to be TRUE. Following is the code snippet:

AVCaptureConnection *lConnection = nil;

  for ( AVCaptureConnection *connection in [lHandle->m_output connections]) {
     for ( AVCaptureInputPort *port in [connection inputPorts] ) {
         if ( [[port mediaType] isEqual:AVMediaTypeVideo] ) {
             lConnection = connection;
             break;
         }
     }
 }
if ([lConnection isVideoOrientationSupported])
    [lConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];
if ([lConnection isVideoMirroringSupported])
    [lConnection setVideoMirrored:TRUE];

Changing setVideoMirrored to True/False also doesn't change anything (isVideoMirroringSupported returns Success)

iAhmed
  • 6,556
  • 2
  • 25
  • 31
Rajat Kothari
  • 300
  • 1
  • 2
  • 12
  • 1
    I'm pretty sure your preview window should be showing mirrored video (in the sense of, as if you were looking into a mirror, so you raise your right arm and the arm on the right hand side of the display goes up) — when you capture data is it mirrored in that sense or is it mirrored compared to your preview window (and, hence, the right way around in terms of what comes from the sensor)? – Tommy Feb 10 '12 at 12:28
  • 1
    Thanks Tommy.Can you tell me the reason why setting SetVideoMirrored to TRUE/FALSE doesnt change any thing. – Rajat Kothari Feb 10 '12 at 13:13
  • Thanks @Tommy. Can you tell me the reason why setting SetVideoMirrored to TRUE/FALSE doesnt change any thing. – Rajat Kothari Feb 10 '12 at 13:23
  • If I could I'd have posted an answer! I assume you've checked that `supportsVideoMirroring` is definitely returning YES? – Tommy Feb 10 '12 at 14:41
  • 1
    @Tommy. Yes i Have checked isVideoMirroringSupported is returning YES, and tried to setVideoMirrored to YES/NO. but i have seen no change. – Rajat Kothari Feb 10 '12 at 14:59
  • 1
    @RajatKothari Did you finally found a solution to this problem? I'm having the same problem with front facing camera. – Sadjad Oct 30 '13 at 06:45

3 Answers3

9

Flip the mirrored image with the following code.

UIImage * flippedImage = [UIImage imageWithCGImage:picture.CGImage scale:picture.scale orientation:UIImageOrientationLeftMirrored];
Mohammed Afsul
  • 692
  • 7
  • 8
3

Swift version:

let flippedImage = UIImage(CGImage: image.CGImage, scale: image.scale, orientation: .LeftMirrored)
Fabio
  • 1,757
  • 19
  • 33
0

You can use the withHorizontallyFlippedOrientation() to flip an UIImage.

// first get an UIImage from the front camera
let sourceImg = UIImage(cgImage: image, scale: 1.0, orientation: .leftMirrored)
return sourceImg.withHorizontallyFlippedOrientation()
Wendee Hsu
  • 98
  • 6