This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func drawSolidCircle(imageBuffer: CVPixelBuffer, pnt: (Int, Int), radius: Int) { | |
/* | |
Marks CVPixelBuffer with a solid green circle of radius r | |
imageBuffer: CVPixelBuffer needs to be already locked and available for write access. | |
*/ | |
CVPixelBufferLockBaseAddress(imageBuffer, .init(rawValue: 0)) | |
let width: Int = CVPixelBufferGetWidth(imageBuffer) | |
let height: Int = CVPixelBufferGetHeight(imageBuffer) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fixOrientation(uiImage: UIImage) -> UIImage{ | |
// No-op if the orientation is already correct | |
if ( uiImage.imageOrientation == UIImageOrientation.up ) { | |
return UIImage(cgImage: uiImage.cgImage!, scale: uiImage.scale, orientation: uiImage.imageOrientation) | |
} | |
// We need to calculate the proper transformation to make the image upright. | |
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored. | |
var transform: CGAffineTransform = CGAffineTransform.identity | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getImage(cvPixelBuffer: CVPixelBuffer) -> UIImage{ | |
CVPixelBufferLockBaseAddress(cvPixelBuffer, CVPixelBufferLockFlags.readOnly) | |
let colorSpace:CGColorSpace = CGColorSpaceCreateDeviceGray() | |
let bitsPerComponent = 8 // Look at the quartz 2-D programming guide(Graphic Context) | |
let targetWidth = CVPixelBufferGetWidthOfPlane(cvPixelBuffer, 0) | |
let targetHeight = CVPixelBufferGetHeightOfPlane(cvPixelBuffer, 0) | |
let bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(cvPixelBuffer, 0) | |
let baseAddress = CVPixelBufferGetBaseAddressOfPlane(cvPixelBuffer, 0) |