Repository: pablosproject/iPhone-OCR-Tesseract-and-OpenCV Branch: master Commit: 99bc1aee4098 Files: 24 Total size: 67.9 KB Directory structure: gitextract_j44k4z48/ ├── .gitignore ├── Podfile ├── README.md ├── TestOCR.xcodeproj/ │ └── project.pbxproj └── infojobOCR/ ├── AppDelegate.h ├── AppDelegate.m ├── ImageProcessingImplementation.h ├── ImageProcessingImplementation.mm ├── ImageProcessingProtocol.h ├── ImageProcessor.cpp ├── ImageProcessor.h ├── TestOCR-Info.plist ├── TestOCR-Prefix.pch ├── UIImage+OpenCV.h ├── UIImage+OpenCV.mm ├── UIImage+operation.h ├── UIImage+operation.m ├── ViewController.h ├── ViewController.m ├── en.lproj/ │ ├── InfoPlist.strings │ └── MainStoryboard.storyboard ├── main.m └── tessdata/ ├── eng.traineddata └── spa.traineddata ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Xcode build/* *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 *.xcworkspace !default.xcworkspace xcuserdata profile *.moved-aside #CocoaPods Pods ================================================ FILE: Podfile ================================================ platform :ios pod 'OpenCV' pod 'Tesseract' ================================================ FILE: README.md ================================================ iPhone-OCR-Tesseract-and-OpenCV =============================== [![Join the chat at https://gitter.im/pablosproject/iPhone-OCR-Tesseract-and-OpenCV](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pablosproject/iPhone-OCR-Tesseract-and-OpenCV?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) This is a sample project created by me (@PablosPoject) and @_AJ_R for academic purpose. It use the OpenCV framework and tutorial made by BloodAxe(https://github.com/BloodAxe) and some other utilities class made by Aptogo (https://github.com/aptogo). It also uses the Tesseract OCR engine to read the text processed with openCV. I also build a simple user interface that permit to take a photo or choose one from library, and also permit to apply to the image every single step in the image processing, or to apply directly all the processing. I hope that these can be useful for someone! Enjoy! #Usage Download the project and use [CocoaPods](http://cocoapods.org/) to install required libraries, by running `pod install`. Contact Me =============================== pablosproject@gmail.com @PablosProject Release under GPL [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/pablosproject/iphone-ocr-tesseract-and-opencv/trend.png)](https://bitdeli.com/free "Bitdeli Badge") ================================================ FILE: TestOCR.xcodeproj/project.pbxproj ================================================ // !$*UTF8*$! { archiveVersion = 1; classes = { }; objectVersion = 46; objects = { /* Begin PBXBuildFile section */ 0C4F6D0829C540F3B7E86E23 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6442C35B3A894F23BF9DB1A8 /* libPods.a */; }; 0E0ECC151583681400116FAE /* UIImage+operation.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E0ECC141583681400116FAE /* UIImage+operation.m */; }; 0E20426B15824F34009D88F2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E20426A15824F34009D88F2 /* UIKit.framework */; }; 0E20426D15824F34009D88F2 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E20426C15824F34009D88F2 /* Foundation.framework */; }; 0E20426F15824F34009D88F2 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E20426E15824F34009D88F2 /* CoreGraphics.framework */; }; 0E20427515824F35009D88F2 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0E20427315824F35009D88F2 /* InfoPlist.strings */; }; 0E20427715824F35009D88F2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E20427615824F35009D88F2 /* main.m */; }; 0E20427B15824F35009D88F2 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E20427A15824F35009D88F2 /* AppDelegate.m */; }; 0E20427E15824F35009D88F2 /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E20427C15824F35009D88F2 /* MainStoryboard.storyboard */; }; 0E20428115824F35009D88F2 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E20428015824F35009D88F2 /* ViewController.m */; }; 0E20429015824FF5009D88F2 /* ImageProcessingImplementation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0E20428D15824FF5009D88F2 /* ImageProcessingImplementation.mm */; }; 0E20429115824FF5009D88F2 /* ImageProcessor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0E20428E15824FF5009D88F2 /* ImageProcessor.cpp */; }; 0E20429815825303009D88F2 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E20429715825303009D88F2 /* AVFoundation.framework */; }; 0E20429A15825308009D88F2 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E20429915825308009D88F2 /* ImageIO.framework */; }; 0E20429C15825316009D88F2 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E20429B15825316009D88F2 /* libz.dylib */; }; 0E20429E1582531F009D88F2 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E20429D1582531F009D88F2 /* CoreVideo.framework */; }; 0E2042A015825324009D88F2 /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E20429F15825324009D88F2 /* CoreMedia.framework */; }; 0E2042A715825613009D88F2 /* UIImage+OpenCV.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0E2042A615825612009D88F2 /* UIImage+OpenCV.mm */; }; 0E74049215825A5E006AE2B4 /* tessdata in Resources */ = {isa = PBXBuildFile; fileRef = 0E74049115825A5E006AE2B4 /* tessdata */; }; 482C9DB517B138770080E8D8 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 482C9DB417B138770080E8D8 /* Default-568h@2x.png */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 0997D6262A934A0E9CDE4161 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; }; 0E0ECC131583681400116FAE /* UIImage+operation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+operation.h"; sourceTree = ""; }; 0E0ECC141583681400116FAE /* UIImage+operation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+operation.m"; sourceTree = ""; }; 0E20426615824F34009D88F2 /* TestOCR.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TestOCR.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0E20426A15824F34009D88F2 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 0E20426C15824F34009D88F2 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 0E20426E15824F34009D88F2 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 0E20427215824F35009D88F2 /* TestOCR-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "TestOCR-Info.plist"; sourceTree = ""; }; 0E20427415824F35009D88F2 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 0E20427615824F35009D88F2 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 0E20427815824F35009D88F2 /* TestOCR-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TestOCR-Prefix.pch"; sourceTree = ""; }; 0E20427915824F35009D88F2 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 0E20427A15824F35009D88F2 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 0E20427D15824F35009D88F2 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard.storyboard; sourceTree = ""; }; 0E20427F15824F35009D88F2 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 0E20428015824F35009D88F2 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 0E20428B15824FF5009D88F2 /* ImageProcessingProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageProcessingProtocol.h; sourceTree = ""; }; 0E20428C15824FF5009D88F2 /* ImageProcessingImplementation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageProcessingImplementation.h; sourceTree = ""; }; 0E20428D15824FF5009D88F2 /* ImageProcessingImplementation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ImageProcessingImplementation.mm; sourceTree = ""; }; 0E20428E15824FF5009D88F2 /* ImageProcessor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageProcessor.cpp; sourceTree = ""; }; 0E20428F15824FF5009D88F2 /* ImageProcessor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageProcessor.h; sourceTree = ""; }; 0E20429715825303009D88F2 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; 0E20429915825308009D88F2 /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; }; 0E20429B15825316009D88F2 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; 0E20429D1582531F009D88F2 /* CoreVideo.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreVideo.framework; path = System/Library/Frameworks/CoreVideo.framework; sourceTree = SDKROOT; }; 0E20429F15825324009D88F2 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; }; 0E2042A515825612009D88F2 /* UIImage+OpenCV.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+OpenCV.h"; sourceTree = ""; }; 0E2042A615825612009D88F2 /* UIImage+OpenCV.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "UIImage+OpenCV.mm"; sourceTree = ""; }; 0E74049115825A5E006AE2B4 /* tessdata */ = {isa = PBXFileReference; lastKnownFileType = folder; path = tessdata; sourceTree = ""; }; 482C9DB417B138770080E8D8 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; 6442C35B3A894F23BF9DB1A8 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ 0E20426315824F34009D88F2 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( 0E2042A015825324009D88F2 /* CoreMedia.framework in Frameworks */, 0E20429E1582531F009D88F2 /* CoreVideo.framework in Frameworks */, 0E20429C15825316009D88F2 /* libz.dylib in Frameworks */, 0E20429A15825308009D88F2 /* ImageIO.framework in Frameworks */, 0E20429815825303009D88F2 /* AVFoundation.framework in Frameworks */, 0E20426B15824F34009D88F2 /* UIKit.framework in Frameworks */, 0E20426D15824F34009D88F2 /* Foundation.framework in Frameworks */, 0E20426F15824F34009D88F2 /* CoreGraphics.framework in Frameworks */, 0C4F6D0829C540F3B7E86E23 /* libPods.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 0E20425B15824F34009D88F2 = { isa = PBXGroup; children = ( 482C9DB417B138770080E8D8 /* Default-568h@2x.png */, 0E20427015824F35009D88F2 /* TestOCR */, 0E20426915824F34009D88F2 /* Frameworks */, 0E20426715824F34009D88F2 /* Products */, 0997D6262A934A0E9CDE4161 /* Pods.xcconfig */, ); sourceTree = ""; }; 0E20426715824F34009D88F2 /* Products */ = { isa = PBXGroup; children = ( 0E20426615824F34009D88F2 /* TestOCR.app */, ); name = Products; sourceTree = ""; }; 0E20426915824F34009D88F2 /* Frameworks */ = { isa = PBXGroup; children = ( 0E20429F15825324009D88F2 /* CoreMedia.framework */, 0E20429D1582531F009D88F2 /* CoreVideo.framework */, 0E20429B15825316009D88F2 /* libz.dylib */, 0E20429915825308009D88F2 /* ImageIO.framework */, 0E20429715825303009D88F2 /* AVFoundation.framework */, 0E20426A15824F34009D88F2 /* UIKit.framework */, 0E20426C15824F34009D88F2 /* Foundation.framework */, 0E20426E15824F34009D88F2 /* CoreGraphics.framework */, 6442C35B3A894F23BF9DB1A8 /* libPods.a */, ); name = Frameworks; sourceTree = ""; }; 0E20427015824F35009D88F2 /* TestOCR */ = { isa = PBXGroup; children = ( 0E74049115825A5E006AE2B4 /* tessdata */, 0E20427915824F35009D88F2 /* AppDelegate.h */, 0E20427A15824F35009D88F2 /* AppDelegate.m */, 0E20427C15824F35009D88F2 /* MainStoryboard.storyboard */, 0E20427F15824F35009D88F2 /* ViewController.h */, 0E20428015824F35009D88F2 /* ViewController.m */, 0E20428B15824FF5009D88F2 /* ImageProcessingProtocol.h */, 0E20428C15824FF5009D88F2 /* ImageProcessingImplementation.h */, 0E20428D15824FF5009D88F2 /* ImageProcessingImplementation.mm */, 0E20428E15824FF5009D88F2 /* ImageProcessor.cpp */, 0E20428F15824FF5009D88F2 /* ImageProcessor.h */, 0E2042A515825612009D88F2 /* UIImage+OpenCV.h */, 0E2042A615825612009D88F2 /* UIImage+OpenCV.mm */, 0E0ECC131583681400116FAE /* UIImage+operation.h */, 0E0ECC141583681400116FAE /* UIImage+operation.m */, 0E20427115824F35009D88F2 /* Supporting Files */, ); name = TestOCR; path = infojobOCR; sourceTree = ""; }; 0E20427115824F35009D88F2 /* Supporting Files */ = { isa = PBXGroup; children = ( 0E20427215824F35009D88F2 /* TestOCR-Info.plist */, 0E20427315824F35009D88F2 /* InfoPlist.strings */, 0E20427615824F35009D88F2 /* main.m */, 0E20427815824F35009D88F2 /* TestOCR-Prefix.pch */, ); name = "Supporting Files"; sourceTree = ""; }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ 0E20426515824F34009D88F2 /* TestOCR */ = { isa = PBXNativeTarget; buildConfigurationList = 0E20428415824F35009D88F2 /* Build configuration list for PBXNativeTarget "TestOCR" */; buildPhases = ( B676B766E76B4C5F9460B0DD /* Check Pods Manifest.lock */, 0E20426215824F34009D88F2 /* Sources */, 0E20426315824F34009D88F2 /* Frameworks */, 0E20426415824F34009D88F2 /* Resources */, 5D4D7A6961374D8AB26D855E /* Copy Pods Resources */, ); buildRules = ( ); dependencies = ( ); name = TestOCR; productName = infojobOCR; productReference = 0E20426615824F34009D88F2 /* TestOCR.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 0E20425D15824F34009D88F2 /* Project object */ = { isa = PBXProject; attributes = { LastUpgradeCheck = 0430; ORGANIZATIONNAME = 26775; }; buildConfigurationList = 0E20426015824F34009D88F2 /* Build configuration list for PBXProject "TestOCR" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( en, ); mainGroup = 0E20425B15824F34009D88F2; productRefGroup = 0E20426715824F34009D88F2 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( 0E20426515824F34009D88F2 /* TestOCR */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ 0E20426415824F34009D88F2 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( 0E20427515824F35009D88F2 /* InfoPlist.strings in Resources */, 0E20427E15824F35009D88F2 /* MainStoryboard.storyboard in Resources */, 0E74049215825A5E006AE2B4 /* tessdata in Resources */, 482C9DB517B138770080E8D8 /* Default-568h@2x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ 5D4D7A6961374D8AB26D855E /* Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); name = "Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n"; }; B676B766E76B4C5F9460B0DD /* Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); name = "Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ 0E20426215824F34009D88F2 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 0E20427715824F35009D88F2 /* main.m in Sources */, 0E20427B15824F35009D88F2 /* AppDelegate.m in Sources */, 0E20428115824F35009D88F2 /* ViewController.m in Sources */, 0E20429015824FF5009D88F2 /* ImageProcessingImplementation.mm in Sources */, 0E20429115824FF5009D88F2 /* ImageProcessor.cpp in Sources */, 0E2042A715825613009D88F2 /* UIImage+OpenCV.mm in Sources */, 0E0ECC151583681400116FAE /* UIImage+operation.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ 0E20427315824F35009D88F2 /* InfoPlist.strings */ = { isa = PBXVariantGroup; children = ( 0E20427415824F35009D88F2 /* en */, ); name = InfoPlist.strings; sourceTree = ""; }; 0E20427C15824F35009D88F2 /* MainStoryboard.storyboard */ = { isa = PBXVariantGroup; children = ( 0E20427D15824F35009D88F2 /* en */, ); name = MainStoryboard.storyboard; sourceTree = ""; }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ 0E20428215824F35009D88F2 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 5.1; SDKROOT = iphoneos; }; name = Debug; }; 0E20428315824F35009D88F2 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_ENABLE_OBJC_ARC = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 5.1; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; }; name = Release; }; 0E20428515824F35009D88F2 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 0997D6262A934A0E9CDE4161 /* Pods.xcconfig */; buildSettings = { FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)\"", ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "infojobOCR/TestOCR-Prefix.pch"; INFOPLIST_FILE = "infojobOCR/TestOCR-Info.plist"; LIBRARY_SEARCH_PATHS = "$(inherited)"; PRODUCT_NAME = TestOCR; WRAPPER_EXTENSION = app; }; name = Debug; }; 0E20428615824F35009D88F2 /* Release */ = { isa = XCBuildConfiguration; baseConfigurationReference = 0997D6262A934A0E9CDE4161 /* Pods.xcconfig */; buildSettings = { FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "\"$(SRCROOT)\"", ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "infojobOCR/TestOCR-Prefix.pch"; INFOPLIST_FILE = "infojobOCR/TestOCR-Info.plist"; LIBRARY_SEARCH_PATHS = "$(inherited)"; PRODUCT_NAME = TestOCR; WRAPPER_EXTENSION = app; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ 0E20426015824F34009D88F2 /* Build configuration list for PBXProject "TestOCR" */ = { isa = XCConfigurationList; buildConfigurations = ( 0E20428215824F35009D88F2 /* Debug */, 0E20428315824F35009D88F2 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; 0E20428415824F35009D88F2 /* Build configuration list for PBXNativeTarget "TestOCR" */ = { isa = XCConfigurationList; buildConfigurations = ( 0E20428515824F35009D88F2 /* Debug */, 0E20428615824F35009D88F2 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; rootObject = 0E20425D15824F34009D88F2 /* Project object */; } ================================================ FILE: infojobOCR/AppDelegate.h ================================================ // // AppDelegate.h // infojobOCR // // Created by Paolo Tagliani on 08/06/12. // Copyright (c) 2012 26775. All rights reserved. // #import @interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; @end ================================================ FILE: infojobOCR/AppDelegate.m ================================================ // // AppDelegate.m // infojobOCR // // Created by Paolo Tagliani on 08/06/12. // Copyright (c) 2012 26775. All rights reserved. // #import "AppDelegate.h" @implementation AppDelegate @synthesize window = _window; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end ================================================ FILE: infojobOCR/ImageProcessingImplementation.h ================================================ // // ImageProcessingImplementation.h // InfojobOCR // // Created by Paolo Tagliani on 10/05/12. // Copyright (c) 2012 26775. All rights reserved. // #import #import "ImageProcessingProtocol.h" @interface ImageProcessingImplementation : NSObject - (UIImage*) processImage:(UIImage*) src; - (NSString*) OCRImage:(UIImage*)src; - (NSString*) pathToLangugeFIle; - (UIImage*) processRotation:(UIImage*)src; - (UIImage*) processHistogram:(UIImage*)src; - (UIImage*) processFilter:(UIImage*)src; - (UIImage*) processBinarize:(UIImage*)src; @end ================================================ FILE: infojobOCR/ImageProcessingImplementation.mm ================================================ // // ImageProcessingImplementation.m // InfojobOCR // // Created by Paolo Tagliani on 10/05/12. // Copyright (c) 2012 26775. All rights reserved. // #import "ImageProcessingImplementation.h" #import "ImageProcessor.h" #import "UIImage+OpenCV.h" @implementation ImageProcessingImplementation - (NSString*) pathToLangugeFIle{ // Set up the tessdata path. This is included in the application bundle // but is copied to the Documents directory on the first run. NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil; NSString *dataPath = [documentPath stringByAppendingPathComponent:@"tessdata"]; NSFileManager *fileManager = [NSFileManager defaultManager]; // If the expected store doesn't exist, copy the default store. if (![fileManager fileExistsAtPath:dataPath]) { // get the path to the app bundle (with the tessdata dir) NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; NSString *tessdataPath = [bundlePath stringByAppendingPathComponent:@"tessdata"]; if (tessdataPath) { [fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL]; } } setenv("TESSDATA_PREFIX", [[documentPath stringByAppendingString:@"/"] UTF8String], 1); return dataPath; } - (UIImage*) processImage:(UIImage*) src{ /** * PRE-PROCESSING OF THE IMAGE **/ ImageProcessor processor; UIImage * processed= [UIImage imageWithCVMat:processor.processImage([src CVGrayscaleMat], src.size.height)]; return processed; } - (NSString*) OCRImage:(UIImage*)src{ // init the tesseract engine. tesseract::TessBaseAPI *tesseract = new tesseract::TessBaseAPI(); tesseract->Init([[self pathToLangugeFIle] cStringUsingEncoding:NSUTF8StringEncoding], "eng"); //Pass the UIIMage to cvmat and pass the sequence of pixel to tesseract cv::Mat toOCR=[src CVGrayscaleMat]; NSLog(@"%d", toOCR.channels()); tesseract->SetImage((uchar*)toOCR.data, toOCR.size().width, toOCR.size().height , toOCR.channels(), toOCR.step1()); tesseract->Recognize(NULL); char* utf8Text = tesseract->GetUTF8Text(); return [NSString stringWithUTF8String:utf8Text]; } - (UIImage*) processRotation:(UIImage*)src{ ImageProcessor processor; cv::Mat source=[src CVGrayscaleMat]; processor.correctRotation(source, source, src.size.height); UIImage *rotated=[UIImage imageWithCVMat:source]; return rotated; } - (UIImage*) processHistogram:(UIImage*)src{ ImageProcessor processor; cv::Mat source=[src CVGrayscaleMat]; cv::Mat output=processor.equalize(source); UIImage *equalized=[UIImage imageWithCVMat:output]; return equalized; } - (UIImage*) processFilter:(UIImage*)src{ ImageProcessor processor; cv::Mat source=[src CVGrayscaleMat]; cv::Mat output=processor.filterMedianSmoot(source); UIImage *filtered=[UIImage imageWithCVMat:output]; return filtered; } - (UIImage*) processBinarize:(UIImage*)src{ ImageProcessor processor; cv::Mat source=[src CVGrayscaleMat]; cv::Mat output=processor.binarize(source); UIImage *binarized=[UIImage imageWithCVMat:output]; return binarized; } @end ================================================ FILE: infojobOCR/ImageProcessingProtocol.h ================================================ // // ImageProcessingProtocol.h // InfojobOCR // // Created by Paolo Tagliani on 10/05/12. // Copyright (c) 2012 26775. All rights reserved. // #import @protocol ImageProcessingProtocol - (UIImage*) processImage:(UIImage*) src; - (NSString*) OCRImage:(UIImage*)src; - (UIImage*) processRotation:(UIImage*)src; - (UIImage*) processHistogram:(UIImage*)src; - (UIImage*) processFilter:(UIImage*)src; - (UIImage*) processBinarize:(UIImage*)src; @end ================================================ FILE: infojobOCR/ImageProcessor.cpp ================================================ // // ImageProcessor.cpp // InfojobOCR // // Created by Paolo Tagliani on 06/06/12. // Copyright (c) 2012 26775. All rights reserved. // #include #include "ImageProcessor.h" cv::Mat ImageProcessor::processImage(cv::Mat source, float height){ //Rotacion if (correctRotation(source, source, height)<0) printf("Error in rotation correction"); // cv::Mat equalized=equalize(source); cv::Mat median_filtered=filterMedianSmoot(source); cv::Mat result=binarize(median_filtered); return result; } cv::Mat ImageProcessor::filterMedianSmoot(const cv::Mat &source){ cv::Mat results; cv::medianBlur(source, results, 3); return results; } cv::Mat ImageProcessor::filterGaussian(const cv::Mat&source){ cv::Mat results; cv::GaussianBlur(source, results, cvSize(3, 3), 0); return results; } cv::Mat ImageProcessor::equalize(const cv::Mat&source){ cv::Mat results; cv::equalizeHist(source, results); return results; } cv::Mat ImageProcessor::binarize(const cv::Mat&source){ cv::Mat results; int blockDim=MIN( source.size().height/4, source.size().width/4); if(blockDim % 2 != 1) blockDim++; //block has to be odd printf("%s : %d","Block dimension", blockDim); cv::adaptiveThreshold(source, results, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY,blockDim, 0); return results; } int ImageProcessor::correctRotation(cv::Mat &image, cv::Mat &output, float height) { //calcular el tamaño optimo de la imagen //Ha de ser lo suficicnetemte grande como para que de detecten bien las líneas //si tomamos de que la imagen ha de ser de 1296 de alto se calcula float prop=0; prop = height/image.cols; //std::cout< lines; cv::Mat resized(cols,rows,CV_8UC1,0); cv::Mat dst(cols,rows,CV_8UC1,255); cv::Mat original = image.clone();; cv::Mat kernel(1,2,CV_8UC1,0); cv::Mat kernel2(3,3,CV_8UC1,0); cv::Size si(0,0); // cv::Mat trans(cols, rows, CV_8UC1,0); // cv::transpose(image,trans); // cv::flip(trans,trans,1); // cv::resize(trans, resized, si, prop,prop); cv::threshold(image, image, 100, 255, CV_THRESH_BINARY); //cv::Canny(image,image,0,100); //cv::erode(image, image, kernel,cv::Point(0,1), 10); cv::morphologyEx(image, image, cv::MORPH_OPEN, kernel2, cv::Point(1,1), 15); //cv::dilate(image, image, kernel,cv::Point(0,1), 2); cv::Canny(image,image,0,100); //lineas de hough //cv::HoughLinesP(image, lines, 1, CV_PI/180, 50, 50, 10 ); cv::HoughLinesP(image, lines, 1, CV_PI/180, 80, 30, 10 ); double media=0; double ang=0; int num=0; cuadrante c[4]; for (int i =0; i < 4;i++) { c[i].media = 0; c[i].contador = 0; } for( size_t i = 0; i < lines.size(); i++ ) { cv::Vec4i l = lines[i]; cv::line( dst, cv::Point(l[0], l[1]), cv::Point(l[2], l[3]), cv::Scalar(0,0,0), 3, CV_AA); //ang =atan2(l[3]-l[1],l[0]-l[2]); ang =atan2(l[1]-l[3],l[0]-l[2]); //if (ang >= 0 && ang <=CV_PI / 2) if (ang >= 0 && ang <=CV_PI / 3) { c[0].media += ang; c[0].contador++; //}else if (ang >CV_PI/2 && ang <= CV_PI) }else if (ang >(2*CV_PI)/3 && ang <= CV_PI) { c[1].media += ang; c[1].contador++; //}else if (ang < 0 && ang > -1*CV_PI/2) }else if (ang > -1*CV_PI && ang < -2*CV_PI/3) { c[2].media += ang; c[2].contador++; }else if (ang > CV_PI/3 && ang < 0) { c[3].media += ang; c[3].contador++; } } int biggest = 0; int bi=0; double rot =0; double aux; for (int i =0; i < 4;i++) { if (c[i].contador > bi) { biggest = i; bi = c[i].contador; } //std::cout<<"El cudrante "< 3) { //std::cout<<"he rotado la image "< CFBundleDevelopmentRegion en CFBundleDisplayName ${PRODUCT_NAME} CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier com.pablosproject.${PRODUCT_NAME:rfc1034identifier} CFBundleInfoDictionaryVersion 6.0 CFBundleName ${PRODUCT_NAME} CFBundlePackageType APPL CFBundleShortVersionString 1.0 CFBundleSignature ???? CFBundleVersion 1.0 LSRequiresIPhoneOS UIMainStoryboardFile MainStoryboard UIRequiredDeviceCapabilities armv7 UISupportedInterfaceOrientations UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight ================================================ FILE: infojobOCR/TestOCR-Prefix.pch ================================================ // // Prefix header for all source files of the 'infojobOCR' target in the 'infojobOCR' project // #import #ifndef __IPHONE_5_0 #warning "This project uses features only available in iOS SDK 5.0 and later." #endif #ifdef __cplusplus #import #include "baseapi.h" #endif #ifdef __OBJC__ #import #import #endif ================================================ FILE: infojobOCR/UIImage+OpenCV.h ================================================ // // UIImage+OpenCV.h // OpenCVClient // // Created by Robin Summerhill on 02/09/2011. // Copyright 2011 Aptogo Limited. All rights reserved. // // Permission is given to use this source code file without charge in any // project, commercial or otherwise, entirely at your risk, with the condition // that any redistribution (in part or whole) of source code must retain // this copyright and permission notice. Attribution in compiled projects is // appreciated but not required. // #import @interface UIImage (UIImage_OpenCV) +(UIImage *)imageWithCVMat:(const cv::Mat&)cvMat; -(id)initWithCVMat:(const cv::Mat&)cvMat; @property(nonatomic, readonly) cv::Mat CVMat; @property(nonatomic, readonly) cv::Mat CVGrayscaleMat; @end ================================================ FILE: infojobOCR/UIImage+OpenCV.mm ================================================ // // UIImage+OpenCV.mm // OpenCVClient // // Created by Robin Summerhill on 02/09/2011. // Copyright 2011 Aptogo Limited. All rights reserved. // // Permission is given to use this source code file without charge in any // project, commercial or otherwise, entirely at your risk, with the condition // that any redistribution (in part or whole) of source code must retain // this copyright and permission notice. Attribution in compiled projects is // appreciated but not required. // #import "UIImage+OpenCV.h" static void ProviderReleaseDataNOP(void *info, const void *data, size_t size) { // Do not release memory return; } @implementation UIImage (UIImage_OpenCV) -(cv::Mat)CVMat { CGColorSpaceRef colorSpace = CGImageGetColorSpace(self.CGImage); CGFloat cols = self.size.width; CGFloat rows = self.size.height; cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to backing data cols, // Width of bitmap rows, // Height of bitmap 8, // Bits per component cvMat.step[0], // Bytes per row colorSpace, // Colorspace kCGImageAlphaNoneSkipLast | kCGBitmapByteOrderDefault); // Bitmap info flags CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), self.CGImage); CGContextRelease(contextRef); return cvMat; } -(cv::Mat)CVGrayscaleMat { CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); CGFloat cols = self.size.width; CGFloat rows = self.size.height; cv::Mat cvMat = cv::Mat(rows, cols, CV_8UC1); // 8 bits per component, 1 channel CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to backing data cols, // Width of bitmap rows, // Height of bitmap 8, // Bits per component cvMat.step[0], // Bytes per row colorSpace, // Colorspace kCGImageAlphaNone | kCGBitmapByteOrderDefault); // Bitmap info flags CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), self.CGImage); CGContextRelease(contextRef); CGColorSpaceRelease(colorSpace); return cvMat; } + (UIImage *)imageWithCVMat:(const cv::Mat&)cvMat { return [[UIImage alloc] initWithCVMat:cvMat]; } - (id)initWithCVMat:(const cv::Mat&)cvMat { NSData *data = [NSData dataWithBytes:cvMat.data length:cvMat.elemSize() * cvMat.total()]; CGColorSpaceRef colorSpace; if (cvMat.elemSize() == 1) { colorSpace = CGColorSpaceCreateDeviceGray(); } else { colorSpace = CGColorSpaceCreateDeviceRGB(); } CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge_retained CFDataRef)data); CGImageRef imageRef = CGImageCreate(cvMat.cols, // Width cvMat.rows, // Height 8, // Bits per component 8 * cvMat.elemSize(), // Bits per pixel cvMat.step[0], // Bytes per row colorSpace, // Colorspace kCGImageAlphaNone | kCGBitmapByteOrderDefault, // Bitmap info flags provider, // CGDataProviderRef NULL, // Decode false, // Should interpolate kCGRenderingIntentDefault); // Intent self = [self initWithCGImage:imageRef]; CGImageRelease(imageRef); CGDataProviderRelease(provider); CGColorSpaceRelease(colorSpace); return self; } @end ================================================ FILE: infojobOCR/UIImage+operation.h ================================================ // // UIImage+operation.h // infojobOCR // // Created by Paolo Tagliani on 09/06/12. // Copyright (c) 2012 26775. All rights reserved. // #import @interface UIImage (UKImage) -(UIImage*)rotate:(UIImageOrientation)orient; @end ================================================ FILE: infojobOCR/UIImage+operation.m ================================================ #include "UIImage+operation.h" static CGRect swapWidthAndHeight(CGRect rect) { CGFloat swap = rect.size.width; rect.size.width = rect.size.height; rect.size.height = swap; return rect; } @implementation UIImage (UKImage) -(UIImage*)rotate:(UIImageOrientation)orient { CGRect bnds = CGRectZero; UIImage* copy = nil; CGContextRef ctxt = nil; CGImageRef imag = self.CGImage; CGRect rect = CGRectZero; CGAffineTransform tran = CGAffineTransformIdentity; rect.size.width = CGImageGetWidth(imag); rect.size.height = CGImageGetHeight(imag); bnds = rect; switch (orient) { case UIImageOrientationUp: // would get you an exact copy of the original assert(false); return nil; case UIImageOrientationUpMirrored: tran = CGAffineTransformMakeTranslation(rect.size.width, 0.0); tran = CGAffineTransformScale(tran, -1.0, 1.0); break; case UIImageOrientationDown: tran = CGAffineTransformMakeTranslation(rect.size.width, rect.size.height); tran = CGAffineTransformRotate(tran, M_PI); break; case UIImageOrientationDownMirrored: tran = CGAffineTransformMakeTranslation(0.0, rect.size.height); tran = CGAffineTransformScale(tran, 1.0, -1.0); break; case UIImageOrientationLeft: bnds = swapWidthAndHeight(bnds); tran = CGAffineTransformMakeTranslation(0.0, rect.size.width); tran = CGAffineTransformRotate(tran, 3.0 * M_PI / 2.0); break; case UIImageOrientationLeftMirrored: bnds = swapWidthAndHeight(bnds); tran = CGAffineTransformMakeTranslation(rect.size.height, rect.size.width); tran = CGAffineTransformScale(tran, -1.0, 1.0); tran = CGAffineTransformRotate(tran, 3.0 * M_PI / 2.0); break; case UIImageOrientationRight: bnds = swapWidthAndHeight(bnds); tran = CGAffineTransformMakeTranslation(rect.size.height, 0.0); tran = CGAffineTransformRotate(tran, M_PI / 2.0); break; case UIImageOrientationRightMirrored: bnds = swapWidthAndHeight(bnds); tran = CGAffineTransformMakeScale(-1.0, 1.0); tran = CGAffineTransformRotate(tran, M_PI / 2.0); break; default: // orientation value supplied is invalid assert(false); return nil; } UIGraphicsBeginImageContext(bnds.size); ctxt = UIGraphicsGetCurrentContext(); switch (orient) { case UIImageOrientationLeft: case UIImageOrientationLeftMirrored: case UIImageOrientationRight: case UIImageOrientationRightMirrored: CGContextScaleCTM(ctxt, -1.0, 1.0); CGContextTranslateCTM(ctxt, -rect.size.height, 0.0); break; default: CGContextScaleCTM(ctxt, 1.0, -1.0); CGContextTranslateCTM(ctxt, 0.0, -rect.size.height); break; } CGContextConcatCTM(ctxt, tran); CGContextDrawImage(UIGraphicsGetCurrentContext(), rect, imag); copy = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return copy; } @end ================================================ FILE: infojobOCR/ViewController.h ================================================ // // ViewController.h // infojobOCR // // Created by Paolo Tagliani on 08/06/12. // Copyright (c) 2012 26775. All rights reserved. // #import #import "ImageProcessingProtocol.h" @interface ViewController : UIViewController{ UIImagePickerController *mediaPicker; UIImage *takenImage; UIImage *processedImage; } @property (strong, nonatomic) IBOutlet UIButton *process; @property (strong, nonatomic) IBOutlet UIImageView *resultView; @property (strong, nonatomic) id imageProcessor; @property (strong, nonatomic) IBOutlet UIButton *read; @property (strong,nonatomic) UIImage *takenImage; @property (strong,nonatomic) UIImage *processedImage; @property (strong, nonatomic) IBOutlet UIButton *rotateButton; @property (strong, nonatomic) IBOutlet UIButton *Histogrambutton; @property (strong, nonatomic) IBOutlet UIButton *FilterButton; @property (strong, nonatomic) IBOutlet UIButton *BinarizeButton; @property (strong, nonatomic) IBOutlet UIButton *originalButton; - (IBAction)TakePhoto:(id)sender; - (IBAction)Pre:(id)sender; - (IBAction)OCR:(id)sender; - (IBAction)PreRotation:(id)sender; - (IBAction)PreHistogram:(id)sender; - (IBAction)PreFilter:(id)sender; - (IBAction)PreBinarize:(id)sender; - (IBAction)returnOriginal:(id)sender; - (IBAction)ChooseMedia:(id)sender; - (UIView*)CreateOverlay; @end ================================================ FILE: infojobOCR/ViewController.m ================================================ // // ViewController.m // infojobOCR // // Created by Paolo Tagliani on 08/06/12. // Copyright (c) 2012 26775. All rights reserved. // #import "ViewController.h" #import "ImageProcessingImplementation.h" #import "UIImage+operation.h" @interface ViewController () @end @implementation ViewController @synthesize takenImage; @synthesize process; @synthesize resultView; @synthesize imageProcessor; @synthesize read; @synthesize processedImage; @synthesize rotateButton; @synthesize Histogrambutton; @synthesize FilterButton; @synthesize BinarizeButton; @synthesize originalButton; - (void)viewDidLoad { [super viewDidLoad]; imageProcessor= [[ImageProcessingImplementation alloc] init]; // Do any additional setup after loading the view, typically from a nib. } - (void)viewDidUnload { [self setResultView:nil]; [self setProcess:nil]; [self setRead:nil]; [self setRotateButton:nil]; [self setRotateButton:nil]; [self setHistogrambutton:nil]; [self setFilterButton:nil]; [self setBinarizeButton:nil]; [self setOriginalButton:nil]; [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(interfaceOrientation == UIInterfaceOrientationPortrait) return YES; else return NO; } - (IBAction)Pre:(id)sender { NSLog(@"Dimension taken image: %f x %f",takenImage.size.width, takenImage.size.height); self.processedImage=[imageProcessor processImage:[self takenImage]]; self.resultView.image=[self processedImage]; NSLog(@"Dimension processed image: %f x %f",takenImage.size.width, takenImage.size.height); } - (IBAction)OCR:(id)sender { NSString *readed=[imageProcessor OCRImage:[self processedImage]]; [[[UIAlertView alloc] initWithTitle:@"" message:[NSString stringWithFormat:@"Recognized:\n%@", readed] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil] show]; } - (IBAction)PreRotation:(id)sender { self.processedImage=[imageProcessor processRotation:[self processedImage]]; self.resultView.image=[self processedImage]; } - (IBAction)PreHistogram:(id)sender { self.processedImage=[imageProcessor processHistogram:[self processedImage]]; self.resultView.image=[self processedImage]; } - (IBAction)PreFilter:(id)sender { self.processedImage=[imageProcessor processFilter:[self processedImage]]; self.resultView.image=[self processedImage]; } - (IBAction)PreBinarize:(id)sender { self.processedImage=[imageProcessor processBinarize:[self processedImage]]; self.resultView.image=[self processedImage]; } - (IBAction)returnOriginal:(id)sender { self.processedImage=[self takenImage ]; self.resultView.image= [self takenImage]; } - (IBAction)TakePhoto:(id)sender { mediaPicker = [[UIImagePickerController alloc] init]; mediaPicker.delegate=self; mediaPicker.allowsEditing = YES; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle: @"Take a photo or choose existing, and use the control to center the announce" delegate: self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take photo", @"Choose Existing", nil]; [actionSheet showInView:self.view]; } else { mediaPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentModalViewController:mediaPicker animated:YES]; } } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if(buttonIndex != actionSheet.cancelButtonIndex) { if (buttonIndex == 0) { mediaPicker.sourceType = UIImagePickerControllerSourceTypeCamera; } else if (buttonIndex == 1) { mediaPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; } [self presentModalViewController:mediaPicker animated:YES]; } else [self dismissModalViewControllerAnimated:YES]; } - (UIView*)CreateOverlay{ UIView *overlay= [[UIView alloc] initWithFrame:CGRectMake (0, 0, self.view.frame.size.width, self.view.frame.size.height*0.10)];//width equal and height 15% overlay.backgroundColor=[UIColor blackColor]; overlay.alpha=0.5; return overlay; } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ [picker dismissModalViewControllerAnimated:YES]; //I take the coordinate of the cropping CGRect croppedRect=[[info objectForKey:UIImagePickerControllerCropRect] CGRectValue]; UIImage *original=[info objectForKey:UIImagePickerControllerOriginalImage]; UIImage *rotatedCorrectly; if (original.imageOrientation!=UIImageOrientationUp) rotatedCorrectly=[original rotate:original.imageOrientation]; else rotatedCorrectly=original; CGImageRef ref= CGImageCreateWithImageInRect(rotatedCorrectly.CGImage, croppedRect); self.takenImage= [UIImage imageWithCGImage:ref]; self.resultView.image=[self takenImage]; self.processedImage=[self takenImage ]; process.hidden=NO; BinarizeButton.hidden=NO; Histogrambutton.hidden=NO; FilterButton.hidden=NO; rotateButton.hidden=NO; self.read.hidden=NO; originalButton.hidden=NO; } @end ================================================ FILE: infojobOCR/en.lproj/InfoPlist.strings ================================================ /* Localized versions of Info.plist keys */ ================================================ FILE: infojobOCR/en.lproj/MainStoryboard.storyboard ================================================ ================================================ FILE: infojobOCR/main.m ================================================ // // main.m // infojobOCR // // Created by Paolo Tagliani on 08/06/12. // Copyright (c) 2012 26775. All rights reserved. // #import #import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } }