전 프레임을 캡처 할 때 프레임을 캡처 할 때 CCW가 90도 회전합니다. CGContext에서 캡쳐 된 이미지를 회전시키고 싶습니다 (Core Graphic을 읽는 것이 다른 프레임 워크보다 훨씬 빠르기 때문에).CGContext의 Samplebuffer에서 캡처 한 프레임을 회전
여기 내 코드입니다 :
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
CVPixelBufferLockBaseAddress(imageBuffer!, CVPixelBufferLockFlags(rawValue: 0))
let width = CVPixelBufferGetWidthOfPlane(imageBuffer!, 0)
let height = CVPixelBufferGetHeightOfPlane(imageBuffer!, 0)
let bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer!, 0)
let lumaBuffer = CVPixelBufferGetBaseAddressOfPlane(imageBuffer!, 0)
let grayColorSpace = CGColorSpaceCreateDeviceGray()
let context = CGContext(data: lumaBuffer,
width: width,
height: height,
bitsPerComponent: 8,
bytesPerRow: bytesPerRow,
space: grayColorSpace,
bitmapInfo: CGImageAlphaInfo.none.rawValue);
let transform1 = CGAffineTransform(rotationAngle: CGFloat(M_PI_2))
context!.concatenate(transform1)
//context!.rotate(by: CGFloat(M_PI_2)) // also not working!
let dstImage = context!.makeImage()
detect(image: dstImage!)
}