this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

initial project

xulihang 4e513ace e9eeb88b

+414
+287
OCR.xcodeproj/project.pbxproj
··· 1 + // !$*UTF8*$! 2 + { 3 + archiveVersion = 1; 4 + classes = { 5 + }; 6 + objectVersion = 55; 7 + objects = { 8 + 9 + /* Begin PBXBuildFile section */ 10 + BE023CCE296174C9001F4E9F /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE023CCD296174C9001F4E9F /* main.swift */; }; 11 + /* End PBXBuildFile section */ 12 + 13 + /* Begin PBXCopyFilesBuildPhase section */ 14 + BE023CC8296174C9001F4E9F /* CopyFiles */ = { 15 + isa = PBXCopyFilesBuildPhase; 16 + buildActionMask = 2147483647; 17 + dstPath = /usr/share/man/man1/; 18 + dstSubfolderSpec = 0; 19 + files = ( 20 + ); 21 + runOnlyForDeploymentPostprocessing = 1; 22 + }; 23 + /* End PBXCopyFilesBuildPhase section */ 24 + 25 + /* Begin PBXFileReference section */ 26 + BE023CCA296174C9001F4E9F /* OCR */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = OCR; sourceTree = BUILT_PRODUCTS_DIR; }; 27 + BE023CCD296174C9001F4E9F /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; }; 28 + /* End PBXFileReference section */ 29 + 30 + /* Begin PBXFrameworksBuildPhase section */ 31 + BE023CC7296174C9001F4E9F /* Frameworks */ = { 32 + isa = PBXFrameworksBuildPhase; 33 + buildActionMask = 2147483647; 34 + files = ( 35 + ); 36 + runOnlyForDeploymentPostprocessing = 0; 37 + }; 38 + /* End PBXFrameworksBuildPhase section */ 39 + 40 + /* Begin PBXGroup section */ 41 + BE023CC1296174C9001F4E9F = { 42 + isa = PBXGroup; 43 + children = ( 44 + BE023CCC296174C9001F4E9F /* OCR */, 45 + BE023CCB296174C9001F4E9F /* Products */, 46 + ); 47 + sourceTree = "<group>"; 48 + }; 49 + BE023CCB296174C9001F4E9F /* Products */ = { 50 + isa = PBXGroup; 51 + children = ( 52 + BE023CCA296174C9001F4E9F /* OCR */, 53 + ); 54 + name = Products; 55 + sourceTree = "<group>"; 56 + }; 57 + BE023CCC296174C9001F4E9F /* OCR */ = { 58 + isa = PBXGroup; 59 + children = ( 60 + BE023CCD296174C9001F4E9F /* main.swift */, 61 + ); 62 + path = OCR; 63 + sourceTree = "<group>"; 64 + }; 65 + /* End PBXGroup section */ 66 + 67 + /* Begin PBXNativeTarget section */ 68 + BE023CC9296174C9001F4E9F /* OCR */ = { 69 + isa = PBXNativeTarget; 70 + buildConfigurationList = BE023CD1296174C9001F4E9F /* Build configuration list for PBXNativeTarget "OCR" */; 71 + buildPhases = ( 72 + BE023CC6296174C9001F4E9F /* Sources */, 73 + BE023CC7296174C9001F4E9F /* Frameworks */, 74 + BE023CC8296174C9001F4E9F /* CopyFiles */, 75 + ); 76 + buildRules = ( 77 + ); 78 + dependencies = ( 79 + ); 80 + name = OCR; 81 + productName = OCR; 82 + productReference = BE023CCA296174C9001F4E9F /* OCR */; 83 + productType = "com.apple.product-type.tool"; 84 + }; 85 + /* End PBXNativeTarget section */ 86 + 87 + /* Begin PBXProject section */ 88 + BE023CC2296174C9001F4E9F /* Project object */ = { 89 + isa = PBXProject; 90 + attributes = { 91 + BuildIndependentTargetsInParallel = 1; 92 + LastSwiftUpdateCheck = 1310; 93 + LastUpgradeCheck = 1310; 94 + TargetAttributes = { 95 + BE023CC9296174C9001F4E9F = { 96 + CreatedOnToolsVersion = 13.1; 97 + }; 98 + }; 99 + }; 100 + buildConfigurationList = BE023CC5296174C9001F4E9F /* Build configuration list for PBXProject "OCR" */; 101 + compatibilityVersion = "Xcode 13.0"; 102 + developmentRegion = en; 103 + hasScannedForEncodings = 0; 104 + knownRegions = ( 105 + en, 106 + Base, 107 + ); 108 + mainGroup = BE023CC1296174C9001F4E9F; 109 + productRefGroup = BE023CCB296174C9001F4E9F /* Products */; 110 + projectDirPath = ""; 111 + projectRoot = ""; 112 + targets = ( 113 + BE023CC9296174C9001F4E9F /* OCR */, 114 + ); 115 + }; 116 + /* End PBXProject section */ 117 + 118 + /* Begin PBXSourcesBuildPhase section */ 119 + BE023CC6296174C9001F4E9F /* Sources */ = { 120 + isa = PBXSourcesBuildPhase; 121 + buildActionMask = 2147483647; 122 + files = ( 123 + BE023CCE296174C9001F4E9F /* main.swift in Sources */, 124 + ); 125 + runOnlyForDeploymentPostprocessing = 0; 126 + }; 127 + /* End PBXSourcesBuildPhase section */ 128 + 129 + /* Begin XCBuildConfiguration section */ 130 + BE023CCF296174C9001F4E9F /* Debug */ = { 131 + isa = XCBuildConfiguration; 132 + buildSettings = { 133 + ALWAYS_SEARCH_USER_PATHS = NO; 134 + CLANG_ANALYZER_NONNULL = YES; 135 + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 136 + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 137 + CLANG_CXX_LIBRARY = "libc++"; 138 + CLANG_ENABLE_MODULES = YES; 139 + CLANG_ENABLE_OBJC_ARC = YES; 140 + CLANG_ENABLE_OBJC_WEAK = YES; 141 + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 142 + CLANG_WARN_BOOL_CONVERSION = YES; 143 + CLANG_WARN_COMMA = YES; 144 + CLANG_WARN_CONSTANT_CONVERSION = YES; 145 + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 146 + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 147 + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 148 + CLANG_WARN_EMPTY_BODY = YES; 149 + CLANG_WARN_ENUM_CONVERSION = YES; 150 + CLANG_WARN_INFINITE_RECURSION = YES; 151 + CLANG_WARN_INT_CONVERSION = YES; 152 + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 153 + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 154 + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 155 + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 156 + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 157 + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 158 + CLANG_WARN_STRICT_PROTOTYPES = YES; 159 + CLANG_WARN_SUSPICIOUS_MOVE = YES; 160 + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 161 + CLANG_WARN_UNREACHABLE_CODE = YES; 162 + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 163 + COPY_PHASE_STRIP = NO; 164 + DEBUG_INFORMATION_FORMAT = dwarf; 165 + ENABLE_STRICT_OBJC_MSGSEND = YES; 166 + ENABLE_TESTABILITY = YES; 167 + GCC_C_LANGUAGE_STANDARD = gnu11; 168 + GCC_DYNAMIC_NO_PIC = NO; 169 + GCC_NO_COMMON_BLOCKS = YES; 170 + GCC_OPTIMIZATION_LEVEL = 0; 171 + GCC_PREPROCESSOR_DEFINITIONS = ( 172 + "DEBUG=1", 173 + "$(inherited)", 174 + ); 175 + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 176 + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 177 + GCC_WARN_UNDECLARED_SELECTOR = YES; 178 + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 179 + GCC_WARN_UNUSED_FUNCTION = YES; 180 + GCC_WARN_UNUSED_VARIABLE = YES; 181 + MACOSX_DEPLOYMENT_TARGET = 12.0; 182 + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 183 + MTL_FAST_MATH = YES; 184 + ONLY_ACTIVE_ARCH = YES; 185 + SDKROOT = macosx; 186 + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 187 + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 188 + }; 189 + name = Debug; 190 + }; 191 + BE023CD0296174C9001F4E9F /* Release */ = { 192 + isa = XCBuildConfiguration; 193 + buildSettings = { 194 + ALWAYS_SEARCH_USER_PATHS = NO; 195 + CLANG_ANALYZER_NONNULL = YES; 196 + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 197 + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 198 + CLANG_CXX_LIBRARY = "libc++"; 199 + CLANG_ENABLE_MODULES = YES; 200 + CLANG_ENABLE_OBJC_ARC = YES; 201 + CLANG_ENABLE_OBJC_WEAK = YES; 202 + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 203 + CLANG_WARN_BOOL_CONVERSION = YES; 204 + CLANG_WARN_COMMA = YES; 205 + CLANG_WARN_CONSTANT_CONVERSION = YES; 206 + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 207 + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 208 + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 209 + CLANG_WARN_EMPTY_BODY = YES; 210 + CLANG_WARN_ENUM_CONVERSION = YES; 211 + CLANG_WARN_INFINITE_RECURSION = YES; 212 + CLANG_WARN_INT_CONVERSION = YES; 213 + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 214 + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 215 + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 216 + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 217 + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 218 + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 219 + CLANG_WARN_STRICT_PROTOTYPES = YES; 220 + CLANG_WARN_SUSPICIOUS_MOVE = YES; 221 + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 222 + CLANG_WARN_UNREACHABLE_CODE = YES; 223 + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 224 + COPY_PHASE_STRIP = NO; 225 + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 226 + ENABLE_NS_ASSERTIONS = NO; 227 + ENABLE_STRICT_OBJC_MSGSEND = YES; 228 + GCC_C_LANGUAGE_STANDARD = gnu11; 229 + GCC_NO_COMMON_BLOCKS = YES; 230 + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 231 + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 232 + GCC_WARN_UNDECLARED_SELECTOR = YES; 233 + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 234 + GCC_WARN_UNUSED_FUNCTION = YES; 235 + GCC_WARN_UNUSED_VARIABLE = YES; 236 + MACOSX_DEPLOYMENT_TARGET = 12.0; 237 + MTL_ENABLE_DEBUG_INFO = NO; 238 + MTL_FAST_MATH = YES; 239 + SDKROOT = macosx; 240 + SWIFT_COMPILATION_MODE = wholemodule; 241 + SWIFT_OPTIMIZATION_LEVEL = "-O"; 242 + }; 243 + name = Release; 244 + }; 245 + BE023CD2296174C9001F4E9F /* Debug */ = { 246 + isa = XCBuildConfiguration; 247 + buildSettings = { 248 + CODE_SIGN_STYLE = Automatic; 249 + PRODUCT_NAME = "$(TARGET_NAME)"; 250 + SWIFT_VERSION = 5.0; 251 + }; 252 + name = Debug; 253 + }; 254 + BE023CD3296174C9001F4E9F /* Release */ = { 255 + isa = XCBuildConfiguration; 256 + buildSettings = { 257 + CODE_SIGN_STYLE = Automatic; 258 + PRODUCT_NAME = "$(TARGET_NAME)"; 259 + SWIFT_VERSION = 5.0; 260 + }; 261 + name = Release; 262 + }; 263 + /* End XCBuildConfiguration section */ 264 + 265 + /* Begin XCConfigurationList section */ 266 + BE023CC5296174C9001F4E9F /* Build configuration list for PBXProject "OCR" */ = { 267 + isa = XCConfigurationList; 268 + buildConfigurations = ( 269 + BE023CCF296174C9001F4E9F /* Debug */, 270 + BE023CD0296174C9001F4E9F /* Release */, 271 + ); 272 + defaultConfigurationIsVisible = 0; 273 + defaultConfigurationName = Release; 274 + }; 275 + BE023CD1296174C9001F4E9F /* Build configuration list for PBXNativeTarget "OCR" */ = { 276 + isa = XCConfigurationList; 277 + buildConfigurations = ( 278 + BE023CD2296174C9001F4E9F /* Debug */, 279 + BE023CD3296174C9001F4E9F /* Release */, 280 + ); 281 + defaultConfigurationIsVisible = 0; 282 + defaultConfigurationName = Release; 283 + }; 284 + /* End XCConfigurationList section */ 285 + }; 286 + rootObject = BE023CC2296174C9001F4E9F /* Project object */; 287 + }
+127
OCR/main.swift
··· 1 + // 2 + // main.swift 3 + // OCR 4 + // 5 + // Created by xulihang on 2023/1/1. 6 + // 7 + 8 + import Vision 9 + import Cocoa 10 + 11 + var MODE = VNRequestTextRecognitionLevel.accurate // or .fast 12 + var USE_LANG_CORRECTION = false 13 + var REVISION:Int 14 + if #available(macOS 11, *) { 15 + REVISION = VNRecognizeTextRequestRevision2 16 + } else { 17 + REVISION = VNRecognizeTextRequestRevision1 18 + } 19 + 20 + func main(args: [String]) -> Int32 { 21 + 22 + if CommandLine.arguments.count == 2 { 23 + if args[1] == "--langs" { 24 + let request = VNRecognizeTextRequest.init() 25 + request.revision = REVISION 26 + request.recognitionLevel = VNRequestTextRecognitionLevel.accurate 27 + let langs = try? request.supportedRecognitionLanguages() 28 + for lang in langs! { 29 + print(lang) 30 + } 31 + } 32 + return 0 33 + }else if CommandLine.arguments.count == 6 { 34 + let (language, fastmode, languageCorrection, src, dst) = (args[1], args[2],args[3],args[4],args[5]) 35 + let substrings = language.split(separator: ",") 36 + var languages:[String] = [] 37 + for substring in substrings { 38 + languages.append(String(substring)) 39 + } 40 + if fastmode == "true" { 41 + MODE = VNRequestTextRecognitionLevel.fast 42 + }else{ 43 + MODE = VNRequestTextRecognitionLevel.accurate 44 + } 45 + 46 + if languageCorrection == "true" { 47 + USE_LANG_CORRECTION = true 48 + }else{ 49 + USE_LANG_CORRECTION = false 50 + } 51 + 52 + guard let img = NSImage(byReferencingFile: src) else { 53 + fputs("Error: failed to load image '\(src)'\n", stderr) 54 + return 1 55 + } 56 + guard let imgRef = img.cgImage(forProposedRect: nil, context: nil, hints: nil) else { 57 + fputs("Error: failed to convert NSImage to CGImage for '\(src)'\n", stderr) 58 + return 1 59 + } 60 + 61 + 62 + let request = VNRecognizeTextRequest { (request, error) in 63 + let observations = request.results as? [VNRecognizedTextObservation] ?? [] 64 + var dict:[String:Any] = [:] 65 + var lines:[Any] = [] 66 + var allText = "" 67 + var index = 0 68 + for observation in observations { 69 + // Find the top observation. 70 + var line:[String:Any] = [:] 71 + let candidate = observation.topCandidates(1).first 72 + let string = candidate?.string 73 + // Find the bounding-box observation for the string range. 74 + let stringRange = string!.startIndex..<string!.endIndex 75 + let boxObservation = try? candidate?.boundingBox(for: stringRange) 76 + 77 + // Get the normalized CGRect value. 78 + let boundingBox = boxObservation?.boundingBox ?? .zero 79 + // Convert the rectangle from normalized coordinates to image coordinates. 80 + let rect = VNImageRectForNormalizedRect(boundingBox, 81 + Int(imgRef.width), 82 + Int(imgRef.height)) 83 + 84 + line["text"] = string ?? "" 85 + line["x"] = Int(rect.minX) 86 + line["width"] = Int(rect.size.width) 87 + line["y"] = Int(rect.minY) 88 + line["height"] = Int(rect.size.height) 89 + lines.append(line) 90 + allText = allText + (string ?? "") 91 + index = index + 1 92 + if index != observations.count { 93 + allText = allText + "\n" 94 + } 95 + } 96 + dict["lines"] = lines 97 + dict["text"] = allText 98 + let data = try? JSONSerialization.data(withJSONObject: dict, options: []) 99 + let jsonString = String(data: data!, 100 + encoding: .utf8) ?? "[]" 101 + try? jsonString.write(to: URL(fileURLWithPath: dst), atomically: true, encoding: String.Encoding.utf8) 102 + } 103 + request.recognitionLevel = MODE 104 + request.usesLanguageCorrection = USE_LANG_CORRECTION 105 + request.revision = REVISION 106 + request.recognitionLanguages = languages 107 + //request.minimumTextHeight = 0 108 + //request.customWords = [String] 109 + try? VNImageRequestHandler(cgImage: imgRef, options: [:]).perform([request]) 110 + 111 + return 0 112 + }else{ 113 + print(""" 114 + usage: 115 + language fastmode languageCorrection image_path output_path 116 + --langs: list suppported languages 117 + 118 + example: 119 + macOCR en false true ./image.jpg out.json 120 + """) 121 + return 1 122 + } 123 + } 124 + 125 + 126 + 127 + exit(main(args: CommandLine.arguments))