├── LICENSE ├── image-2.jpg ├── image-3.jpg ├── image.jpg ├── my_image.jpg ├── myimg-1.png ├── myimg-2.png ├── myimg-3.png ├── myimg.png ├── ovtest.xcodeproj └── project.pbxproj └── ovtest ├── auto.cpp ├── auto.h ├── bk.cpp ├── main.cpp ├── my_image.jpg ├── other.cpp ├── other.h └── test /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 avocado-yali 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /image-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vitrum/opencv-demo/1b522ffb7ca07f21ba524b957661b94047f90671/image-2.jpg -------------------------------------------------------------------------------- /image-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vitrum/opencv-demo/1b522ffb7ca07f21ba524b957661b94047f90671/image-3.jpg -------------------------------------------------------------------------------- /image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vitrum/opencv-demo/1b522ffb7ca07f21ba524b957661b94047f90671/image.jpg -------------------------------------------------------------------------------- /my_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vitrum/opencv-demo/1b522ffb7ca07f21ba524b957661b94047f90671/my_image.jpg -------------------------------------------------------------------------------- /myimg-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vitrum/opencv-demo/1b522ffb7ca07f21ba524b957661b94047f90671/myimg-1.png -------------------------------------------------------------------------------- /myimg-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vitrum/opencv-demo/1b522ffb7ca07f21ba524b957661b94047f90671/myimg-2.png -------------------------------------------------------------------------------- /myimg-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vitrum/opencv-demo/1b522ffb7ca07f21ba524b957661b94047f90671/myimg-3.png -------------------------------------------------------------------------------- /myimg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vitrum/opencv-demo/1b522ffb7ca07f21ba524b957661b94047f90671/myimg.png -------------------------------------------------------------------------------- /ovtest.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 039D50D01B5F69F7002A08C5 /* libopencv_core.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 03BB35A41B5F660D00F2A01F /* libopencv_core.2.4.11.dylib */; }; 11 | 039D50D11B5F69F7002A08C5 /* libopencv_highgui.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 03BB35A61B5F663E00F2A01F /* libopencv_highgui.2.4.11.dylib */; }; 12 | 039D50D41B5F69F7002A08C5 /* libopencv_gpu.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50D21B5F69F7002A08C5 /* libopencv_gpu.2.4.11.dylib */; }; 13 | 039D50D51B5F69F7002A08C5 /* libopencv_photo.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50D31B5F69F7002A08C5 /* libopencv_photo.2.4.11.dylib */; }; 14 | 039D50E51B5F6B2D002A08C5 /* libopencv_calib3d.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50D71B5F6B2D002A08C5 /* libopencv_calib3d.2.4.11.dylib */; }; 15 | 039D50E61B5F6B2D002A08C5 /* libopencv_contrib.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50D81B5F6B2D002A08C5 /* libopencv_contrib.2.4.11.dylib */; }; 16 | 039D50E71B5F6B2D002A08C5 /* libopencv_features2d.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50D91B5F6B2D002A08C5 /* libopencv_features2d.2.4.11.dylib */; }; 17 | 039D50E81B5F6B2D002A08C5 /* libopencv_flann.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50DA1B5F6B2D002A08C5 /* libopencv_flann.2.4.11.dylib */; }; 18 | 039D50E91B5F6B2D002A08C5 /* libopencv_imgproc.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50DB1B5F6B2D002A08C5 /* libopencv_imgproc.2.4.11.dylib */; }; 19 | 039D50EA1B5F6B2D002A08C5 /* libopencv_legacy.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50DC1B5F6B2D002A08C5 /* libopencv_legacy.2.4.11.dylib */; }; 20 | 039D50EB1B5F6B2D002A08C5 /* libopencv_ml.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50DD1B5F6B2D002A08C5 /* libopencv_ml.2.4.11.dylib */; }; 21 | 039D50EC1B5F6B2D002A08C5 /* libopencv_nonfree.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50DE1B5F6B2D002A08C5 /* libopencv_nonfree.2.4.11.dylib */; }; 22 | 039D50ED1B5F6B2D002A08C5 /* libopencv_objdetect.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50DF1B5F6B2D002A08C5 /* libopencv_objdetect.2.4.11.dylib */; }; 23 | 039D50EE1B5F6B2D002A08C5 /* libopencv_ocl.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50E01B5F6B2D002A08C5 /* libopencv_ocl.2.4.11.dylib */; }; 24 | 039D50EF1B5F6B2D002A08C5 /* libopencv_stitching.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50E11B5F6B2D002A08C5 /* libopencv_stitching.2.4.11.dylib */; }; 25 | 039D50F01B5F6B2D002A08C5 /* libopencv_superres.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50E21B5F6B2D002A08C5 /* libopencv_superres.2.4.11.dylib */; }; 26 | 039D50F11B5F6B2D002A08C5 /* libopencv_video.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50E31B5F6B2D002A08C5 /* libopencv_video.2.4.11.dylib */; }; 27 | 039D50F21B5F6B2D002A08C5 /* libopencv_videostab.2.4.11.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 039D50E41B5F6B2D002A08C5 /* libopencv_videostab.2.4.11.dylib */; }; 28 | 03B7C7051B5DE1F000A4FDA6 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 03B7C7041B5DE1F000A4FDA6 /* main.cpp */; }; 29 | /* End PBXBuildFile section */ 30 | 31 | /* Begin PBXCopyFilesBuildPhase section */ 32 | 03B7C6FF1B5DE1F000A4FDA6 /* CopyFiles */ = { 33 | isa = PBXCopyFilesBuildPhase; 34 | buildActionMask = 2147483647; 35 | dstPath = /usr/share/man/man1; 36 | dstSubfolderSpec = 0; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 1; 40 | }; 41 | /* End PBXCopyFilesBuildPhase section */ 42 | 43 | /* Begin PBXFileReference section */ 44 | 039387DC1B60801400763A00 /* auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = auto.cpp; sourceTree = ""; }; 45 | 039387DD1B60801400763A00 /* auto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = auto.h; sourceTree = ""; }; 46 | 039D50D21B5F69F7002A08C5 /* libopencv_gpu.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_gpu.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_gpu.2.4.11.dylib; sourceTree = ""; }; 47 | 039D50D31B5F69F7002A08C5 /* libopencv_photo.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_photo.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_photo.2.4.11.dylib; sourceTree = ""; }; 48 | 039D50D71B5F6B2D002A08C5 /* libopencv_calib3d.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_calib3d.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_calib3d.2.4.11.dylib; sourceTree = ""; }; 49 | 039D50D81B5F6B2D002A08C5 /* libopencv_contrib.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_contrib.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_contrib.2.4.11.dylib; sourceTree = ""; }; 50 | 039D50D91B5F6B2D002A08C5 /* libopencv_features2d.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_features2d.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_features2d.2.4.11.dylib; sourceTree = ""; }; 51 | 039D50DA1B5F6B2D002A08C5 /* libopencv_flann.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_flann.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_flann.2.4.11.dylib; sourceTree = ""; }; 52 | 039D50DB1B5F6B2D002A08C5 /* libopencv_imgproc.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_imgproc.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_imgproc.2.4.11.dylib; sourceTree = ""; }; 53 | 039D50DC1B5F6B2D002A08C5 /* libopencv_legacy.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_legacy.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_legacy.2.4.11.dylib; sourceTree = ""; }; 54 | 039D50DD1B5F6B2D002A08C5 /* libopencv_ml.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_ml.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_ml.2.4.11.dylib; sourceTree = ""; }; 55 | 039D50DE1B5F6B2D002A08C5 /* libopencv_nonfree.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_nonfree.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_nonfree.2.4.11.dylib; sourceTree = ""; }; 56 | 039D50DF1B5F6B2D002A08C5 /* libopencv_objdetect.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_objdetect.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_objdetect.2.4.11.dylib; sourceTree = ""; }; 57 | 039D50E01B5F6B2D002A08C5 /* libopencv_ocl.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_ocl.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_ocl.2.4.11.dylib; sourceTree = ""; }; 58 | 039D50E11B5F6B2D002A08C5 /* libopencv_stitching.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_stitching.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_stitching.2.4.11.dylib; sourceTree = ""; }; 59 | 039D50E21B5F6B2D002A08C5 /* libopencv_superres.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_superres.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_superres.2.4.11.dylib; sourceTree = ""; }; 60 | 039D50E31B5F6B2D002A08C5 /* libopencv_video.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_video.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_video.2.4.11.dylib; sourceTree = ""; }; 61 | 039D50E41B5F6B2D002A08C5 /* libopencv_videostab.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_videostab.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_videostab.2.4.11.dylib; sourceTree = ""; }; 62 | 039D50F31B5F6C66002A08C5 /* my_image.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = my_image.jpg; sourceTree = ""; }; 63 | 03B7C7011B5DE1F000A4FDA6 /* ovtest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ovtest; sourceTree = BUILT_PRODUCTS_DIR; }; 64 | 03B7C7041B5DE1F000A4FDA6 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 65 | 03BB35A41B5F660D00F2A01F /* libopencv_core.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_core.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_core.2.4.11.dylib; sourceTree = ""; }; 66 | 03BB35A61B5F663E00F2A01F /* libopencv_highgui.2.4.11.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libopencv_highgui.2.4.11.dylib; path = /usr/local/Cellar/opencv/2.4.11_1/lib/libopencv_highgui.2.4.11.dylib; sourceTree = ""; }; 67 | /* End PBXFileReference section */ 68 | 69 | /* Begin PBXFrameworksBuildPhase section */ 70 | 03B7C6FE1B5DE1F000A4FDA6 /* Frameworks */ = { 71 | isa = PBXFrameworksBuildPhase; 72 | buildActionMask = 2147483647; 73 | files = ( 74 | 039D50E51B5F6B2D002A08C5 /* libopencv_calib3d.2.4.11.dylib in Frameworks */, 75 | 039D50E61B5F6B2D002A08C5 /* libopencv_contrib.2.4.11.dylib in Frameworks */, 76 | 039D50E71B5F6B2D002A08C5 /* libopencv_features2d.2.4.11.dylib in Frameworks */, 77 | 039D50E81B5F6B2D002A08C5 /* libopencv_flann.2.4.11.dylib in Frameworks */, 78 | 039D50E91B5F6B2D002A08C5 /* libopencv_imgproc.2.4.11.dylib in Frameworks */, 79 | 039D50EA1B5F6B2D002A08C5 /* libopencv_legacy.2.4.11.dylib in Frameworks */, 80 | 039D50EB1B5F6B2D002A08C5 /* libopencv_ml.2.4.11.dylib in Frameworks */, 81 | 039D50EC1B5F6B2D002A08C5 /* libopencv_nonfree.2.4.11.dylib in Frameworks */, 82 | 039D50ED1B5F6B2D002A08C5 /* libopencv_objdetect.2.4.11.dylib in Frameworks */, 83 | 039D50EE1B5F6B2D002A08C5 /* libopencv_ocl.2.4.11.dylib in Frameworks */, 84 | 039D50EF1B5F6B2D002A08C5 /* libopencv_stitching.2.4.11.dylib in Frameworks */, 85 | 039D50F01B5F6B2D002A08C5 /* libopencv_superres.2.4.11.dylib in Frameworks */, 86 | 039D50F11B5F6B2D002A08C5 /* libopencv_video.2.4.11.dylib in Frameworks */, 87 | 039D50F21B5F6B2D002A08C5 /* libopencv_videostab.2.4.11.dylib in Frameworks */, 88 | 039D50D41B5F69F7002A08C5 /* libopencv_gpu.2.4.11.dylib in Frameworks */, 89 | 039D50D11B5F69F7002A08C5 /* libopencv_highgui.2.4.11.dylib in Frameworks */, 90 | 039D50D51B5F69F7002A08C5 /* libopencv_photo.2.4.11.dylib in Frameworks */, 91 | 039D50D01B5F69F7002A08C5 /* libopencv_core.2.4.11.dylib in Frameworks */, 92 | ); 93 | runOnlyForDeploymentPostprocessing = 0; 94 | }; 95 | /* End PBXFrameworksBuildPhase section */ 96 | 97 | /* Begin PBXGroup section */ 98 | 039D50D61B5F6A68002A08C5 /* opencv */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 039D50D71B5F6B2D002A08C5 /* libopencv_calib3d.2.4.11.dylib */, 102 | 039D50D81B5F6B2D002A08C5 /* libopencv_contrib.2.4.11.dylib */, 103 | 039D50D91B5F6B2D002A08C5 /* libopencv_features2d.2.4.11.dylib */, 104 | 039D50DA1B5F6B2D002A08C5 /* libopencv_flann.2.4.11.dylib */, 105 | 039D50DB1B5F6B2D002A08C5 /* libopencv_imgproc.2.4.11.dylib */, 106 | 039D50DC1B5F6B2D002A08C5 /* libopencv_legacy.2.4.11.dylib */, 107 | 039D50DD1B5F6B2D002A08C5 /* libopencv_ml.2.4.11.dylib */, 108 | 039D50DE1B5F6B2D002A08C5 /* libopencv_nonfree.2.4.11.dylib */, 109 | 039D50DF1B5F6B2D002A08C5 /* libopencv_objdetect.2.4.11.dylib */, 110 | 039D50E01B5F6B2D002A08C5 /* libopencv_ocl.2.4.11.dylib */, 111 | 039D50E11B5F6B2D002A08C5 /* libopencv_stitching.2.4.11.dylib */, 112 | 039D50E21B5F6B2D002A08C5 /* libopencv_superres.2.4.11.dylib */, 113 | 039D50E31B5F6B2D002A08C5 /* libopencv_video.2.4.11.dylib */, 114 | 039D50E41B5F6B2D002A08C5 /* libopencv_videostab.2.4.11.dylib */, 115 | 039D50D21B5F69F7002A08C5 /* libopencv_gpu.2.4.11.dylib */, 116 | 039D50D31B5F69F7002A08C5 /* libopencv_photo.2.4.11.dylib */, 117 | 03BB35A61B5F663E00F2A01F /* libopencv_highgui.2.4.11.dylib */, 118 | 03BB35A41B5F660D00F2A01F /* libopencv_core.2.4.11.dylib */, 119 | ); 120 | name = opencv; 121 | sourceTree = ""; 122 | }; 123 | 03B7C6F81B5DE1F000A4FDA6 = { 124 | isa = PBXGroup; 125 | children = ( 126 | 039D50D61B5F6A68002A08C5 /* opencv */, 127 | 03B7C7031B5DE1F000A4FDA6 /* ovtest */, 128 | 03B7C7021B5DE1F000A4FDA6 /* Products */, 129 | ); 130 | sourceTree = ""; 131 | }; 132 | 03B7C7021B5DE1F000A4FDA6 /* Products */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | 03B7C7011B5DE1F000A4FDA6 /* ovtest */, 136 | ); 137 | name = Products; 138 | sourceTree = ""; 139 | }; 140 | 03B7C7031B5DE1F000A4FDA6 /* ovtest */ = { 141 | isa = PBXGroup; 142 | children = ( 143 | 03B7C7041B5DE1F000A4FDA6 /* main.cpp */, 144 | 039387DC1B60801400763A00 /* auto.cpp */, 145 | 039387DD1B60801400763A00 /* auto.h */, 146 | 039D50F31B5F6C66002A08C5 /* my_image.jpg */, 147 | ); 148 | path = ovtest; 149 | sourceTree = ""; 150 | }; 151 | /* End PBXGroup section */ 152 | 153 | /* Begin PBXNativeTarget section */ 154 | 03B7C7001B5DE1F000A4FDA6 /* ovtest */ = { 155 | isa = PBXNativeTarget; 156 | buildConfigurationList = 03B7C7081B5DE1F000A4FDA6 /* Build configuration list for PBXNativeTarget "ovtest" */; 157 | buildPhases = ( 158 | 03B7C6FD1B5DE1F000A4FDA6 /* Sources */, 159 | 03B7C6FE1B5DE1F000A4FDA6 /* Frameworks */, 160 | 03B7C6FF1B5DE1F000A4FDA6 /* CopyFiles */, 161 | ); 162 | buildRules = ( 163 | ); 164 | dependencies = ( 165 | ); 166 | name = ovtest; 167 | productName = ovtest; 168 | productReference = 03B7C7011B5DE1F000A4FDA6 /* ovtest */; 169 | productType = "com.apple.product-type.tool"; 170 | }; 171 | /* End PBXNativeTarget section */ 172 | 173 | /* Begin PBXProject section */ 174 | 03B7C6F91B5DE1F000A4FDA6 /* Project object */ = { 175 | isa = PBXProject; 176 | attributes = { 177 | LastUpgradeCheck = 0640; 178 | ORGANIZATIONNAME = vitrum.zhu; 179 | TargetAttributes = { 180 | 03B7C7001B5DE1F000A4FDA6 = { 181 | CreatedOnToolsVersion = 6.4; 182 | }; 183 | }; 184 | }; 185 | buildConfigurationList = 03B7C6FC1B5DE1F000A4FDA6 /* Build configuration list for PBXProject "ovtest" */; 186 | compatibilityVersion = "Xcode 3.2"; 187 | developmentRegion = English; 188 | hasScannedForEncodings = 0; 189 | knownRegions = ( 190 | en, 191 | ); 192 | mainGroup = 03B7C6F81B5DE1F000A4FDA6; 193 | productRefGroup = 03B7C7021B5DE1F000A4FDA6 /* Products */; 194 | projectDirPath = ""; 195 | projectRoot = ""; 196 | targets = ( 197 | 03B7C7001B5DE1F000A4FDA6 /* ovtest */, 198 | ); 199 | }; 200 | /* End PBXProject section */ 201 | 202 | /* Begin PBXSourcesBuildPhase section */ 203 | 03B7C6FD1B5DE1F000A4FDA6 /* Sources */ = { 204 | isa = PBXSourcesBuildPhase; 205 | buildActionMask = 2147483647; 206 | files = ( 207 | 03B7C7051B5DE1F000A4FDA6 /* main.cpp in Sources */, 208 | ); 209 | runOnlyForDeploymentPostprocessing = 0; 210 | }; 211 | /* End PBXSourcesBuildPhase section */ 212 | 213 | /* Begin XCBuildConfiguration section */ 214 | 03B7C7061B5DE1F000A4FDA6 /* Debug */ = { 215 | isa = XCBuildConfiguration; 216 | buildSettings = { 217 | ALWAYS_SEARCH_USER_PATHS = NO; 218 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 219 | CLANG_CXX_LIBRARY = "libc++"; 220 | CLANG_ENABLE_MODULES = YES; 221 | CLANG_ENABLE_OBJC_ARC = YES; 222 | CLANG_WARN_BOOL_CONVERSION = YES; 223 | CLANG_WARN_CONSTANT_CONVERSION = YES; 224 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 225 | CLANG_WARN_EMPTY_BODY = YES; 226 | CLANG_WARN_ENUM_CONVERSION = YES; 227 | CLANG_WARN_INT_CONVERSION = YES; 228 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 229 | CLANG_WARN_UNREACHABLE_CODE = YES; 230 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 231 | COPY_PHASE_STRIP = NO; 232 | DEBUG_INFORMATION_FORMAT = dwarf; 233 | ENABLE_STRICT_OBJC_MSGSEND = YES; 234 | GCC_C_LANGUAGE_STANDARD = gnu99; 235 | GCC_DYNAMIC_NO_PIC = NO; 236 | GCC_NO_COMMON_BLOCKS = YES; 237 | GCC_OPTIMIZATION_LEVEL = 0; 238 | GCC_PREPROCESSOR_DEFINITIONS = ( 239 | "DEBUG=1", 240 | "$(inherited)", 241 | ); 242 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 243 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 244 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 245 | GCC_WARN_UNDECLARED_SELECTOR = YES; 246 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 247 | GCC_WARN_UNUSED_FUNCTION = YES; 248 | GCC_WARN_UNUSED_VARIABLE = YES; 249 | MACOSX_DEPLOYMENT_TARGET = 10.10; 250 | MTL_ENABLE_DEBUG_INFO = YES; 251 | ONLY_ACTIVE_ARCH = YES; 252 | SDKROOT = macosx; 253 | }; 254 | name = Debug; 255 | }; 256 | 03B7C7071B5DE1F000A4FDA6 /* Release */ = { 257 | isa = XCBuildConfiguration; 258 | buildSettings = { 259 | ALWAYS_SEARCH_USER_PATHS = NO; 260 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 261 | CLANG_CXX_LIBRARY = "libc++"; 262 | CLANG_ENABLE_MODULES = YES; 263 | CLANG_ENABLE_OBJC_ARC = YES; 264 | CLANG_WARN_BOOL_CONVERSION = YES; 265 | CLANG_WARN_CONSTANT_CONVERSION = YES; 266 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 267 | CLANG_WARN_EMPTY_BODY = YES; 268 | CLANG_WARN_ENUM_CONVERSION = YES; 269 | CLANG_WARN_INT_CONVERSION = YES; 270 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 271 | CLANG_WARN_UNREACHABLE_CODE = YES; 272 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 273 | COPY_PHASE_STRIP = NO; 274 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 275 | ENABLE_NS_ASSERTIONS = NO; 276 | ENABLE_STRICT_OBJC_MSGSEND = YES; 277 | GCC_C_LANGUAGE_STANDARD = gnu99; 278 | GCC_NO_COMMON_BLOCKS = YES; 279 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 280 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 281 | GCC_WARN_UNDECLARED_SELECTOR = YES; 282 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 283 | GCC_WARN_UNUSED_FUNCTION = YES; 284 | GCC_WARN_UNUSED_VARIABLE = YES; 285 | MACOSX_DEPLOYMENT_TARGET = 10.10; 286 | MTL_ENABLE_DEBUG_INFO = NO; 287 | SDKROOT = macosx; 288 | }; 289 | name = Release; 290 | }; 291 | 03B7C7091B5DE1F000A4FDA6 /* Debug */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | HEADER_SEARCH_PATHS = ( 295 | "$(inherited)", 296 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 297 | /usr/local/include, 298 | ); 299 | LIBRARY_SEARCH_PATHS = ( 300 | "$(inherited)", 301 | "$(PROJECT_DIR)", 302 | /usr/local/lib, 303 | /usr/local/Cellar/opencv/2.4.11_1/lib, 304 | ); 305 | PRODUCT_NAME = "$(TARGET_NAME)"; 306 | }; 307 | name = Debug; 308 | }; 309 | 03B7C70A1B5DE1F000A4FDA6 /* Release */ = { 310 | isa = XCBuildConfiguration; 311 | buildSettings = { 312 | HEADER_SEARCH_PATHS = ( 313 | "$(inherited)", 314 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 315 | /usr/local/include, 316 | ); 317 | LIBRARY_SEARCH_PATHS = ( 318 | "$(inherited)", 319 | "$(PROJECT_DIR)", 320 | /usr/local/lib, 321 | /usr/local/Cellar/opencv/2.4.11_1/lib, 322 | ); 323 | PRODUCT_NAME = "$(TARGET_NAME)"; 324 | }; 325 | name = Release; 326 | }; 327 | /* End XCBuildConfiguration section */ 328 | 329 | /* Begin XCConfigurationList section */ 330 | 03B7C6FC1B5DE1F000A4FDA6 /* Build configuration list for PBXProject "ovtest" */ = { 331 | isa = XCConfigurationList; 332 | buildConfigurations = ( 333 | 03B7C7061B5DE1F000A4FDA6 /* Debug */, 334 | 03B7C7071B5DE1F000A4FDA6 /* Release */, 335 | ); 336 | defaultConfigurationIsVisible = 0; 337 | defaultConfigurationName = Release; 338 | }; 339 | 03B7C7081B5DE1F000A4FDA6 /* Build configuration list for PBXNativeTarget "ovtest" */ = { 340 | isa = XCConfigurationList; 341 | buildConfigurations = ( 342 | 03B7C7091B5DE1F000A4FDA6 /* Debug */, 343 | 03B7C70A1B5DE1F000A4FDA6 /* Release */, 344 | ); 345 | defaultConfigurationIsVisible = 0; 346 | defaultConfigurationName = Release; 347 | }; 348 | /* End XCConfigurationList section */ 349 | }; 350 | rootObject = 03B7C6F91B5DE1F000A4FDA6 /* Project object */; 351 | } 352 | -------------------------------------------------------------------------------- /ovtest/auto.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // auto.cpp 3 | // ovtest 4 | // 5 | // Created by vitrum.zhu on 15/7/23. 6 | // Copyright (c) 2015年 vitrum.zhu. All rights reserved. 7 | // 8 | 9 | #include "auto.h" 10 | 11 | 12 | // 13 | // main.cpp 14 | // ovtest 15 | // 16 | // Created by vitrum.zhu on 15/7/21. 17 | // Copyright (c) 2015年 vitrum.zhu. All rights reserved. 18 | // 19 | 20 | // Example showing how to read and write images 21 | #include 22 | #include 23 | #include 24 | using namespace cv; 25 | using namespace std; 26 | 27 | 28 | 29 | cv::Point2f center(0,0); 30 | 31 | cv::Point2f computeIntersect(cv::Vec4i a, 32 | cv::Vec4i b) 33 | { 34 | int x1 = a[0], y1 = a[1], x2 = a[2], y2 = a[3], x3 = b[0], y3 = b[1], x4 = b[2], y4 = b[3]; 35 | // float denom; 36 | 37 | if (float d = ((float)(x1 - x2) * (y3 - y4)) - ((y1 - y2) * (x3 - x4))) 38 | { 39 | cv::Point2f pt; 40 | pt.x = ((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d; 41 | pt.y = ((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d; 42 | return pt; 43 | } 44 | else 45 | return cv::Point2f(-1, -1); 46 | } 47 | 48 | void sortCorners(std::vector& corners, 49 | cv::Point2f center) 50 | { 51 | std::vector top, bot; 52 | 53 | for (int i = 0; i < corners.size(); i++) 54 | { 55 | if (corners[i].y < center.y) 56 | top.push_back(corners[i]); 57 | else 58 | bot.push_back(corners[i]); 59 | } 60 | corners.clear(); 61 | 62 | if (top.size() == 2 && bot.size() == 2){ 63 | cv::Point2f tl = top[0].x > top[1].x ? top[1] : top[0]; 64 | cv::Point2f tr = top[0].x > top[1].x ? top[0] : top[1]; 65 | cv::Point2f bl = bot[0].x > bot[1].x ? bot[1] : bot[0]; 66 | cv::Point2f br = bot[0].x > bot[1].x ? bot[0] : bot[1]; 67 | 68 | 69 | corners.push_back(tl); 70 | corners.push_back(tr); 71 | corners.push_back(br); 72 | corners.push_back(bl); 73 | } 74 | } 75 | 76 | int main() 77 | { 78 | cv::Mat src = cv::imread("myimg-3.png"); 79 | Mat img_proc ,img_dis ; 80 | 81 | if (src.empty()) 82 | return -1; 83 | int w = src.size().width, h = src.size().height, min_w = 100; 84 | double scale = min(30.0, w * 1.0 / min_w); 85 | int w_proc = w * 1.0 / scale, h_proc = h * 1.0 / scale; 86 | resize(src, img_proc, Size(w_proc, h_proc)); 87 | img_dis = img_proc.clone(); 88 | 89 | 90 | cv::Mat bw; 91 | cv::cvtColor(img_proc, bw, CV_BGR2GRAY); 92 | cv::blur(bw, bw, cv::Size(3, 3)); 93 | cv::Canny(bw, bw, 50, 200, 3); 94 | 95 | 96 | 97 | 98 | std::vector lines; 99 | cv::HoughLinesP(bw, lines, 1, CV_PI/180, 30, 30, 0); 100 | 101 | // cv::HoughLinesP(bw, lines, 1,CV_PI / 180, w_proc / 3, w_proc / 3, 0); 102 | 103 | 104 | cout<<"w:"<< src.size().width<< ", w_proc:"< corners; 135 | for (int i = 0; i < lines.size(); i++) 136 | { 137 | for (int j = i+1; j < lines.size(); j++) 138 | { 139 | cv::Point2f pt = computeIntersect(lines[i], lines[j]); 140 | if (pt.x >= 0 && pt.y >= 0) 141 | corners.push_back(pt); 142 | } 143 | } 144 | 145 | std::vector approx; 146 | cv::approxPolyDP(cv::Mat(corners), approx, cv::arcLength(cv::Mat(corners), true) * 0.02, true); 147 | 148 | 149 | 150 | 151 | 152 | 153 | if (approx.size() != 4) 154 | { 155 | std::cout << "The object is not quadrilateral!" << std::endl; 156 | std::cout << "Approx size is : " < quad_pts; 185 | quad_pts.push_back(cv::Point2f(0, 0)); 186 | quad_pts.push_back(cv::Point2f(quad.cols, 0)); 187 | quad_pts.push_back(cv::Point2f(quad.cols, quad.rows)); 188 | quad_pts.push_back(cv::Point2f(0, quad.rows)); 189 | 190 | cv::Mat transmtx = cv::getPerspectiveTransform(corners, quad_pts); 191 | cv::warpPerspective(src, quad, transmtx, quad.size()); 192 | 193 | cv::imshow("image", img_dis); 194 | cv::imshow("quadrilateral", quad); 195 | cv::waitKey(); 196 | return 0; 197 | } -------------------------------------------------------------------------------- /ovtest/auto.h: -------------------------------------------------------------------------------- 1 | // 2 | // auto.h 3 | // ovtest 4 | // 5 | // Created by vitrum.zhu on 15/7/23. 6 | // Copyright (c) 2015年 vitrum.zhu. All rights reserved. 7 | // 8 | 9 | #ifndef __ovtest__auto__ 10 | #define __ovtest__auto__ 11 | 12 | #include 13 | 14 | #endif /* defined(__ovtest__auto__) */ 15 | -------------------------------------------------------------------------------- /ovtest/bk.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // ovtest 4 | // 5 | // Created by vitrum.zhu on 15/7/21. 6 | // Copyright (c) 2015年 vitrum.zhu. All rights reserved. 7 | // 8 | 9 | // Example showing how to read and write images 10 | #include 11 | #include 12 | using namespace cv; 13 | 14 | 15 | 16 | cv::Point2f center(0,0); 17 | 18 | cv::Point2f computeIntersect(cv::Vec4i a,cv::Vec4i b) 19 | { 20 | int x1 = a[0],y1 = a[1],x2 = a[2],y2 = a[3],x3 = b[0],y3 = b[1],x4 = b[2],y4 = b[3]; 21 | 22 | if (float d = ((float)(x1 - x2)*(y3 - y4)-(y1 - y2)*(x3 - x4))) 23 | { 24 | cv::Point2f pt; 25 | pt.x = ((x1*y2 - y1*x2)*(x3 - x4) - (x1 - x2)*(x3*y4 - y3*x4))/d; 26 | pt.y = ((x1*y2 - y1*x2)*(y3 - y4) - (y1 - y2)*(x3*y4 - y3*x4))/d; 27 | return pt; 28 | } 29 | else 30 | return cv::Point2f(-1,-1); 31 | } 32 | 33 | void sortCorners(std::vector& corners,cv::Point2f center) 34 | { 35 | std::vector top,bot; 36 | 37 | for (unsigned int i =0;i< corners.size();i++) 38 | { 39 | if (corners[i].y top[1].x ? top[1] : top[0]; 50 | cv::Point2f tr = top[0].x > top[1].x ? top[0] : top[1]; 51 | cv::Point2f bl = bot[0].x > bot[1].x ? bot[1] : bot[0]; 52 | cv::Point2f br = bot[0].x > bot[1].x ? bot[0] : bot[1]; 53 | 54 | corners.clear(); 55 | //注意以下存放顺序是顺时针,当时这里出错了,如果想任意顺序下文开辟的四边形矩阵注意对应 56 | corners.push_back(tl); 57 | corners.push_back(tr); 58 | corners.push_back(br); 59 | corners.push_back(bl); 60 | 61 | } 62 | 63 | // Main 64 | 65 | int main(int argc, char** argv) 66 | { 67 | // Load an image from file - change this based on your image name 68 | Mat img = imread("myimg.png", CV_LOAD_IMAGE_UNCHANGED); 69 | Mat img_proc; 70 | if(img.empty()) 71 | { 72 | fprintf(stderr, "failed to load input image\n"); 73 | return -1; 74 | } 75 | int w = img.size().width, h = img.size().height, min_w = 200; 76 | double scale = min(10.0, w * 1.0 / min_w); 77 | int w_proc = w * 1.0 / scale, h_proc = h * 1.0 / scale; 78 | 79 | resize(img, img_proc, Size(w_proc, h_proc)); 80 | Mat img_dis = img_proc.clone(); 81 | 82 | // this is just to show, that you won't have to pre-alloc 83 | // result-images with c++ any more.. 84 | Mat bw; 85 | cvtColor(img_proc,bw,CV_BGR2GRAY); 86 | 87 | imshow("gray_src", bw); 88 | blur(bw,bw,cv::Size(3,3)); 89 | 90 | // Save temp image file. 91 | // if( ! imwrite("image_gray.png", bw) ) 92 | // { 93 | // fprintf(stderr, "failed to write image file\n"); 94 | // } 95 | 96 | imshow("blur", bw); 97 | Canny(bw, bw, 100, 100,3); 98 | 99 | imshow("cannyblur",bw); 100 | 101 | 102 | // Save temp image file. 103 | // if( ! imwrite("image_cannyblur.png", bw) ) 104 | // { 105 | // fprintf(stderr, "failed to write image file\n"); 106 | // } 107 | 108 | 109 | 110 | std::vector lines; 111 | // std::vector horizontals, verticals; 112 | // HoughLinesP(bw, lines, 1, CV_PI / 180, w_proc / 3, w_proc / 3, 20); 113 | cv::HoughLinesP(bw,lines,1,CV_PI/180,70,30,10); 114 | std::cout<<"共检测出:"<70可以检测成连线 30是最小线长 119 | //在直线L上的点(且点与点之间距离小于maxLineGap=10的)连成线段,然后这些点全部删除,并且记录该线段的参数,就是起始点和终止点 120 | 121 | 122 | // Save temp image file. 123 | // if( ! imwrite("image_HoughLinesP.png", bw) ) 124 | // { 125 | // fprintf(stderr, "failed to write image file\n"); 126 | // } 127 | 128 | //needed for visualization only//这里是将检测的线调整到延长至全屏,即射线的效果,其实可以不必这么做 129 | // for (unsigned int i = 0;i corners;//线的交点存储 140 | for (unsigned int i = 0;i= 0 && pt.y >=0) 146 | { 147 | corners.push_back(pt); 148 | } 149 | } 150 | } 151 | std::cout<<"共交叉点出:"< approx; 155 | cv::approxPolyDP(cv::Mat(corners),approx,cv::arcLength(cv::Mat(corners),true)*0.02,true); 156 | 157 | if (approx.size()!=4) 158 | { 159 | std::cout<<"The object is not quadrilateral(四边形):"< quad_pts; 194 | quad_pts.push_back(cv::Point2f(0,0)); 195 | quad_pts.push_back(cv::Point2f(quad.cols,0));//(220,0) 196 | quad_pts.push_back(cv::Point2f(quad.cols,quad.rows));//(220,300) 197 | quad_pts.push_back(cv::Point2f(0,quad.rows)); 198 | 199 | // Get transformation matrix 200 | cv::Mat transmtx = cv::getPerspectiveTransform(corners,quad_pts); //求源坐标系(已畸变的)与目标坐标系的转换矩阵 201 | 202 | // Apply perspective transformation透视转换 203 | cv::warpPerspective(img,quad,transmtx,quad.size()); 204 | cv::imshow("src",img); 205 | cv::imshow("image",dst); 206 | cv::imshow("quadrilateral",quad); 207 | 208 | cv::waitKey(); 209 | return 0; 210 | 211 | 212 | 213 | } -------------------------------------------------------------------------------- /ovtest/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // ovtest 4 | // 5 | // Created by vitrum.zhu on 15/7/21. 6 | // Copyright (c) 2015年 vitrum.zhu. All rights reserved. 7 | // 8 | 9 | // Example showing how to read and write images 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | using namespace cv; 16 | using namespace std; 17 | 18 | /** 19 | * Get edges of an image 20 | * @param gray - grayscale input image 21 | * @param canny - output edge image 22 | */ 23 | void getCanny(Mat gray, Mat &canny) { 24 | Mat thres; 25 | double high_thres = threshold(gray, thres, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU), low_thres = high_thres * 0.5; 26 | Canny(gray, canny, low_thres, high_thres); 27 | } 28 | 29 | struct Line { 30 | Point _p1; 31 | Point _p2; 32 | Point _center; 33 | 34 | Line(Point p1, Point p2) { 35 | _p1 = p1; 36 | _p2 = p2; 37 | _center = Point((p1.x + p2.x) / 2, (p1.y + p2.y) / 2); 38 | } 39 | }; 40 | 41 | bool cmp_y(const Line &p1, const Line &p2) { 42 | return p1._center.y < p2._center.y; 43 | } 44 | 45 | bool cmp_x(const Line &p1, const Line &p2) { 46 | return p1._center.x < p2._center.x; 47 | } 48 | 49 | /** 50 | * Compute intersect point of two lines l1 and l2 51 | * @param l1 52 | * @param l2 53 | * @return Intersect Point 54 | */ 55 | Point2f computeIntersect(Line l1, Line l2) { 56 | int x1 = l1._p1.x, x2 = l1._p2.x, y1 = l1._p1.y, y2 = l1._p2.y; 57 | int x3 = l2._p1.x, x4 = l2._p2.x, y3 = l2._p1.y, y4 = l2._p2.y; 58 | if (float d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)) { 59 | Point2f pt; 60 | pt.x = ((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d; 61 | pt.y = ((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d; 62 | return pt; 63 | } 64 | return Point2f(-1, -1); 65 | } 66 | 67 | void scan(String file, bool debug = true) { 68 | 69 | /* get input image */ 70 | Mat img = imread(file); 71 | // resize input image to img_proc to reduce computation 72 | Mat img_proc; 73 | int w = img.size().width, h = img.size().height, min_w = 200; 74 | double scale = min(10.0, w * 1.0 / min_w); 75 | int w_proc = w * 1.0 / scale, h_proc = h * 1.0 / scale; 76 | resize(img, img_proc, Size(w_proc, h_proc)); 77 | Mat img_dis = img_proc.clone(); 78 | 79 | /* get four outline edges of the document */ 80 | // get edges of the image 81 | Mat gray, canny; 82 | cvtColor(img_proc, gray, CV_BGR2GRAY); 83 | getCanny(gray, canny); 84 | 85 | // extract lines from the edge image 86 | vector lines; 87 | vector horizontals, verticals; 88 | HoughLinesP(canny, lines, 1, CV_PI / 180, w_proc / 3, w_proc / 3, 20); 89 | for (size_t i = 0; i < lines.size(); i++) { 90 | Vec4i v = lines[i]; 91 | double delta_x = v[0] - v[2], delta_y = v[1] - v[3]; 92 | Line l(Point(v[0], v[1]), Point(v[2], v[3])); 93 | // get horizontal lines and vertical lines respectively 94 | if (fabs(delta_x) > fabs(delta_y)) { 95 | horizontals.push_back(l); 96 | } else { 97 | verticals.push_back(l); 98 | } 99 | // for visualization only 100 | if (debug) 101 | line(img_proc, Point(v[0], v[1]), Point(v[2], v[3]), Scalar(0, 0, 255), 1, CV_AA); 102 | } 103 | 104 | // edge cases when not enough lines are detected 105 | if (horizontals.size() < 2) { 106 | if (horizontals.size() == 0 || horizontals[0]._center.y > h_proc / 2) { 107 | horizontals.push_back(Line(Point(0, 0), Point(w_proc - 1, 0))); 108 | } 109 | if (horizontals.size() == 0 || horizontals[0]._center.y <= h_proc / 2) { 110 | horizontals.push_back(Line(Point(0, h_proc - 1), Point(w_proc - 1, h_proc - 1))); 111 | } 112 | } 113 | if (verticals.size() < 2) { 114 | if (verticals.size() == 0 || verticals[0]._center.x > w_proc / 2) { 115 | verticals.push_back(Line(Point(0, 0), Point(0, h_proc - 1))); 116 | } 117 | if (verticals.size() == 0 || verticals[0]._center.x <= w_proc / 2) { 118 | verticals.push_back(Line(Point(w_proc - 1, 0), Point(w_proc - 1, h_proc - 1))); 119 | } 120 | } 121 | // sort lines according to their center point 122 | sort(horizontals.begin(), horizontals.end(), cmp_y); 123 | sort(verticals.begin(), verticals.end(), cmp_x); 124 | // for visualization only 125 | if (debug) { 126 | line(img_proc, horizontals[0]._p1, horizontals[0]._p2, Scalar(0, 255, 0), 2, CV_AA); 127 | line(img_proc, horizontals[horizontals.size() - 1]._p1, horizontals[horizontals.size() - 1]._p2, Scalar(0, 255, 0), 2, CV_AA); 128 | line(img_proc, verticals[0]._p1, verticals[0]._p2, Scalar(255, 0, 0), 2, CV_AA); 129 | line(img_proc, verticals[verticals.size() - 1]._p1, verticals[verticals.size() - 1]._p2, Scalar(255, 0, 0), 2, CV_AA); 130 | } 131 | 132 | /* perspective transformation */ 133 | 134 | // define the destination image size: A4 - 200 PPI 135 | int w_a4 = 1654, h_a4 = 2339; 136 | //int w_a4 = 595, h_a4 = 842; 137 | Mat dst = Mat::zeros(h_a4, w_a4, CV_8UC3); 138 | 139 | // corners of destination image with the sequence [tl, tr, bl, br] 140 | vector dst_pts, img_pts; 141 | dst_pts.push_back(Point(0, 0)); 142 | dst_pts.push_back(Point(w_a4 - 1, 0)); 143 | dst_pts.push_back(Point(0, h_a4 - 1)); 144 | dst_pts.push_back(Point(w_a4 - 1, h_a4 - 1)); 145 | 146 | // corners of source image with the sequence [tl, tr, bl, br] 147 | img_pts.push_back(computeIntersect(horizontals[0], verticals[0])); 148 | img_pts.push_back(computeIntersect(horizontals[0], verticals[verticals.size() - 1])); 149 | img_pts.push_back(computeIntersect(horizontals[horizontals.size() - 1], verticals[0])); 150 | img_pts.push_back(computeIntersect(horizontals[horizontals.size() - 1], verticals[verticals.size() - 1])); 151 | 152 | // convert to original image scale 153 | for (size_t i = 0; i < img_pts.size(); i++) { 154 | // for visualization only 155 | if (debug) { 156 | circle(img_proc, img_pts[i], 10, Scalar(255, 255, 0), 3); 157 | } 158 | img_pts[i].x *= scale; 159 | img_pts[i].y *= scale; 160 | } 161 | 162 | // get transformation matrix 163 | Mat transmtx = getPerspectiveTransform(img_pts, dst_pts); 164 | 165 | // apply perspective transformation 166 | warpPerspective(img, dst, transmtx, dst.size()); 167 | 168 | // save dst img 169 | imwrite("dst.jpg", dst); 170 | 171 | // for visualization only 172 | if (debug) { 173 | namedWindow("dst", CV_WINDOW_KEEPRATIO); 174 | imshow("src", img_dis); 175 | imshow("canny", canny); 176 | imshow("img_proc", img_proc); 177 | imshow("dst", dst); 178 | waitKey(0); 179 | } 180 | } 181 | 182 | int main(int argc, char** argv) { 183 | string img_path[] = {"myimg-2.png", "images/doc2.jpg", "images/doc3.jpg"}; 184 | scan(img_path[0]); 185 | return 0; 186 | } -------------------------------------------------------------------------------- /ovtest/my_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vitrum/opencv-demo/1b522ffb7ca07f21ba524b957661b94047f90671/ovtest/my_image.jpg -------------------------------------------------------------------------------- /ovtest/other.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // other.cpp 3 | // ovtest 4 | // 5 | // Created by vitrum.zhu on 15/7/23. 6 | // Copyright (c) 2015年 vitrum.zhu. All rights reserved. 7 | // 8 | 9 | #include "other.h" 10 | 11 | // 12 | // main.cpp 13 | // opencv 14 | // 15 | // Created by vitrum.zhu on 15/7/21. 16 | // Copyright (c) 2015年 vitrum. All rights reserved. 17 | // 18 | 19 | 20 | //-----------------------------------【程序说明】---------------------------------------------- 21 | // 程序名称::《【OpenCV入门教程之十四】OpenCV霍夫变换:霍夫线变换,霍夫圆变换合辑 》 博文配套源码 22 | // 开发所用IDE版本:Visual Studio 2010 23 | // 开发所用OpenCV版本: 2.4.9 24 | // 2014年5月26日 Created by 浅墨 25 | // 配套博文链接: http://blog.csdn.net/poem_qianmo/article/details/26977557 26 | // PS:程序结合配合博文学习效果更佳 27 | // 浅墨的微博:@浅墨_毛星云 http://weibo.com/1723155442 28 | // 浅墨的知乎:http://www.zhihu.com/people/mao-xing-yun 29 | // 浅墨的豆瓣:http://www.douban.com/people/53426472/ 30 | //---------------------------------------------------------------------------------------------- 31 | 32 | //-----------------------------------【头文件包含部分】--------------------------------------- 33 | // 描述:包含程序所依赖的头文件 34 | //---------------------------------------------------------------------------------------------- 35 | #include 36 | #include 37 | #include 38 | 39 | //-----------------------------------【命名空间声明部分】-------------------------------------- 40 | // 描述:包含程序所使用的命名空间 41 | //----------------------------------------------------------------------------------------------- 42 | using namespace std; 43 | using namespace cv; 44 | 45 | 46 | //-----------------------------------【全局变量声明部分】-------------------------------------- 47 | // 描述:全局变量声明 48 | //----------------------------------------------------------------------------------------------- 49 | Mat g_srcImage, g_dstImage,g_midImage;//原始图、中间图和效果图 50 | vector g_lines;//定义一个矢量结构g_lines用于存放得到的线段矢量集合 51 | //变量接收的TrackBar位置参数 52 | int g_nthreshold=100; 53 | 54 | //-----------------------------------【全局函数声明部分】-------------------------------------- 55 | // 描述:全局函数声明 56 | //----------------------------------------------------------------------------------------------- 57 | 58 | static void on_HoughLines(int, void*);//回调函数 59 | static void ShowHelpText(); 60 | 61 | 62 | //-----------------------------------【main( )函数】-------------------------------------------- 63 | // 描述:控制台应用程序的入口函数,我们的程序从这里开始 64 | //----------------------------------------------------------------------------------------------- 65 | int main( ) 66 | { 67 | //改变console字体颜色 68 | system("color 3F"); 69 | 70 | ShowHelpText(); 71 | 72 | //载入原始图和Mat变量定义 73 | Mat g_srcImage = imread("1.jpg"); //工程目录下应该有一张名为1.jpg的素材图 74 | 75 | //显示原始图 76 | imshow("【原始图】", g_srcImage); 77 | 78 | //创建滚动条 79 | namedWindow("【效果图】",1); 80 | createTrackbar("值", "【效果图】",&g_nthreshold,200,on_HoughLines); 81 | 82 | //进行边缘检测和转化为灰度图 83 | Canny(g_srcImage, g_midImage, 50, 200, 3);//进行一次canny边缘检测 84 | cvtColor(g_midImage,g_dstImage, CV_GRAY2BGR);//转化边缘检测后的图为灰度图 85 | 86 | //调用一次回调函数,调用一次HoughLinesP函数 87 | on_HoughLines(g_nthreshold,0); 88 | HoughLinesP(g_midImage, g_lines, 1, CV_PI/180, 80, 50, 10 ); 89 | 90 | //显示效果图 91 | imshow("【效果图】", g_dstImage); 92 | 93 | 94 | waitKey(0); 95 | 96 | return 0; 97 | 98 | } 99 | 100 | 101 | //-----------------------------------【on_HoughLines( )函数】-------------------------------- 102 | // 描述:【顶帽运算/黑帽运算】窗口的回调函数 103 | //---------------------------------------------------------------------------------------------- 104 | static void on_HoughLines(int, void*) 105 | { 106 | //定义局部变量储存全局变量 107 | Mat dstImage=g_dstImage.clone(); 108 | Mat midImage=g_midImage.clone(); 109 | 110 | //调用HoughLinesP函数 111 | vector mylines; 112 | HoughLinesP(midImage, mylines, 1, CV_PI/180, g_nthreshold+1, 50, 10 ); 113 | 114 | //循环遍历绘制每一条线段 115 | for( size_t i = 0; i < mylines.size(); i++ ) 116 | { 117 | Vec4i l = mylines[i]; 118 | line( dstImage, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(23,180,55), 1, CV_AA); 119 | } 120 | //显示图像 121 | imshow("【效果图】",dstImage); 122 | } 123 | 124 | //-----------------------------------【ShowHelpText( )函数】---------------------------------- 125 | // 描述:输出一些帮助信息 126 | //---------------------------------------------------------------------------------------------- 127 | static void ShowHelpText() 128 | { 129 | //输出一些帮助信息 130 | printf("\n\n\n\t请调整滚动条观察图像效果~\n\n"); 131 | printf("\n\n\t\t\t\t\t\t\t\t by浅墨" 132 | ); 133 | } -------------------------------------------------------------------------------- /ovtest/other.h: -------------------------------------------------------------------------------- 1 | // 2 | // other.h 3 | // ovtest 4 | // 5 | // Created by vitrum.zhu on 15/7/23. 6 | // Copyright (c) 2015年 vitrum.zhu. All rights reserved. 7 | // 8 | 9 | #ifndef __ovtest__other__ 10 | #define __ovtest__other__ 11 | 12 | #include 13 | 14 | #endif /* defined(__ovtest__other__) */ 15 | -------------------------------------------------------------------------------- /ovtest/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vitrum/opencv-demo/1b522ffb7ca07f21ba524b957661b94047f90671/ovtest/test --------------------------------------------------------------------------------