Skip to content

Instantly share code, notes, and snippets.

View ozgurshn's full-sized avatar

Ozgur Sahin ozgurshn

View GitHub Profile
@ozgurshn
ozgurshn / imageviewtansition.swift
Created February 26, 2020 01:25
UIimageview transition animation
//https://stackoverflow.com/questions/7638831/fade-dissolve-when-changing-uiimageviews-image/38350024#38350024
let toImage = UIImage(named:"myname.png")
UIView.transition(with: self.imageView,
duration: 0.3,
options: .transitionCrossDissolve,
animations: {
self.imageView.image = toImage
},
completion: nil)
@ozgurshn
ozgurshn / AppstoreReview.swift
Created February 11, 2020 16:47
Ask for AppStore Review
//
// AppstoreReview.swift
// Colorizer
//
// Created by ozgur on 2/11/20.
// Copyright © 2020 Den. All rights reserved.
//
import Foundation
import StoreKit
@ozgurshn
ozgurshn / videoplane.swift
Created December 16, 2019 13:25
add video as a plane node to SCNView
let videoNode = SKVideoNode(url: URL(string: "https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4")!)
videoNode.play()
// set the size (just a rough one will do)
let videoScene = SKScene(size: CGSize(width: 480, height: 360))
// center our video to the size of our video scene
videoNode.position = CGPoint(x: videoScene.size.width / 2, y: videoScene.size.height / 2)
// invert our video so it does not look upside down
videoNode.yScale = -1.0
// videoNode.xScale = -1.0
// add the video to our scene
@ozgurshn
ozgurshn / pixelbufferTransform.swift
Created December 16, 2019 12:51
Core image perspective transform on cvpixelbuffer
guard let rectangle = request?.results?.first as? VNRectangleObservation else {
guard let error = error else { return }
print("Error: Rectangle detection failed - Vision request returned an error. \(error.localizedDescription)")
return
}
guard let filter = CIFilter(name: "CIPerspectiveCorrection") else {
print("Error: Rectangle detection failed - Could not create perspective correction filter.")
return
}
let width = CGFloat(CVPixelBufferGetWidth(currentCameraImage))
@ozgurshn
ozgurshn / orientation.swift
Last active December 12, 2019 15:22
Scale and orient UIImage coming from image picker (according to apple sample)
func scaleAndOrient(image: UIImage) -> UIImage {
// Set a default value for limiting image size.
let maxResolution: CGFloat = 640
guard let cgImage = image.cgImage else {
print("UIImage has no CGImage backing it!")
return image
}
@ozgurshn
ozgurshn / FaceLandmarkProjection.swift
Created December 12, 2019 01:19
Apple Vision face landmark projection in
func getTransformedPoints(
landmark:VNFaceLandmarkRegion2D,
faceRect:CGRect,
imageSize:CGSize) -> [CGPoint]{
// last point is 0.0
return landmark.normalizedPoints.map({ (np) -> CGPoint in
return CGPoint(
x: faceRect.origin.x + np.x * faceRect.size.width,
y: imageSize.height - (np.y * faceRect.size.height + faceRect.origin.y))

Privacy Policy

built the Photo Colorizer app as a Commercial app. This SERVICE is provided by and is intended for use as is.

This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.

If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.

The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at Photo Colorizer unless otherwise defined in this Privacy Policy.

@ozgurshn
ozgurshn / highestresolutionFrontCam.swift
Created August 29, 2019 01:29
Get highest resolution from cam for vision requests.
/// - Tag: ConfigureDeviceResolution
fileprivate func highestResolution420Format(for device: AVCaptureDevice) -> (format: AVCaptureDevice.Format, resolution: CGSize)? {
var highestResolutionFormat: AVCaptureDevice.Format? = nil
var highestResolutionDimensions = CMVideoDimensions(width: 0, height: 0)
for format in device.formats {
let deviceFormat = format as AVCaptureDevice.Format
let deviceFormatDescription = deviceFormat.formatDescription
if CMFormatDescriptionGetMediaSubType(deviceFormatDescription) == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange {
@ozgurshn
ozgurshn / orientationForVision.swift
Last active August 29, 2019 01:00
Setting device orientation in vision image request handler
let exifOrientation = self.exifOrientationForCurrentDeviceOrientation()
guard let requests = self.trackingRequests, !requests.isEmpty else {
// No tracking object detected, so perform initial detection
let imageRequestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer,
orientation: exifOrientation,
options: requestHandlerOptions)
func exifOrientationForDeviceOrientation(_ deviceOrientation: UIDeviceOrientation) -> CGImagePropertyOrientation {
import NaturalLanguage
let text = "Prime Minister Boris Johnson has urged the EU to re-open the withdrawal deal reached with Theresa May, and to make key changes that would allow it to be passed by Parliament."
let tagger = NLTagger(tagSchemes: [.nameType ])
tagger.string = text
let options: NLTagger.Options = [.omitPunctuation, .omitWhitespace, .joinNames]
let tags: [NLTag] = [.personalName, .placeName, .organizationName, .adverb ,NLTag.pronoun, NLTag.determiner, NLTag.noun , NLTag.interjection ]
tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word, scheme: NLTagScheme.nameType, options: options) { tag, tokenRange in
if let tag = tag, tags.contains(tag) {
print("\(text[tokenRange]): \(tag.rawValue)")