2017-04-10 5 views
1

AVCaptureSession의 각 프레임을 처리하고 필터링 된 이미지를 UIImageView에서 미리 보려고합니다. 그것은 작동하지만 UIImageView의 이미지가 회전 (왜곡) 된 것처럼 보입니다. 나는 여기에서 그리고 Google에서 답변을 찾으려고 노력하고 있지만 어떤 실용적인 해결책도 찾을 수 없었다. 누구에게 무엇을 시도해 볼 생각이 있습니까? 내가 스위프트 3.0captureOutput의 오리엔테이션 문제 : didOutputSampleBuffer : from connection :

사용하고 Btw는

는, 이것은 내가 사용하고있는 코드입니다 :

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) { 

    let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) 
    let attachments = CMCopyDictionaryOfAttachments(kCFAllocatorMalloc, sampleBuffer!, kCMAttachmentMode_ShouldPropagate) 
    let coreImage = CIImage(cvImageBuffer: pixelBuffer!, options: attachments as! [String : Any]?) 
    var filteredImage = UIImage(ciImage: coreImage, scale: 1.0, orientation: UIImageOrientation.right) 

    if filter { 
     NSLog("FILTER ACTIVATED") 
     let filterType = CIFilter(name: "CISepiaTone") 
     filterType?.setValue(coreImage, forKey: kCIInputImageKey) 
     filterType?.setValue(0.5, forKey: kCIInputIntensityKey) 
     filteredImage = UIImage(ciImage: filterType!.value(forKey: kCIOutputImageKey) as! CIImage!, scale: filteredImage.scale, orientation: UIImageOrientation.right) 
    } 

    DispatchQueue.main.async() { 
     self.imageViewPreview.image = filteredImage // UIImageView 
    } 
} 

그리고 이것은 내가 미리보기에서 볼 것입니다 :

UIImageView preview

많은 미리 감사드립니다.

+0

you'r 이미지 방향'UIImageOrientation.right'는 원래 방향에 대해 'UIImageOrientation.up'이되어서는 안됩니다 ... –

+0

고마워요. 이. 나는 그것을 시도했지만 결과는 동일합니다 ... –

답변

0

발견했습니다! 그것은 그 방법에 라인 connection.videoOrientation = AVCaptureVideoOrientation.portrait을 추가해야했다. ...