Merge lp:~yolanda.robla/ubuntu/saucy/sikuli/debian_merge into lp:ubuntu/saucy/sikuli
- Saucy (13.10)
- debian_merge
- Merge into saucy
Proposed by
Yolanda Robla
Status: | Merged |
---|---|
Merged at revision: | 15 |
Proposed branch: | lp:~yolanda.robla/ubuntu/saucy/sikuli/debian_merge |
Merge into: | lp:ubuntu/saucy/sikuli |
Diff against target: |
11100 lines (+744/-9680) 55 files modified
.pc/applied-patches (+0/-10) .pc/executable-wrappers.patch/sikuli-ide/target/linux/Sikuli-IDE/sikuli-ide.sh (+0/-3) .pc/executable-wrappers.patch/sikuli-script/target/sikuli-script.sh (+0/-2) .pc/fix-cmake-sikuli-ide.patch/sikuli-ide/CMakeLists.txt (+0/-403) .pc/gcc-4.7.patch/sikuli-script/src/main/native/sikuli-debug.h (+0/-52) .pc/install-extension.patch/sikuli-script/src/main/java/org/sikuli/script/ExtensionManager.java (+0/-175) .pc/jgoodies-1.6-compat.patch/sikuli-ide/CMakeLists.txt (+0/-405) .pc/jgoodies-1.6-compat.patch/sikuli-ide/src/main/java/org/sikuli/ide/PreferencesWin.java (+0/-561) .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/Finder.java (+0/-195) .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/TextRecognizer.java (+0/-120) .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/VDictProxy.java (+0/-118) .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/internal/hotkey/LinuxHotkeyManager.java (+0/-106) .pc/native.patch/sikuli-script/src/main/native/vision.i (+0/-264) .pc/no-opencv-surf-module.patch/sikuli-script/src/main/native/cvgui.cpp (+0/-2508) .pc/no-opencv-surf-module.patch/sikuli-script/src/main/native/cvgui.h (+0/-239) .pc/no-opencv-surf-module.patch/sikuli-script/src/main/native/imgdb.cpp (+0/-311) .pc/no-opencv-surf-module.patch/sikuli-script/src/main/native/imgdb.h (+0/-75) .pc/no-opencv-surf-module.patch/sikuli-script/src/main/native/vision.cpp (+0/-506) .pc/no-opencv-surf-module.patch/sikuli-script/src/main/native/vision.h (+0/-118) .pc/no-opencv-surf-module.patch/sikuli-script/src/main/native/vision.i (+0/-264) .pc/tess3.patch/cmake_modules/FindTesseract.cmake (+0/-47) .pc/tess3.patch/sikuli-script/src/main/native/tessocr.cpp (+0/-984) .pc/tessdata.patch/sikuli-script/CMakeLists.txt (+0/-297) .pc/tessdata.patch/sikuli-script/src/main/java/org/sikuli/script/TextRecognizer.java (+0/-118) .pc/tessdata.patch/sikuli-script/src/main/native/tessocr.cpp (+0/-983) .pc/use-java-libs-from-debian.patch/sikuli-ide/CMakeLists.txt (+0/-404) .pc/use-java-libs-from-debian.patch/sikuli-script/CMakeLists.txt (+0/-298) cmake_modules/FindTesseract.cmake (+12/-3) debian/changelog (+36/-0) debian/control (+6/-6) debian/patches/executable-wrappers.patch (+6/-6) debian/patches/force-java6-target.patch (+30/-0) debian/patches/jgoodies-1.6-compat.patch (+0/-40) debian/patches/series (+2/-1) debian/patches/setTextAndMnemonic.patch (+64/-0) debian/rules (+1/-1) sikuli-ide/CMakeLists.txt (+12/-14) sikuli-ide/src/main/java/org/sikuli/ide/PreferencesWin.java (+2/-3) sikuli-ide/target/linux/Sikuli-IDE/sikuli-ide.sh (+2/-1) sikuli-script/CMakeLists.txt (+17/-16) sikuli-script/src/main/java/org/sikuli/script/ExtensionManager.java (+2/-3) sikuli-script/src/main/java/org/sikuli/script/Finder.java (+4/-2) sikuli-script/src/main/java/org/sikuli/script/TextRecognizer.java (+11/-5) sikuli-script/src/main/java/org/sikuli/script/VDictProxy.java (+3/-2) sikuli-script/src/main/java/org/sikuli/script/internal/hotkey/LinuxHotkeyManager.java (+3/-2) sikuli-script/src/main/native/cvgui.cpp (+318/-0) sikuli-script/src/main/native/cvgui.h (+1/-0) sikuli-script/src/main/native/imgdb.cpp (+115/-0) sikuli-script/src/main/native/imgdb.h (+5/-0) sikuli-script/src/main/native/sikuli-debug.h (+1/-1) sikuli-script/src/main/native/tessocr.cpp (+12/-3) sikuli-script/src/main/native/vision.cpp (+63/-0) sikuli-script/src/main/native/vision.h (+5/-0) sikuli-script/src/main/native/vision.i (+10/-4) sikuli-script/target/sikuli-script.sh (+1/-1) |
To merge this branch: | bzr merge lp:~yolanda.robla/ubuntu/saucy/sikuli/debian_merge |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Daniel Holbach (community) | Approve | ||
Review via email: mp+176670@code.launchpad.net |
Commit message
Description of the change
Merging from latest Debian version
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed file '.pc/applied-patches' | |||
2 | --- .pc/applied-patches 2012-12-07 22:13:08 +0000 | |||
3 | +++ .pc/applied-patches 1970-01-01 00:00:00 +0000 | |||
4 | @@ -1,10 +0,0 @@ | |||
5 | 1 | executable-wrappers.patch | ||
6 | 2 | native.patch | ||
7 | 3 | use-java-libs-from-debian.patch | ||
8 | 4 | install-extension.patch | ||
9 | 5 | fix-cmake-sikuli-ide.patch | ||
10 | 6 | tess3.patch | ||
11 | 7 | tessdata.patch | ||
12 | 8 | gcc-4.7.patch | ||
13 | 9 | no-opencv-surf-module.patch | ||
14 | 10 | jgoodies-1.6-compat.patch | ||
15 | 11 | 0 | ||
16 | === removed directory '.pc/executable-wrappers.patch' | |||
17 | === removed directory '.pc/executable-wrappers.patch/sikuli-ide' | |||
18 | === removed directory '.pc/executable-wrappers.patch/sikuli-ide/target' | |||
19 | === removed directory '.pc/executable-wrappers.patch/sikuli-ide/target/linux' | |||
20 | === removed directory '.pc/executable-wrappers.patch/sikuli-ide/target/linux/Sikuli-IDE' | |||
21 | === removed file '.pc/executable-wrappers.patch/sikuli-ide/target/linux/Sikuli-IDE/sikuli-ide.sh' | |||
22 | --- .pc/executable-wrappers.patch/sikuli-ide/target/linux/Sikuli-IDE/sikuli-ide.sh 2011-04-16 00:23:53 +0000 | |||
23 | +++ .pc/executable-wrappers.patch/sikuli-ide/target/linux/Sikuli-IDE/sikuli-ide.sh 1970-01-01 00:00:00 +0000 | |||
24 | @@ -1,3 +0,0 @@ | |||
25 | 1 | #!/bin/sh | ||
26 | 2 | DIR=`dirname $0` | ||
27 | 3 | LC_NUMERIC=C java -Dsikuli.console=true -Dsikuli.debug=0 -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -jar $DIR/sikuli-ide.jar $* | ||
28 | 4 | 0 | ||
29 | === removed directory '.pc/executable-wrappers.patch/sikuli-script' | |||
30 | === removed directory '.pc/executable-wrappers.patch/sikuli-script/target' | |||
31 | === removed file '.pc/executable-wrappers.patch/sikuli-script/target/sikuli-script.sh' | |||
32 | --- .pc/executable-wrappers.patch/sikuli-script/target/sikuli-script.sh 2011-01-24 01:07:30 +0000 | |||
33 | +++ .pc/executable-wrappers.patch/sikuli-script/target/sikuli-script.sh 1970-01-01 00:00:00 +0000 | |||
34 | @@ -1,2 +0,0 @@ | |||
35 | 1 | #!/bin/sh | ||
36 | 2 | java -jar sikuli-script.jar $@ | ||
37 | 3 | 0 | ||
38 | === removed directory '.pc/fix-cmake-sikuli-ide.patch' | |||
39 | === removed directory '.pc/fix-cmake-sikuli-ide.patch/sikuli-ide' | |||
40 | === removed file '.pc/fix-cmake-sikuli-ide.patch/sikuli-ide/CMakeLists.txt' | |||
41 | --- .pc/fix-cmake-sikuli-ide.patch/sikuli-ide/CMakeLists.txt 2011-10-04 23:32:13 +0000 | |||
42 | +++ .pc/fix-cmake-sikuli-ide.patch/sikuli-ide/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
43 | @@ -1,403 +0,0 @@ | |||
44 | 1 | # Copyright 2010-2011, Sikuli.org | ||
45 | 2 | # Released under the MIT License. | ||
46 | 3 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) | ||
47 | 4 | PROJECT (sikuli-ide Java) | ||
48 | 5 | |||
49 | 6 | SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules") | ||
50 | 7 | INCLUDE(${CMAKE_MODULE_PATH}/common.cmake) | ||
51 | 8 | INCLUDE(${CMAKE_MODULE_PATH}/detect_osx_ver.cmake) | ||
52 | 9 | INCLUDE(${CMAKE_MODULE_PATH}/find_dep_libs.cmake) | ||
53 | 10 | |||
54 | 11 | |||
55 | 12 | ENABLE_TESTING() | ||
56 | 13 | |||
57 | 14 | SET(CMAKE_VERBOSE_MAKEFILE 0) | ||
58 | 15 | |||
59 | 16 | FIND_PACKAGE(Java 1.6 REQUIRED) | ||
60 | 17 | SET( NON_NATIVE_TARGET TRUE) | ||
61 | 18 | |||
62 | 19 | IF(UNIX) | ||
63 | 20 | SET(SEP ":") | ||
64 | 21 | ELSE() | ||
65 | 22 | SET(SEP ";") | ||
66 | 23 | ENDIF() | ||
67 | 24 | |||
68 | 25 | |||
69 | 26 | SET(BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") | ||
70 | 27 | SET(JAVA_SRC_DIR "${BASE_DIR}/src/main/java") | ||
71 | 28 | SET(NATIVE_SRC_DIR "${BASE_DIR}/src/main/native") | ||
72 | 29 | SET(COMMON_LIB_DIR "${BASE_DIR}/../lib") | ||
73 | 30 | SET(INCLUDE_LIB_DIR "${BASE_DIR}/lib") | ||
74 | 31 | SET(BINARY_DIR "${BASE_DIR}/target") | ||
75 | 32 | SET(BINARY_CLASS_DIR "${BINARY_DIR}/classes") | ||
76 | 33 | SET(BINARY_LIB_DIR "${BINARY_DIR}/lib") | ||
77 | 34 | SET(JAR_DIR "${BINARY_DIR}/jar") | ||
78 | 35 | SET(RESOURCE_DIR "${BASE_DIR}/resources") | ||
79 | 36 | SET(RELEASE_DIR "${BASE_DIR}/../release") | ||
80 | 37 | |||
81 | 38 | SET(JAVA_TEST_DIR "${BASE_DIR}/src/test/java") | ||
82 | 39 | SET(TEST_RESOURCE_DIR "test-res") | ||
83 | 40 | SET(JAVA_TEST_FOR_HUDSON_XML "../hudson-test.xml") | ||
84 | 41 | SET(TEST_CLASS_DIR "${CMAKE_BINARY_DIR}/test") | ||
85 | 42 | |||
86 | 43 | SET(SIKULI_SCRIPT_JAR "${COMMON_LIB_DIR}/sikuli-script.jar") | ||
87 | 44 | SET(JUNIT_JAR "/usr/share/java/junit.jar") | ||
88 | 45 | SET(SWING_LAYOUT_JAR "/usr/share/java/swing-layout.jar") | ||
89 | 46 | SET(COMMONS_CLI_JAR "/usr/share/java/commons-cli.jar") | ||
90 | 47 | SET(JSON_SIMPLE_JAR "/usr/share/java/json_simple.jar") | ||
91 | 48 | SET(SWINGX_JAR "/usr/share/java/swingx-core.jar") | ||
92 | 49 | SET(MAC_WIDGETS_JAR "/usr/share/java/mac_widgets.jar") | ||
93 | 50 | SET(FORMS_JAR "/usr/share/java/forms.jar") | ||
94 | 51 | |||
95 | 52 | |||
96 | 53 | FILE(MAKE_DIRECTORY ${BINARY_DIR}) | ||
97 | 54 | FILE(MAKE_DIRECTORY ${BINARY_CLASS_DIR}) | ||
98 | 55 | FILE(MAKE_DIRECTORY ${JAR_DIR}) | ||
99 | 56 | FILE(MAKE_DIRECTORY ${TEST_CLASS_DIR}) | ||
100 | 57 | |||
101 | 58 | ## Sikuli IDE | ||
102 | 59 | |||
103 | 60 | SET(MAIN_CLASS org.sikuli.ide.SikuliIDE) | ||
104 | 61 | SET(RUN_USER_ARGS -Dsikuli.console=true -Dfile.encoding=UTF-8 | ||
105 | 62 | -Dsikuli.testing=yes | ||
106 | 63 | -Xms64m -Xmx512m | ||
107 | 64 | CACHE STRING | ||
108 | 65 | "The arguments for running Sikuli IDE with 'make run-user'" | ||
109 | 66 | ) | ||
110 | 67 | SET(RUN_ARGS -Dsikuli.console=false -Dsikuli.Debug=3 -Dfile.encoding=UTF-8 | ||
111 | 68 | -Dsikuli.testing=yes | ||
112 | 69 | -Xms64m -Xmx512m | ||
113 | 70 | #-Duser.language=zh -Duser.region=TW | ||
114 | 71 | CACHE STRING | ||
115 | 72 | "The arguments for running Sikuli IDE with 'make run'" | ||
116 | 73 | ) | ||
117 | 74 | IF(APPLE) | ||
118 | 75 | LIST(APPEND RUN_ARGS -Xdock:name='Sikuli IDE') | ||
119 | 76 | ENDIF() | ||
120 | 77 | |||
121 | 78 | #SET(ARGS -s -r ../sample-scripts/mod1.sikuli --args a1 a2) # example args | ||
122 | 79 | SET(ARGS "") | ||
123 | 80 | |||
124 | 81 | SET(CLASSPATH | ||
125 | 82 | ${SIKULI_SCRIPT_JAR}${SEP}${JUNIT_JAR}${SEP}${SWING_LAYOUT_JAR}${SEP}${COMMONS_CLI_JAR}${SEP}${JSON_SIMPLE_JAR}${SEP}${SWINGX_JAR}${SEP}${MAC_WIDGETS_JAR}${SEP}${FORMS_JAR}${SEP}/usr/share/java/jython.jar | ||
126 | 83 | ) | ||
127 | 84 | |||
128 | 85 | SET(JAR_FILE sikuli-ide.jar) | ||
129 | 86 | SET(RESOURCES icons META-INF scripts i18n) | ||
130 | 87 | |||
131 | 88 | IF(LINUX) | ||
132 | 89 | SET(MANIFEST ${RESOURCE_DIR}/META-INF/MANIFEST-linux.MF) | ||
133 | 90 | #SET(CLASSPATH ${CLASSPATH}${SEP}${JXGRABKEY_JAR}) | ||
134 | 91 | ELSEIF(WIN32) | ||
135 | 92 | SET(MANIFEST ${RESOURCE_DIR}/META-INF/MANIFEST-win32.MF) | ||
136 | 93 | #SET(CLASSPATH ${CLASSPATH}${SEP}${JINTELLITYPE_JAR}) | ||
137 | 94 | ELSE() | ||
138 | 95 | SET(MANIFEST ${RESOURCE_DIR}/META-INF/MANIFEST.MF) | ||
139 | 96 | ENDIF() | ||
140 | 97 | |||
141 | 98 | |||
142 | 99 | add_custom_target( ${JAR_FILE} | ||
143 | 100 | COMMAND ${JAVA_ARCHIVE} cfm ${BINARY_DIR}/${JAR_FILE} | ||
144 | 101 | ${MANIFEST} -C ${JAR_DIR} * | ||
145 | 102 | COMMAND ${CMAKE_COMMAND} -E copy ${BINARY_DIR}/${JAR_FILE} ${COMMON_LIB_DIR}/${JAR_FILE} | ||
146 | 103 | COMMENT "Packaging ${JAR_FILE}" | ||
147 | 104 | WORKING_DIRECTORY ${JAR_DIR} | ||
148 | 105 | ) | ||
149 | 106 | |||
150 | 107 | add_custom_target( ${JAR_FILE}.resources | ||
151 | 108 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCE_DIR} ${JAR_DIR} | ||
152 | 109 | COMMENT "Copying IDE resources" | ||
153 | 110 | ) | ||
154 | 111 | |||
155 | 112 | add_custom_target( ${JAR_FILE}.prepare | ||
156 | 113 | COMMENT "Preparing ${JAR_FILE}" | ||
157 | 114 | ) | ||
158 | 115 | |||
159 | 116 | add_custom_target( run-user | ||
160 | 117 | COMMAND ${JAVA_RUNTIME} ${RUN_USER_ARGS} | ||
161 | 118 | -classpath "${CLASSPATH}${SEP}${JAR_DIR}" | ||
162 | 119 | ${MAIN_CLASS} ${ARGS} | ||
163 | 120 | ) | ||
164 | 121 | |||
165 | 122 | add_custom_target( run | ||
166 | 123 | COMMAND ${JAVA_RUNTIME} ${RUN_ARGS} | ||
167 | 124 | -classpath "${CLASSPATH}${SEP}${JAR_DIR}" | ||
168 | 125 | ${MAIN_CLASS} ${ARGS} | ||
169 | 126 | ) | ||
170 | 127 | |||
171 | 128 | if(NOT DEFINED SIKULI_VERSION OR SIKULI_VERSION STREQUAL "") | ||
172 | 129 | file(READ ${BASE_DIR}/latest-ver SIKULI_VERSION) | ||
173 | 130 | STRING(STRIP ${SIKULI_VERSION} SIKULI_VERSION) | ||
174 | 131 | ENDIF() | ||
175 | 132 | message("Sikuli Version ${SIKULI_VERSION}") | ||
176 | 133 | |||
177 | 134 | SET(JYTHON_CLASS org.python.util.jython) | ||
178 | 135 | add_custom_target( update-version | ||
179 | 136 | COMMAND ${JAVA_RUNTIME} -cp "${CLASSPATH}" ${JYTHON_CLASS} ${BASE_DIR}/../utils/update-version.py ${JAVA_SRC_DIR}/org/sikuli/ide/IDESettings.java "${SIKULI_VERSION}" | ||
180 | 137 | COMMENT "Update version number in Sikuli-IDE" | ||
181 | 138 | ) | ||
182 | 139 | |||
183 | 140 | SET(INCLUDE_JARS ${SIKULI_SCRIPT_JAR} ${JUNIT_JAR} | ||
184 | 141 | ${SWING_LAYOUT_JAR} ${COMMONS_CLI_JAR} | ||
185 | 142 | ${BINARY_DIR}/${JAR_FILE} ${JSON_SIMPLE_JAR} | ||
186 | 143 | ${SWINGX_JAR} ${MAC_WIDGETS_JAR} ${FORMS_JAR} | ||
187 | 144 | ) | ||
188 | 145 | |||
189 | 146 | ## Windows Package | ||
190 | 147 | |||
191 | 148 | IF(WIN32) | ||
192 | 149 | SET(OS "win32") | ||
193 | 150 | SET(APP_FILE "Sikuli-IDE") | ||
194 | 151 | SET(BINARY_APP_DIR "${BINARY_DIR}/${OS}") | ||
195 | 152 | SET(JAR_IN_APP_DIR ${BINARY_APP_DIR}/${APP_FILE}) | ||
196 | 153 | SET(FRAMEWORKS_IN_APP_DIR ${JAR_IN_APP_DIR}/libs) | ||
197 | 154 | SET(JAR_LIB_DIR ${JAR_DIR}/META-INF/lib) | ||
198 | 155 | |||
199 | 156 | #LIST(APPEND INCLUDE_JARS ${JINTELLITYPE_JAR}) | ||
200 | 157 | FILE(GLOB sikuli_script_jnilibs "${BASE_DIR}/../sikuli-script/target/lib/*.dll") | ||
201 | 158 | SET(jnilibs ${sikuli_script_jnilibs}) | ||
202 | 159 | ENDIF() | ||
203 | 160 | |||
204 | 161 | ## Linux Package | ||
205 | 162 | |||
206 | 163 | IF(LINUX) | ||
207 | 164 | SET(OS "linux") | ||
208 | 165 | SET(APP_FILE "Sikuli-IDE") | ||
209 | 166 | SET(BINARY_APP_DIR "${BINARY_DIR}/${OS}") | ||
210 | 167 | SET(JAR_IN_APP_DIR ${BINARY_APP_DIR}/${APP_FILE}) | ||
211 | 168 | SET(FRAMEWORKS_IN_APP_DIR ${JAR_IN_APP_DIR}/libs) | ||
212 | 169 | SET(JAR_LIB_DIR ${JAR_DIR}/META-INF/lib) | ||
213 | 170 | |||
214 | 171 | #LIST(APPEND INCLUDE_JARS ${JXGRABKEY_JAR}) | ||
215 | 172 | SET(jnilibs "") | ||
216 | 173 | FILE(GLOB sikuli_script_jnilibs "${BASE_DIR}/../sikuli-script/target/lib/*.so") | ||
217 | 174 | LIST(APPEND jnilibs ${sikuli_script_jnilibs}) | ||
218 | 175 | ENDIF(LINUX) | ||
219 | 176 | |||
220 | 177 | ## Sikuli-IDE.App for Mac OS X | ||
221 | 178 | |||
222 | 179 | IF(APPLE) | ||
223 | 180 | IF(APPLE_SNOW_LEOPARD) | ||
224 | 181 | SET(OSX_VER "osx-10.6") | ||
225 | 182 | ELSEIF(APPLE_LEOPARD) | ||
226 | 183 | SET(OSX_VER "osx-10.5") | ||
227 | 184 | ENDIF() | ||
228 | 185 | SET(OS ${OSX_VER}) | ||
229 | 186 | |||
230 | 187 | SET(APP_FILE "Sikuli-IDE.app") | ||
231 | 188 | SET(BINARY_APP_DIR "${BINARY_DIR}/${OS}") | ||
232 | 189 | SET(JAR_IN_APP_DIR ${BINARY_APP_DIR}/${APP_FILE}/Contents/Resources/Java) | ||
233 | 190 | SET(FRAMEWORKS_IN_APP_DIR ${BINARY_APP_DIR}/${APP_FILE}/Contents/Frameworks) | ||
234 | 191 | |||
235 | 192 | FIND_PACKAGE(OpenCV REQUIRED) | ||
236 | 193 | #message("opencv lib: ${OpenCV_LIB_DIR}") | ||
237 | 194 | LIST(APPEND CMAKE_LIBRARY_PATH ${OpenCV_LIB_DIR}) | ||
238 | 195 | |||
239 | 196 | FILE(GLOB jnilibs "${BINARY_LIB_DIR}/*.jnilib") | ||
240 | 197 | FILE(GLOB sikuli_script_jnilibs "${BASE_DIR}/../sikuli-script/target/lib/*.jnilib") | ||
241 | 198 | LIST(APPEND jnilibs ${sikuli_script_jnilibs}) | ||
242 | 199 | |||
243 | 200 | find_dep_libs("${jnilibs}" deplibs) | ||
244 | 201 | find_dep_libs("${deplibs}" deplibs) | ||
245 | 202 | #MESSAGE("Dep: ${deplibs}") | ||
246 | 203 | |||
247 | 204 | ENDIF(APPLE) | ||
248 | 205 | |||
249 | 206 | SET(RELEASE_FILE "Sikuli-${SIKULI_VERSION}-${OS}") | ||
250 | 207 | |||
251 | 208 | ## Packaging App | ||
252 | 209 | add_custom_target( ${APP_FILE} | ||
253 | 210 | COMMENT "Generate ${BINARY_DIR}/${APP_FILE}" | ||
254 | 211 | ) | ||
255 | 212 | |||
256 | 213 | add_dependencies( ${APP_FILE} ${JAR_FILE} ) | ||
257 | 214 | |||
258 | 215 | IF(LINUX) | ||
259 | 216 | EXEC_PROGRAM(uname ARGS -m OUTPUT_VARIABLE SYSTEM_ARCH) | ||
260 | 217 | SET(RELEASE_FILE "${RELEASE_FILE}-${SYSTEM_ARCH}") | ||
261 | 218 | if(SYSTEM_ARCH MATCHES "x86_64") | ||
262 | 219 | SET(LIB_GRABKEY "${COMMON_LIB_DIR}/jxgrabkey/lib/libJXGrabKey-64.so") | ||
263 | 220 | else() | ||
264 | 221 | SET(LIB_GRABKEY "${COMMON_LIB_DIR}/jxgrabkey/lib/libJXGrabKey-32.so") | ||
265 | 222 | endif() | ||
266 | 223 | |||
267 | 224 | add_custom_target( ${APP_FILE}.framework | ||
268 | 225 | COMMAND ${CMAKE_COMMAND} -E make_directory ${FRAMEWORKS_IN_APP_DIR} | ||
269 | 226 | COMMAND cp ${jnilibs} ${FRAMEWORKS_IN_APP_DIR} | ||
270 | 227 | COMMENT "Packaging Frameworks in App" | ||
271 | 228 | ) | ||
272 | 229 | add_dependencies( ${APP_FILE} ${APP_FILE}.framework ) | ||
273 | 230 | |||
274 | 231 | ENDIF(LINUX) | ||
275 | 232 | |||
276 | 233 | IF(WIN32) | ||
277 | 234 | SET(APP_FILES Sikuli-IDE-w.bat Sikuli-IDE.bat Sikuli-IDE.exe ide-icon.ico) | ||
278 | 235 | SET(WIN32_LIBS ${COMMON_LIB_DIR}/win32) | ||
279 | 236 | SET(OPENCV_LIBS cv210 cvaux210 cxcore210 highgui210 ml210) | ||
280 | 237 | |||
281 | 238 | SET(LIB_GRABKEY "${COMMON_LIB_DIR}/jintellitype-1.3.6/JIntellitype.dll") | ||
282 | 239 | add_custom_target( ${JAR_FILE}.framework | ||
283 | 240 | COMMAND ${CMAKE_COMMAND} -E make_directory ${JAR_LIB_DIR} | ||
284 | 241 | #COMMAND ${CMAKE_COMMAND} -E copy ${LIB_GRABKEY} ${JAR_LIB_DIR}/ | ||
285 | 242 | COMMENT "Packaging Frameworks in Jar" | ||
286 | 243 | ) | ||
287 | 244 | add_dependencies( ${JAR_FILE} ${JAR_FILE}.framework ) | ||
288 | 245 | |||
289 | 246 | add_custom_target( ${APP_FILE}.framework | ||
290 | 247 | COMMAND ${CMAKE_COMMAND} -E make_directory ${FRAMEWORKS_IN_APP_DIR} | ||
291 | 248 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${WIN32_LIBS} ${FRAMEWORKS_IN_APP_DIR} | ||
292 | 249 | COMMENT "Packaging Frameworks in App" | ||
293 | 250 | ) | ||
294 | 251 | add_dependencies( ${APP_FILE} ${APP_FILE}.framework ) | ||
295 | 252 | |||
296 | 253 | #libs | ||
297 | 254 | |||
298 | 255 | install(FILES ${jnilibs} | ||
299 | 256 | DESTINATION ${FRAMEWORKS_IN_APP_DIR}) | ||
300 | 257 | FOREACH(F ${OPENCV_LIBS}) | ||
301 | 258 | install(FILES ${OpenCV_DIR}/bin/${F}.dll | ||
302 | 259 | DESTINATION ${FRAMEWORKS_IN_APP_DIR}) | ||
303 | 260 | ENDFOREACH() | ||
304 | 261 | |||
305 | 262 | FOREACH(F ${APP_FILES}) | ||
306 | 263 | install(FILES ${BINARY_APP_DIR}/${F} | ||
307 | 264 | DESTINATION ${JAR_IN_APP_DIR}) | ||
308 | 265 | |||
309 | 266 | ENDFOREACH() | ||
310 | 267 | ENDIF(WIN32) | ||
311 | 268 | |||
312 | 269 | IF(APPLE) | ||
313 | 270 | add_custom_target( ${APP_FILE}.framework | ||
314 | 271 | COMMAND ${CMAKE_COMMAND} -E make_directory ${FRAMEWORKS_IN_APP_DIR} | ||
315 | 272 | COMMAND cp -f ${jnilibs} ${FRAMEWORKS_IN_APP_DIR} | ||
316 | 273 | COMMAND cp -f ${deplibs} ${FRAMEWORKS_IN_APP_DIR} | ||
317 | 274 | COMMAND ${CMAKE_COMMAND} -E chdir ${FRAMEWORKS_IN_APP_DIR} ./change-lib-path.sh | ||
318 | 275 | COMMENT "Packaging Frameworks" | ||
319 | 276 | ) | ||
320 | 277 | |||
321 | 278 | add_custom_target( ${APP_FILE}.update_ver | ||
322 | 279 | COMMAND defaults write ${BINARY_APP_DIR}/${APP_FILE}/Contents/Info CFBundleVersion `echo ${SIKULI_VERSION} | awk '{print $$1}'` | ||
323 | 280 | COMMAND plutil -convert xml1 ${BINARY_APP_DIR}/${APP_FILE}/Contents/Info.plist | ||
324 | 281 | ) | ||
325 | 282 | |||
326 | 283 | add_dependencies( ${APP_FILE} ${APP_FILE}.framework ${APP_FILE}.update_ver) | ||
327 | 284 | |||
328 | 285 | ENDIF(APPLE) | ||
329 | 286 | |||
330 | 287 | install(DIRECTORY ${BINARY_APP_DIR}/${APP_FILE} | ||
331 | 288 | USE_SOURCE_PERMISSIONS | ||
332 | 289 | DESTINATION . | ||
333 | 290 | ) | ||
334 | 291 | |||
335 | 292 | |||
336 | 293 | add_custom_target( app ALL | ||
337 | 294 | ) | ||
338 | 295 | |||
339 | 296 | |||
340 | 297 | FOREACH(JAR ${INCLUDE_JARS}) | ||
341 | 298 | get_filename_component(JAR_FILENAME ${JAR} NAME) | ||
342 | 299 | get_filename_component(target ${JAR} NAME_WE) | ||
343 | 300 | set(target "include_${target}") | ||
344 | 301 | add_custom_target( ${target} | ||
345 | 302 | COMMAND ${CMAKE_COMMAND} -E copy ${JAR} ${JAR_IN_APP_DIR}/${JAR_FILENAME} | ||
346 | 303 | |||
347 | 304 | COMMENT "Copying ${JAR_FILENAME}" | ||
348 | 305 | ) | ||
349 | 306 | add_dependencies( ${APP_FILE} ${target} ) | ||
350 | 307 | ENDFOREACH(JAR ${INCLUDE_JARS}) | ||
351 | 308 | |||
352 | 309 | |||
353 | 310 | add_dependencies( app ${APP_FILE}) | ||
354 | 311 | |||
355 | 312 | ## Language files | ||
356 | 313 | |||
357 | 314 | add_custom_target( update-po | ||
358 | 315 | COMMAND prop2po ${RESOURCE_DIR}/i18n/IDE_en_US.properties > ${RESOURCE_DIR}/i18n/IDE/IDE.pot | ||
359 | 316 | |||
360 | 317 | COMMENT "Update the IDE.pot file" | ||
361 | 318 | ) | ||
362 | 319 | |||
363 | 320 | add_custom_target( update-prop | ||
364 | 321 | COMMAND ${BASE_DIR}/../utils/update-prop.sh ${RESOURCE_DIR} | ||
365 | 322 | COMMENT "Update the IDE language properties." | ||
366 | 323 | ) | ||
367 | 324 | |||
368 | 325 | |||
369 | 326 | ## Packaging | ||
370 | 327 | |||
371 | 328 | if(APPLE) | ||
372 | 329 | SET(CPACK_GENERATOR DragNDrop ) | ||
373 | 330 | # SET(CPACK_GENERATOR ZIP ) | ||
374 | 331 | else(APPLE) | ||
375 | 332 | SET(CPACK_GENERATOR | ||
376 | 333 | ZIP | ||
377 | 334 | ) | ||
378 | 335 | endif(APPLE) | ||
379 | 336 | |||
380 | 337 | SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Sikuli ${SIKULI_VERSION}") | ||
381 | 338 | SET(CPACK_PACKAGE_VENDOR "Sikuli Development Team") | ||
382 | 339 | SET(CPACK_PACKAGE_DESCRIPTION_FILE "${BASE_DIR}/../readme.txt") | ||
383 | 340 | SET(CPACK_RESOURCE_FILE_LICENSE "${BASE_DIR}/../copyright.txt") | ||
384 | 341 | SET(CPACK_PACKAGE_FILE_NAME ${RELEASE_FILE}) | ||
385 | 342 | |||
386 | 343 | INCLUDE(CPack) | ||
387 | 344 | |||
388 | 345 | install(FILES | ||
389 | 346 | ${CPACK_PACKAGE_DESCRIPTION_FILE} | ||
390 | 347 | ${CPACK_RESOURCE_FILE_LICENSE} | ||
391 | 348 | DESTINATION . | ||
392 | 349 | ) | ||
393 | 350 | |||
394 | 351 | # type "make package" to generate release packages | ||
395 | 352 | |||
396 | 353 | |||
397 | 354 | ## tests | ||
398 | 355 | |||
399 | 356 | SET(MAIN_TEST_SUITE ${PACKAGE}.SikuliIDETestSuite) | ||
400 | 357 | |||
401 | 358 | add_custom_target( java-test.test-res | ||
402 | 359 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${BASE_DIR}/${TEST_RESOURCE_DIR} ${CMAKE_BINARY_DIR}/${TEST_RESOURCE_DIR} | ||
403 | 360 | COMMENT "Copy test resource" | ||
404 | 361 | ) | ||
405 | 362 | |||
406 | 363 | add_custom_target( java-test | ||
407 | 364 | # COMMAND ${JAVA_RUNTIME} -cp ${TEST_CLASS_DIR}${SEP}${BINARY_DIR}/${JAR_FILE}${SEP}${JUNIT_JAR} junit.textui.TestRunner ${MAIN_TEST_SUITE} | ||
408 | 365 | COMMAND ant -f ${JAVA_TEST_FOR_HUDSON_XML} | ||
409 | 366 | COMMENT "Run Java unit tests" | ||
410 | 367 | ) | ||
411 | 368 | |||
412 | 369 | add_dependencies( java-test | ||
413 | 370 | ${JAR_FILE} | ||
414 | 371 | ${PROJECT_NAME}.test.classes | ||
415 | 372 | java-test.test-res | ||
416 | 373 | ) | ||
417 | 374 | |||
418 | 375 | add_custom_target( all-test | ||
419 | 376 | ) | ||
420 | 377 | |||
421 | 378 | add_dependencies( all-test | ||
422 | 379 | java-test | ||
423 | 380 | ) | ||
424 | 381 | |||
425 | 382 | ## Dependencies | ||
426 | 383 | |||
427 | 384 | add_dependencies( ${JAR_FILE}.prepare | ||
428 | 385 | ${JAR_FILE}.resources | ||
429 | 386 | ${JAR_FILE}.classes-in-jar | ||
430 | 387 | # ${JAR_FILE}.libs-in-jar | ||
431 | 388 | ) | ||
432 | 389 | |||
433 | 390 | add_dependencies( ${JAR_FILE} ${JAR_FILE}.prepare ) | ||
434 | 391 | add_dependencies( run-user ${JAR_FILE}) | ||
435 | 392 | add_dependencies( run ${JAR_FILE}) | ||
436 | 393 | add_dependencies( app ${APP_FILE}) | ||
437 | 394 | |||
438 | 395 | |||
439 | 396 | ADD_SUBDIRECTORY( ${JAVA_SRC_DIR} ) | ||
440 | 397 | #ADD_SUBDIRECTORY( ${NATIVE_SRC_DIR} ) | ||
441 | 398 | ADD_SUBDIRECTORY( ${JAVA_TEST_DIR} ) | ||
442 | 399 | |||
443 | 400 | |||
444 | 401 | |||
445 | 402 | SET(SIKULI_VERSION CACHE INTERNAL "" FORCE) | ||
446 | 403 | |||
447 | 404 | 0 | ||
448 | === removed directory '.pc/gcc-4.7.patch' | |||
449 | === removed directory '.pc/gcc-4.7.patch/sikuli-script' | |||
450 | === removed directory '.pc/gcc-4.7.patch/sikuli-script/src' | |||
451 | === removed directory '.pc/gcc-4.7.patch/sikuli-script/src/main' | |||
452 | === removed directory '.pc/gcc-4.7.patch/sikuli-script/src/main/native' | |||
453 | === removed file '.pc/gcc-4.7.patch/sikuli-script/src/main/native/sikuli-debug.h' | |||
454 | --- .pc/gcc-4.7.patch/sikuli-script/src/main/native/sikuli-debug.h 2012-05-11 23:51:05 +0000 | |||
455 | +++ .pc/gcc-4.7.patch/sikuli-script/src/main/native/sikuli-debug.h 1970-01-01 00:00:00 +0000 | |||
456 | @@ -1,52 +0,0 @@ | |||
457 | 1 | /* | ||
458 | 2 | * Copyright 2010-2011, Sikuli.org | ||
459 | 3 | * Released under the MIT License. | ||
460 | 4 | * | ||
461 | 5 | */ | ||
462 | 6 | #ifndef _SIKULU_DEBUG_H | ||
463 | 7 | #define _SIKULI_DEBUG_H | ||
464 | 8 | |||
465 | 9 | |||
466 | 10 | #include <streambuf> | ||
467 | 11 | #include <ostream> | ||
468 | 12 | |||
469 | 13 | namespace sikuli{ | ||
470 | 14 | enum DebugCategories { | ||
471 | 15 | OCR, FINDER | ||
472 | 16 | }; | ||
473 | 17 | void setDebug(DebugCategories cat, int level); | ||
474 | 18 | |||
475 | 19 | extern int OCR_DEBUG_LEVEL; | ||
476 | 20 | extern int FINDER_DEBUG_LEVEL; | ||
477 | 21 | |||
478 | 22 | template <class cT, class traits = std::char_traits<cT> > | ||
479 | 23 | class basic_nullbuf: public std::basic_streambuf<cT, traits> { | ||
480 | 24 | typename traits::int_type overflow(typename traits::int_type c) | ||
481 | 25 | { | ||
482 | 26 | return traits::not_eof(c); // indicate success | ||
483 | 27 | } | ||
484 | 28 | }; | ||
485 | 29 | |||
486 | 30 | template <class cT, class traits = std::char_traits<cT> > | ||
487 | 31 | class basic_onullstream: public std::basic_ostream<cT, traits> { | ||
488 | 32 | public: | ||
489 | 33 | basic_onullstream(): | ||
490 | 34 | std::basic_ios<cT, traits>(&m_sbuf), | ||
491 | 35 | std::basic_ostream<cT, traits>(&m_sbuf) | ||
492 | 36 | { | ||
493 | 37 | init(&m_sbuf); | ||
494 | 38 | } | ||
495 | 39 | |||
496 | 40 | private: | ||
497 | 41 | basic_nullbuf<cT, traits> m_sbuf; | ||
498 | 42 | }; | ||
499 | 43 | |||
500 | 44 | typedef basic_onullstream<char> onullstream; | ||
501 | 45 | typedef basic_onullstream<wchar_t> wonullstream; | ||
502 | 46 | |||
503 | 47 | std::ostream& dout(const char* name=""); | ||
504 | 48 | std::ostream& dhead(const char* name); | ||
505 | 49 | |||
506 | 50 | } | ||
507 | 51 | |||
508 | 52 | #endif | ||
509 | 53 | 0 | ||
510 | === removed directory '.pc/install-extension.patch' | |||
511 | === removed directory '.pc/install-extension.patch/sikuli-script' | |||
512 | === removed directory '.pc/install-extension.patch/sikuli-script/src' | |||
513 | === removed directory '.pc/install-extension.patch/sikuli-script/src/main' | |||
514 | === removed directory '.pc/install-extension.patch/sikuli-script/src/main/java' | |||
515 | === removed directory '.pc/install-extension.patch/sikuli-script/src/main/java/org' | |||
516 | === removed directory '.pc/install-extension.patch/sikuli-script/src/main/java/org/sikuli' | |||
517 | === removed directory '.pc/install-extension.patch/sikuli-script/src/main/java/org/sikuli/script' | |||
518 | === removed file '.pc/install-extension.patch/sikuli-script/src/main/java/org/sikuli/script/ExtensionManager.java' | |||
519 | --- .pc/install-extension.patch/sikuli-script/src/main/java/org/sikuli/script/ExtensionManager.java 2011-10-04 00:57:09 +0000 | |||
520 | +++ .pc/install-extension.patch/sikuli-script/src/main/java/org/sikuli/script/ExtensionManager.java 1970-01-01 00:00:00 +0000 | |||
521 | @@ -1,175 +0,0 @@ | |||
522 | 1 | /* | ||
523 | 2 | * Copyright 2010-2011, Sikuli.org | ||
524 | 3 | * Released under the MIT License. | ||
525 | 4 | * | ||
526 | 5 | */ | ||
527 | 6 | package org.sikuli.script; | ||
528 | 7 | |||
529 | 8 | import java.io.*; | ||
530 | 9 | import java.net.URL; | ||
531 | 10 | import java.util.ArrayList; | ||
532 | 11 | |||
533 | 12 | class Extension implements Serializable{ | ||
534 | 13 | public String name; | ||
535 | 14 | public String url; | ||
536 | 15 | public String version; | ||
537 | 16 | |||
538 | 17 | public Extension(String name_, String url_, String version_){ | ||
539 | 18 | name = name_; | ||
540 | 19 | url = url_; | ||
541 | 20 | version = version_; | ||
542 | 21 | } | ||
543 | 22 | } | ||
544 | 23 | |||
545 | 24 | public class ExtensionManager { | ||
546 | 25 | protected final static String EXT_LIST_FILE = ".ext-list"; | ||
547 | 26 | protected static ExtensionManager _instance = null; | ||
548 | 27 | protected File _extListFile; | ||
549 | 28 | protected ArrayList<Extension> _extensions; | ||
550 | 29 | |||
551 | 30 | public static ExtensionManager getInstance(){ | ||
552 | 31 | if(_instance == null) | ||
553 | 32 | _instance = new ExtensionManager(); | ||
554 | 33 | return _instance; | ||
555 | 34 | } | ||
556 | 35 | |||
557 | 36 | protected void readExtList() { | ||
558 | 37 | try{ | ||
559 | 38 | FileInputStream fis = new FileInputStream(_extListFile); | ||
560 | 39 | ObjectInputStream in = new ObjectInputStream(fis); | ||
561 | 40 | _extensions = (ArrayList<Extension>)in.readObject(); | ||
562 | 41 | in.close(); | ||
563 | 42 | } | ||
564 | 43 | catch(Exception e){ | ||
565 | 44 | _extensions = new ArrayList<Extension>(); | ||
566 | 45 | } | ||
567 | 46 | } | ||
568 | 47 | |||
569 | 48 | protected void updateExtList() throws IOException, ClassNotFoundException{ | ||
570 | 49 | FileOutputStream fos = new FileOutputStream(_extListFile); | ||
571 | 50 | ObjectOutputStream out = new ObjectOutputStream(fos); | ||
572 | 51 | out.writeObject(_extensions); | ||
573 | 52 | out.close(); | ||
574 | 53 | } | ||
575 | 54 | |||
576 | 55 | protected ExtensionManager(){ | ||
577 | 56 | _extListFile = new File(getUserExtPath(),EXT_LIST_FILE); | ||
578 | 57 | readExtList(); | ||
579 | 58 | } | ||
580 | 59 | |||
581 | 60 | |||
582 | 61 | protected Extension find(String name){ | ||
583 | 62 | for(Extension e : _extensions){ | ||
584 | 63 | if(e.name.equals(name)) | ||
585 | 64 | return e; | ||
586 | 65 | } | ||
587 | 66 | return null; | ||
588 | 67 | } | ||
589 | 68 | |||
590 | 69 | protected void addExtension(String name, String url, String version){ | ||
591 | 70 | |||
592 | 71 | // remove the previously installed extension of the same name | ||
593 | 72 | Extension old_ext = find(name); | ||
594 | 73 | if (old_ext != null) | ||
595 | 74 | _extensions.remove(old_ext); | ||
596 | 75 | |||
597 | 76 | Extension ext = new Extension(name, url, version); | ||
598 | 77 | _extensions.add(ext); | ||
599 | 78 | |||
600 | 79 | try{ | ||
601 | 80 | updateExtList(); | ||
602 | 81 | } | ||
603 | 82 | catch(Exception e){ | ||
604 | 83 | e.printStackTrace(); | ||
605 | 84 | } | ||
606 | 85 | } | ||
607 | 86 | |||
608 | 87 | |||
609 | 88 | public String getVersion(String name){ | ||
610 | 89 | Extension e = find(name); | ||
611 | 90 | if (e != null){ | ||
612 | 91 | return e.version; | ||
613 | 92 | }else{ | ||
614 | 93 | return null; | ||
615 | 94 | } | ||
616 | 95 | } | ||
617 | 96 | |||
618 | 97 | public boolean isOutOfDate(String name, String version){ | ||
619 | 98 | Extension e = find(name); | ||
620 | 99 | if (e == null){ | ||
621 | 100 | return false; | ||
622 | 101 | }else{ | ||
623 | 102 | String s1 = normalisedVersion(e.version); // installed version | ||
624 | 103 | String s2 = normalisedVersion(version); // version number to check | ||
625 | 104 | int cmp = s1.compareTo(s2); | ||
626 | 105 | return cmp < 0; | ||
627 | 106 | } | ||
628 | 107 | } | ||
629 | 108 | |||
630 | 109 | public boolean isInstalled(String name){ | ||
631 | 110 | Extension e = find(name); | ||
632 | 111 | return e != null; | ||
633 | 112 | } | ||
634 | 113 | |||
635 | 114 | private String getExtName(String nameWithVer){ | ||
636 | 115 | int verSep = nameWithVer.lastIndexOf("-"); | ||
637 | 116 | if(verSep>=0){ | ||
638 | 117 | return nameWithVer.substring(0, verSep) + ".jar"; | ||
639 | 118 | } | ||
640 | 119 | return nameWithVer; | ||
641 | 120 | } | ||
642 | 121 | |||
643 | 122 | /** | ||
644 | 123 | * install a Sikuli extension (.JAR) | ||
645 | 124 | */ | ||
646 | 125 | public boolean install(String name, String url_, String version_){ | ||
647 | 126 | String extPath = getUserExtPath(); | ||
648 | 127 | String tmpdir = System.getProperty("java.io.tmpdir"); | ||
649 | 128 | try{ | ||
650 | 129 | URL url = new URL(url_); | ||
651 | 130 | File localFile = new File(Util.downloadURL(url, tmpdir)); | ||
652 | 131 | String extName = getExtName(localFile.getName()); | ||
653 | 132 | File targetFile = new File(extPath, extName); | ||
654 | 133 | if(targetFile.exists()) | ||
655 | 134 | targetFile.delete(); | ||
656 | 135 | if( !localFile.renameTo(targetFile) ){ | ||
657 | 136 | Debug.error("Failed to install " + localFile.getName() + " to " + targetFile.getAbsolutePath()); | ||
658 | 137 | return false; | ||
659 | 138 | } | ||
660 | 139 | addExtension(name, url_, version_); | ||
661 | 140 | } | ||
662 | 141 | catch(IOException e){ | ||
663 | 142 | Debug.error("Failed to download " + url_); | ||
664 | 143 | e.printStackTrace(); | ||
665 | 144 | return false; | ||
666 | 145 | } | ||
667 | 146 | return true; | ||
668 | 147 | } | ||
669 | 148 | |||
670 | 149 | /** | ||
671 | 150 | * returns the absolute path to the user's extension path | ||
672 | 151 | */ | ||
673 | 152 | public String getUserExtPath(){ | ||
674 | 153 | String ret = Env.getSikuliDataPath() + File.separator + "extensions"; | ||
675 | 154 | File f = new File(ret); | ||
676 | 155 | if(!f.exists()) | ||
677 | 156 | f.mkdirs(); | ||
678 | 157 | return ret; | ||
679 | 158 | } | ||
680 | 159 | |||
681 | 160 | |||
682 | 161 | |||
683 | 162 | public static String normalisedVersion(String version) { | ||
684 | 163 | return normalisedVersion(version, ".", 4); | ||
685 | 164 | } | ||
686 | 165 | |||
687 | 166 | public static String normalisedVersion(String version, String sep, int maxWidth) { | ||
688 | 167 | String[] split = java.util.regex.Pattern.compile(sep, java.util.regex.Pattern.LITERAL).split(version); | ||
689 | 168 | StringBuilder sb = new StringBuilder(); | ||
690 | 169 | for (String s : split) { | ||
691 | 170 | sb.append(String.format("%" + maxWidth + 's', s)); | ||
692 | 171 | } | ||
693 | 172 | return sb.toString(); | ||
694 | 173 | } | ||
695 | 174 | |||
696 | 175 | } | ||
697 | 176 | 0 | ||
698 | === removed directory '.pc/jgoodies-1.6-compat.patch' | |||
699 | === removed directory '.pc/jgoodies-1.6-compat.patch/sikuli-ide' | |||
700 | === removed file '.pc/jgoodies-1.6-compat.patch/sikuli-ide/CMakeLists.txt' | |||
701 | --- .pc/jgoodies-1.6-compat.patch/sikuli-ide/CMakeLists.txt 2012-12-07 22:13:08 +0000 | |||
702 | +++ .pc/jgoodies-1.6-compat.patch/sikuli-ide/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
703 | @@ -1,405 +0,0 @@ | |||
704 | 1 | # Copyright 2010-2011, Sikuli.org | ||
705 | 2 | # Released under the MIT License. | ||
706 | 3 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) | ||
707 | 4 | PROJECT (sikuli-ide Java) | ||
708 | 5 | |||
709 | 6 | SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake_modules") | ||
710 | 7 | INCLUDE(${CMAKE_MODULE_PATH}/common.cmake) | ||
711 | 8 | INCLUDE(${CMAKE_MODULE_PATH}/detect_osx_ver.cmake) | ||
712 | 9 | INCLUDE(${CMAKE_MODULE_PATH}/find_dep_libs.cmake) | ||
713 | 10 | |||
714 | 11 | |||
715 | 12 | ENABLE_TESTING() | ||
716 | 13 | |||
717 | 14 | SET(CMAKE_VERBOSE_MAKEFILE 0) | ||
718 | 15 | |||
719 | 16 | FIND_PACKAGE(Java 1.6 REQUIRED) | ||
720 | 17 | SET( NON_NATIVE_TARGET TRUE) | ||
721 | 18 | |||
722 | 19 | IF(UNIX) | ||
723 | 20 | SET(SEP ":") | ||
724 | 21 | ELSE() | ||
725 | 22 | SET(SEP ";") | ||
726 | 23 | ENDIF() | ||
727 | 24 | |||
728 | 25 | |||
729 | 26 | SET(BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") | ||
730 | 27 | SET(JAVA_SRC_DIR "${BASE_DIR}/src/main/java") | ||
731 | 28 | SET(NATIVE_SRC_DIR "${BASE_DIR}/src/main/native") | ||
732 | 29 | SET(COMMON_LIB_DIR "${BASE_DIR}/../lib") | ||
733 | 30 | SET(INCLUDE_LIB_DIR "${BASE_DIR}/lib") | ||
734 | 31 | SET(BINARY_DIR "${BASE_DIR}/target") | ||
735 | 32 | SET(BINARY_CLASS_DIR "${BINARY_DIR}/classes") | ||
736 | 33 | SET(BINARY_LIB_DIR "${BINARY_DIR}/lib") | ||
737 | 34 | SET(JAR_DIR "${BINARY_DIR}/jar") | ||
738 | 35 | SET(RESOURCE_DIR "${BASE_DIR}/resources") | ||
739 | 36 | SET(RELEASE_DIR "${BASE_DIR}/../release") | ||
740 | 37 | |||
741 | 38 | SET(JAVA_TEST_DIR "${BASE_DIR}/src/test/java") | ||
742 | 39 | SET(TEST_RESOURCE_DIR "test-res") | ||
743 | 40 | SET(JAVA_TEST_FOR_HUDSON_XML "../hudson-test.xml") | ||
744 | 41 | SET(TEST_CLASS_DIR "${CMAKE_BINARY_DIR}/test") | ||
745 | 42 | |||
746 | 43 | SET(SIKULI_SCRIPT_JAR "${COMMON_LIB_DIR}/sikuli-script.jar") | ||
747 | 44 | SET(JUNIT_JAR "/usr/share/java/junit.jar") | ||
748 | 45 | SET(SWING_LAYOUT_JAR "/usr/share/java/swing-layout.jar") | ||
749 | 46 | SET(COMMONS_CLI_JAR "/usr/share/java/commons-cli.jar") | ||
750 | 47 | SET(JSON_SIMPLE_JAR "/usr/share/java/json_simple.jar") | ||
751 | 48 | SET(SWINGX_JAR "/usr/share/java/swingx-core.jar") | ||
752 | 49 | SET(MAC_WIDGETS_JAR "/usr/share/java/mac_widgets.jar") | ||
753 | 50 | SET(FORMS_JAR "/usr/share/java/forms.jar") | ||
754 | 51 | |||
755 | 52 | |||
756 | 53 | FILE(MAKE_DIRECTORY ${BINARY_DIR}) | ||
757 | 54 | FILE(MAKE_DIRECTORY ${BINARY_CLASS_DIR}) | ||
758 | 55 | FILE(MAKE_DIRECTORY ${JAR_DIR}) | ||
759 | 56 | FILE(MAKE_DIRECTORY ${TEST_CLASS_DIR}) | ||
760 | 57 | |||
761 | 58 | ## Sikuli IDE | ||
762 | 59 | |||
763 | 60 | SET(MAIN_CLASS org.sikuli.ide.SikuliIDE) | ||
764 | 61 | SET(RUN_USER_ARGS -Dsikuli.console=true -Dfile.encoding=UTF-8 | ||
765 | 62 | -Dsikuli.testing=yes | ||
766 | 63 | -Xms64m -Xmx512m | ||
767 | 64 | CACHE STRING | ||
768 | 65 | "The arguments for running Sikuli IDE with 'make run-user'" | ||
769 | 66 | ) | ||
770 | 67 | SET(RUN_ARGS -Dsikuli.console=false -Dsikuli.Debug=3 -Dfile.encoding=UTF-8 | ||
771 | 68 | -Dsikuli.testing=yes | ||
772 | 69 | -Xms64m -Xmx512m | ||
773 | 70 | #-Duser.language=zh -Duser.region=TW | ||
774 | 71 | CACHE STRING | ||
775 | 72 | "The arguments for running Sikuli IDE with 'make run'" | ||
776 | 73 | ) | ||
777 | 74 | IF(APPLE) | ||
778 | 75 | LIST(APPEND RUN_ARGS -Xdock:name='Sikuli IDE') | ||
779 | 76 | ENDIF() | ||
780 | 77 | |||
781 | 78 | #SET(ARGS -s -r ../sample-scripts/mod1.sikuli --args a1 a2) # example args | ||
782 | 79 | SET(ARGS "") | ||
783 | 80 | |||
784 | 81 | SET(CLASSPATH | ||
785 | 82 | ${SIKULI_SCRIPT_JAR}${SEP}${JUNIT_JAR}${SEP}${SWING_LAYOUT_JAR}${SEP}${COMMONS_CLI_JAR}${SEP}${JSON_SIMPLE_JAR}${SEP}${SWINGX_JAR}${SEP}${MAC_WIDGETS_JAR}${SEP}${FORMS_JAR}${SEP}/usr/share/java/jython.jar | ||
786 | 83 | ) | ||
787 | 84 | |||
788 | 85 | SET(JAR_FILE sikuli-ide.jar) | ||
789 | 86 | SET(RESOURCES icons META-INF scripts i18n) | ||
790 | 87 | |||
791 | 88 | IF(LINUX) | ||
792 | 89 | SET(MANIFEST ${RESOURCE_DIR}/META-INF/MANIFEST-linux.MF) | ||
793 | 90 | #SET(CLASSPATH ${CLASSPATH}${SEP}${JXGRABKEY_JAR}) | ||
794 | 91 | ELSEIF(WIN32) | ||
795 | 92 | SET(MANIFEST ${RESOURCE_DIR}/META-INF/MANIFEST-win32.MF) | ||
796 | 93 | #SET(CLASSPATH ${CLASSPATH}${SEP}${JINTELLITYPE_JAR}) | ||
797 | 94 | ELSE() | ||
798 | 95 | SET(MANIFEST ${RESOURCE_DIR}/META-INF/MANIFEST.MF) | ||
799 | 96 | ENDIF() | ||
800 | 97 | |||
801 | 98 | |||
802 | 99 | add_custom_target( ${JAR_FILE} | ||
803 | 100 | COMMAND ${JAVA_ARCHIVE} cfm ${BINARY_DIR}/${JAR_FILE} | ||
804 | 101 | ${MANIFEST} -C ${JAR_DIR} * | ||
805 | 102 | COMMAND ${CMAKE_COMMAND} -E copy ${BINARY_DIR}/${JAR_FILE} ${COMMON_LIB_DIR}/${JAR_FILE} | ||
806 | 103 | COMMENT "Packaging ${JAR_FILE}" | ||
807 | 104 | WORKING_DIRECTORY ${JAR_DIR} | ||
808 | 105 | ) | ||
809 | 106 | |||
810 | 107 | add_custom_target( ${JAR_FILE}.resources | ||
811 | 108 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCE_DIR} ${JAR_DIR} | ||
812 | 109 | COMMENT "Copying IDE resources" | ||
813 | 110 | ) | ||
814 | 111 | |||
815 | 112 | add_custom_target( ${JAR_FILE}.prepare | ||
816 | 113 | COMMENT "Preparing ${JAR_FILE}" | ||
817 | 114 | ) | ||
818 | 115 | |||
819 | 116 | add_custom_target( run-user | ||
820 | 117 | COMMAND ${JAVA_RUNTIME} ${RUN_USER_ARGS} | ||
821 | 118 | -classpath "${CLASSPATH}${SEP}${JAR_DIR}" | ||
822 | 119 | ${MAIN_CLASS} ${ARGS} | ||
823 | 120 | ) | ||
824 | 121 | |||
825 | 122 | add_custom_target( run | ||
826 | 123 | COMMAND ${JAVA_RUNTIME} ${RUN_ARGS} | ||
827 | 124 | -classpath "${CLASSPATH}${SEP}${JAR_DIR}" | ||
828 | 125 | ${MAIN_CLASS} ${ARGS} | ||
829 | 126 | ) | ||
830 | 127 | |||
831 | 128 | if(NOT DEFINED SIKULI_VERSION OR SIKULI_VERSION STREQUAL "") | ||
832 | 129 | file(READ ${BASE_DIR}/latest-ver SIKULI_VERSION) | ||
833 | 130 | STRING(STRIP ${SIKULI_VERSION} SIKULI_VERSION) | ||
834 | 131 | ENDIF() | ||
835 | 132 | message("Sikuli Version ${SIKULI_VERSION}") | ||
836 | 133 | |||
837 | 134 | SET(JYTHON_CLASS org.python.util.jython) | ||
838 | 135 | add_custom_target( update-version | ||
839 | 136 | COMMAND ${JAVA_RUNTIME} -cp "${CLASSPATH}" ${JYTHON_CLASS} ${BASE_DIR}/../utils/update-version.py ${JAVA_SRC_DIR}/org/sikuli/ide/IDESettings.java "${SIKULI_VERSION}" | ||
840 | 137 | COMMENT "Update version number in Sikuli-IDE" | ||
841 | 138 | ) | ||
842 | 139 | |||
843 | 140 | SET(INCLUDE_JARS ${SIKULI_SCRIPT_JAR} ${JUNIT_JAR} | ||
844 | 141 | ${SWING_LAYOUT_JAR} ${COMMONS_CLI_JAR} | ||
845 | 142 | ${BINARY_DIR}/${JAR_FILE} ${JSON_SIMPLE_JAR} | ||
846 | 143 | ${SWINGX_JAR} ${MAC_WIDGETS_JAR} ${FORMS_JAR} | ||
847 | 144 | ) | ||
848 | 145 | |||
849 | 146 | ## Windows Package | ||
850 | 147 | |||
851 | 148 | IF(WIN32) | ||
852 | 149 | SET(OS "win32") | ||
853 | 150 | SET(APP_FILE "Sikuli-IDE") | ||
854 | 151 | SET(BINARY_APP_DIR "${BINARY_DIR}/${OS}") | ||
855 | 152 | SET(JAR_IN_APP_DIR ${BINARY_APP_DIR}/${APP_FILE}) | ||
856 | 153 | SET(FRAMEWORKS_IN_APP_DIR ${JAR_IN_APP_DIR}/libs) | ||
857 | 154 | SET(JAR_LIB_DIR ${JAR_DIR}/META-INF/lib) | ||
858 | 155 | |||
859 | 156 | #LIST(APPEND INCLUDE_JARS ${JINTELLITYPE_JAR}) | ||
860 | 157 | FILE(GLOB sikuli_script_jnilibs "${BASE_DIR}/../sikuli-script/target/lib/*.dll") | ||
861 | 158 | SET(jnilibs ${sikuli_script_jnilibs}) | ||
862 | 159 | ENDIF() | ||
863 | 160 | |||
864 | 161 | ## Linux Package | ||
865 | 162 | |||
866 | 163 | IF(LINUX) | ||
867 | 164 | SET(OS "linux") | ||
868 | 165 | SET(APP_FILE "Sikuli-IDE") | ||
869 | 166 | SET(BINARY_APP_DIR "${BINARY_DIR}/${OS}") | ||
870 | 167 | SET(JAR_IN_APP_DIR ${BINARY_APP_DIR}/${APP_FILE}) | ||
871 | 168 | SET(FRAMEWORKS_IN_APP_DIR ${JAR_IN_APP_DIR}/libs) | ||
872 | 169 | SET(JAR_LIB_DIR ${JAR_DIR}/META-INF/lib) | ||
873 | 170 | |||
874 | 171 | #LIST(APPEND INCLUDE_JARS ${JXGRABKEY_JAR}) | ||
875 | 172 | SET(jnilibs "") | ||
876 | 173 | FILE(GLOB sikuli_script_jnilibs "${BASE_DIR}/../sikuli-script/target/lib/*.so") | ||
877 | 174 | LIST(APPEND jnilibs ${sikuli_script_jnilibs}) | ||
878 | 175 | ENDIF(LINUX) | ||
879 | 176 | |||
880 | 177 | ## Sikuli-IDE.App for Mac OS X | ||
881 | 178 | |||
882 | 179 | IF(APPLE) | ||
883 | 180 | IF(APPLE_SNOW_LEOPARD) | ||
884 | 181 | SET(OSX_VER "osx-10.6") | ||
885 | 182 | ELSEIF(APPLE_LEOPARD) | ||
886 | 183 | SET(OSX_VER "osx-10.5") | ||
887 | 184 | ENDIF() | ||
888 | 185 | SET(OS ${OSX_VER}) | ||
889 | 186 | |||
890 | 187 | SET(APP_FILE "Sikuli-IDE.app") | ||
891 | 188 | SET(BINARY_APP_DIR "${BINARY_DIR}/${OS}") | ||
892 | 189 | SET(JAR_IN_APP_DIR ${BINARY_APP_DIR}/${APP_FILE}/Contents/Resources/Java) | ||
893 | 190 | SET(FRAMEWORKS_IN_APP_DIR ${BINARY_APP_DIR}/${APP_FILE}/Contents/Frameworks) | ||
894 | 191 | |||
895 | 192 | FIND_PACKAGE(OpenCV REQUIRED) | ||
896 | 193 | #message("opencv lib: ${OpenCV_LIB_DIR}") | ||
897 | 194 | LIST(APPEND CMAKE_LIBRARY_PATH ${OpenCV_LIB_DIR}) | ||
898 | 195 | |||
899 | 196 | FILE(GLOB jnilibs "${BINARY_LIB_DIR}/*.jnilib") | ||
900 | 197 | FILE(GLOB sikuli_script_jnilibs "${BASE_DIR}/../sikuli-script/target/lib/*.jnilib") | ||
901 | 198 | LIST(APPEND jnilibs ${sikuli_script_jnilibs}) | ||
902 | 199 | |||
903 | 200 | find_dep_libs("${jnilibs}" deplibs) | ||
904 | 201 | find_dep_libs("${deplibs}" deplibs) | ||
905 | 202 | #MESSAGE("Dep: ${deplibs}") | ||
906 | 203 | |||
907 | 204 | ENDIF(APPLE) | ||
908 | 205 | |||
909 | 206 | SET(RELEASE_FILE "Sikuli-${SIKULI_VERSION}-${OS}") | ||
910 | 207 | |||
911 | 208 | ## Packaging App | ||
912 | 209 | add_custom_target( ${APP_FILE} | ||
913 | 210 | COMMENT "Generate ${BINARY_DIR}/${APP_FILE}" | ||
914 | 211 | ) | ||
915 | 212 | |||
916 | 213 | add_dependencies( ${APP_FILE} ${JAR_FILE} ) | ||
917 | 214 | |||
918 | 215 | IF(LINUX) | ||
919 | 216 | EXEC_PROGRAM(uname ARGS -m OUTPUT_VARIABLE SYSTEM_ARCH) | ||
920 | 217 | SET(RELEASE_FILE "${RELEASE_FILE}-${SYSTEM_ARCH}") | ||
921 | 218 | if(SYSTEM_ARCH MATCHES "x86_64") | ||
922 | 219 | SET(LIB_GRABKEY "${COMMON_LIB_DIR}/jxgrabkey/lib/libJXGrabKey-64.so") | ||
923 | 220 | else() | ||
924 | 221 | SET(LIB_GRABKEY "${COMMON_LIB_DIR}/jxgrabkey/lib/libJXGrabKey-32.so") | ||
925 | 222 | endif() | ||
926 | 223 | |||
927 | 224 | add_custom_target( ${APP_FILE}.framework | ||
928 | 225 | COMMAND ${CMAKE_COMMAND} -E make_directory ${FRAMEWORKS_IN_APP_DIR} | ||
929 | 226 | COMMAND cp ${jnilibs} ${FRAMEWORKS_IN_APP_DIR} | ||
930 | 227 | COMMENT "Packaging Frameworks in App" | ||
931 | 228 | ) | ||
932 | 229 | add_dependencies( ${APP_FILE} ${APP_FILE}.framework ) | ||
933 | 230 | |||
934 | 231 | ENDIF(LINUX) | ||
935 | 232 | |||
936 | 233 | IF(WIN32) | ||
937 | 234 | SET(APP_FILES Sikuli-IDE-w.bat Sikuli-IDE.bat Sikuli-IDE.exe ide-icon.ico) | ||
938 | 235 | SET(WIN32_LIBS ${COMMON_LIB_DIR}/win32) | ||
939 | 236 | SET(OPENCV_LIBS cv210 cvaux210 cxcore210 highgui210 ml210) | ||
940 | 237 | |||
941 | 238 | SET(LIB_GRABKEY "${COMMON_LIB_DIR}/jintellitype-1.3.6/JIntellitype.dll") | ||
942 | 239 | add_custom_target( ${JAR_FILE}.framework | ||
943 | 240 | COMMAND ${CMAKE_COMMAND} -E make_directory ${JAR_LIB_DIR} | ||
944 | 241 | #COMMAND ${CMAKE_COMMAND} -E copy ${LIB_GRABKEY} ${JAR_LIB_DIR}/ | ||
945 | 242 | COMMENT "Packaging Frameworks in Jar" | ||
946 | 243 | ) | ||
947 | 244 | add_dependencies( ${JAR_FILE} ${JAR_FILE}.framework ) | ||
948 | 245 | |||
949 | 246 | add_custom_target( ${APP_FILE}.framework | ||
950 | 247 | COMMAND ${CMAKE_COMMAND} -E make_directory ${FRAMEWORKS_IN_APP_DIR} | ||
951 | 248 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${WIN32_LIBS} ${FRAMEWORKS_IN_APP_DIR} | ||
952 | 249 | COMMENT "Packaging Frameworks in App" | ||
953 | 250 | ) | ||
954 | 251 | add_dependencies( ${APP_FILE} ${APP_FILE}.framework ) | ||
955 | 252 | |||
956 | 253 | #libs | ||
957 | 254 | |||
958 | 255 | install(FILES ${jnilibs} | ||
959 | 256 | DESTINATION ${FRAMEWORKS_IN_APP_DIR}) | ||
960 | 257 | FOREACH(F ${OPENCV_LIBS}) | ||
961 | 258 | install(FILES ${OpenCV_DIR}/bin/${F}.dll | ||
962 | 259 | DESTINATION ${FRAMEWORKS_IN_APP_DIR}) | ||
963 | 260 | ENDFOREACH() | ||
964 | 261 | |||
965 | 262 | FOREACH(F ${APP_FILES}) | ||
966 | 263 | install(FILES ${BINARY_APP_DIR}/${F} | ||
967 | 264 | DESTINATION ${JAR_IN_APP_DIR}) | ||
968 | 265 | |||
969 | 266 | ENDFOREACH() | ||
970 | 267 | ENDIF(WIN32) | ||
971 | 268 | |||
972 | 269 | IF(APPLE) | ||
973 | 270 | add_custom_target( ${APP_FILE}.framework | ||
974 | 271 | COMMAND ${CMAKE_COMMAND} -E make_directory ${FRAMEWORKS_IN_APP_DIR} | ||
975 | 272 | COMMAND cp -f ${jnilibs} ${FRAMEWORKS_IN_APP_DIR} | ||
976 | 273 | COMMAND cp -f ${deplibs} ${FRAMEWORKS_IN_APP_DIR} | ||
977 | 274 | COMMAND ${CMAKE_COMMAND} -E chdir ${FRAMEWORKS_IN_APP_DIR} ./change-lib-path.sh | ||
978 | 275 | COMMENT "Packaging Frameworks" | ||
979 | 276 | ) | ||
980 | 277 | |||
981 | 278 | add_custom_target( ${APP_FILE}.update_ver | ||
982 | 279 | COMMAND defaults write ${BINARY_APP_DIR}/${APP_FILE}/Contents/Info CFBundleVersion `echo ${SIKULI_VERSION} | awk '{print $$1}'` | ||
983 | 280 | COMMAND plutil -convert xml1 ${BINARY_APP_DIR}/${APP_FILE}/Contents/Info.plist | ||
984 | 281 | ) | ||
985 | 282 | |||
986 | 283 | add_dependencies( ${APP_FILE} ${APP_FILE}.framework ${APP_FILE}.update_ver) | ||
987 | 284 | |||
988 | 285 | ENDIF(APPLE) | ||
989 | 286 | |||
990 | 287 | install(DIRECTORY ${BINARY_APP_DIR}/${APP_FILE} | ||
991 | 288 | USE_SOURCE_PERMISSIONS | ||
992 | 289 | DESTINATION . | ||
993 | 290 | ) | ||
994 | 291 | |||
995 | 292 | |||
996 | 293 | add_custom_target( app ALL | ||
997 | 294 | ) | ||
998 | 295 | |||
999 | 296 | |||
1000 | 297 | FOREACH(JAR ${INCLUDE_JARS}) | ||
1001 | 298 | get_filename_component(JAR_FILENAME ${JAR} NAME) | ||
1002 | 299 | get_filename_component(target ${JAR} NAME_WE) | ||
1003 | 300 | set(target "include_${target}") | ||
1004 | 301 | add_custom_target( ${target} | ||
1005 | 302 | COMMAND ${CMAKE_COMMAND} -E copy ${JAR} ${JAR_IN_APP_DIR}/${JAR_FILENAME} | ||
1006 | 303 | |||
1007 | 304 | COMMENT "Copying ${JAR_FILENAME}" | ||
1008 | 305 | ) | ||
1009 | 306 | add_dependencies( ${APP_FILE} ${target} ) | ||
1010 | 307 | ENDFOREACH(JAR ${INCLUDE_JARS}) | ||
1011 | 308 | |||
1012 | 309 | |||
1013 | 310 | get_filename_component(target ${JAR_FILE} NAME_WE) | ||
1014 | 311 | add_dependencies( include_${target} ${JAR_FILE}) | ||
1015 | 312 | add_dependencies( app ${APP_FILE}) | ||
1016 | 313 | |||
1017 | 314 | ## Language files | ||
1018 | 315 | |||
1019 | 316 | add_custom_target( update-po | ||
1020 | 317 | COMMAND prop2po ${RESOURCE_DIR}/i18n/IDE_en_US.properties > ${RESOURCE_DIR}/i18n/IDE/IDE.pot | ||
1021 | 318 | |||
1022 | 319 | COMMENT "Update the IDE.pot file" | ||
1023 | 320 | ) | ||
1024 | 321 | |||
1025 | 322 | add_custom_target( update-prop | ||
1026 | 323 | COMMAND ${BASE_DIR}/../utils/update-prop.sh ${RESOURCE_DIR} | ||
1027 | 324 | COMMENT "Update the IDE language properties." | ||
1028 | 325 | ) | ||
1029 | 326 | |||
1030 | 327 | |||
1031 | 328 | ## Packaging | ||
1032 | 329 | |||
1033 | 330 | if(APPLE) | ||
1034 | 331 | SET(CPACK_GENERATOR DragNDrop ) | ||
1035 | 332 | # SET(CPACK_GENERATOR ZIP ) | ||
1036 | 333 | else(APPLE) | ||
1037 | 334 | SET(CPACK_GENERATOR | ||
1038 | 335 | ZIP | ||
1039 | 336 | ) | ||
1040 | 337 | endif(APPLE) | ||
1041 | 338 | |||
1042 | 339 | SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Sikuli ${SIKULI_VERSION}") | ||
1043 | 340 | SET(CPACK_PACKAGE_VENDOR "Sikuli Development Team") | ||
1044 | 341 | SET(CPACK_PACKAGE_DESCRIPTION_FILE "${BASE_DIR}/../readme.txt") | ||
1045 | 342 | SET(CPACK_RESOURCE_FILE_LICENSE "${BASE_DIR}/../copyright.txt") | ||
1046 | 343 | SET(CPACK_PACKAGE_FILE_NAME ${RELEASE_FILE}) | ||
1047 | 344 | |||
1048 | 345 | INCLUDE(CPack) | ||
1049 | 346 | |||
1050 | 347 | install(FILES | ||
1051 | 348 | ${CPACK_PACKAGE_DESCRIPTION_FILE} | ||
1052 | 349 | ${CPACK_RESOURCE_FILE_LICENSE} | ||
1053 | 350 | DESTINATION . | ||
1054 | 351 | ) | ||
1055 | 352 | |||
1056 | 353 | # type "make package" to generate release packages | ||
1057 | 354 | |||
1058 | 355 | |||
1059 | 356 | ## tests | ||
1060 | 357 | |||
1061 | 358 | SET(MAIN_TEST_SUITE ${PACKAGE}.SikuliIDETestSuite) | ||
1062 | 359 | |||
1063 | 360 | add_custom_target( java-test.test-res | ||
1064 | 361 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${BASE_DIR}/${TEST_RESOURCE_DIR} ${CMAKE_BINARY_DIR}/${TEST_RESOURCE_DIR} | ||
1065 | 362 | COMMENT "Copy test resource" | ||
1066 | 363 | ) | ||
1067 | 364 | |||
1068 | 365 | add_custom_target( java-test | ||
1069 | 366 | # COMMAND ${JAVA_RUNTIME} -cp ${TEST_CLASS_DIR}${SEP}${BINARY_DIR}/${JAR_FILE}${SEP}${JUNIT_JAR} junit.textui.TestRunner ${MAIN_TEST_SUITE} | ||
1070 | 367 | COMMAND ant -f ${JAVA_TEST_FOR_HUDSON_XML} | ||
1071 | 368 | COMMENT "Run Java unit tests" | ||
1072 | 369 | ) | ||
1073 | 370 | |||
1074 | 371 | add_dependencies( java-test | ||
1075 | 372 | ${JAR_FILE} | ||
1076 | 373 | ${PROJECT_NAME}.test.classes | ||
1077 | 374 | java-test.test-res | ||
1078 | 375 | ) | ||
1079 | 376 | |||
1080 | 377 | add_custom_target( all-test | ||
1081 | 378 | ) | ||
1082 | 379 | |||
1083 | 380 | add_dependencies( all-test | ||
1084 | 381 | java-test | ||
1085 | 382 | ) | ||
1086 | 383 | |||
1087 | 384 | ## Dependencies | ||
1088 | 385 | |||
1089 | 386 | add_dependencies( ${JAR_FILE}.prepare | ||
1090 | 387 | ${JAR_FILE}.resources | ||
1091 | 388 | ${JAR_FILE}.classes-in-jar | ||
1092 | 389 | # ${JAR_FILE}.libs-in-jar | ||
1093 | 390 | ) | ||
1094 | 391 | |||
1095 | 392 | add_dependencies( ${JAR_FILE} ${JAR_FILE}.prepare ) | ||
1096 | 393 | add_dependencies( run-user ${JAR_FILE}) | ||
1097 | 394 | add_dependencies( run ${JAR_FILE}) | ||
1098 | 395 | add_dependencies( app ${APP_FILE}) | ||
1099 | 396 | |||
1100 | 397 | |||
1101 | 398 | ADD_SUBDIRECTORY( ${JAVA_SRC_DIR} ) | ||
1102 | 399 | #ADD_SUBDIRECTORY( ${NATIVE_SRC_DIR} ) | ||
1103 | 400 | ADD_SUBDIRECTORY( ${JAVA_TEST_DIR} ) | ||
1104 | 401 | |||
1105 | 402 | |||
1106 | 403 | |||
1107 | 404 | SET(SIKULI_VERSION CACHE INTERNAL "" FORCE) | ||
1108 | 405 | |||
1109 | 406 | 0 | ||
1110 | === removed directory '.pc/jgoodies-1.6-compat.patch/sikuli-ide/src' | |||
1111 | === removed directory '.pc/jgoodies-1.6-compat.patch/sikuli-ide/src/main' | |||
1112 | === removed directory '.pc/jgoodies-1.6-compat.patch/sikuli-ide/src/main/java' | |||
1113 | === removed directory '.pc/jgoodies-1.6-compat.patch/sikuli-ide/src/main/java/org' | |||
1114 | === removed directory '.pc/jgoodies-1.6-compat.patch/sikuli-ide/src/main/java/org/sikuli' | |||
1115 | === removed directory '.pc/jgoodies-1.6-compat.patch/sikuli-ide/src/main/java/org/sikuli/ide' | |||
1116 | === removed file '.pc/jgoodies-1.6-compat.patch/sikuli-ide/src/main/java/org/sikuli/ide/PreferencesWin.java' | |||
1117 | --- .pc/jgoodies-1.6-compat.patch/sikuli-ide/src/main/java/org/sikuli/ide/PreferencesWin.java 2012-12-07 22:13:08 +0000 | |||
1118 | +++ .pc/jgoodies-1.6-compat.patch/sikuli-ide/src/main/java/org/sikuli/ide/PreferencesWin.java 1970-01-01 00:00:00 +0000 | |||
1119 | @@ -1,561 +0,0 @@ | |||
1120 | 1 | /* | ||
1121 | 2 | * Copyright 2010-2011, Sikuli.org | ||
1122 | 3 | * Released under the MIT License. | ||
1123 | 4 | * | ||
1124 | 5 | */ | ||
1125 | 6 | package org.sikuli.ide; | ||
1126 | 7 | |||
1127 | 8 | import java.awt.*; | ||
1128 | 9 | import java.awt.event.*; | ||
1129 | 10 | import java.util.prefs.*; | ||
1130 | 11 | import java.util.Arrays; | ||
1131 | 12 | import java.util.Comparator; | ||
1132 | 13 | import java.util.Locale; | ||
1133 | 14 | import java.util.ResourceBundle; | ||
1134 | 15 | import java.util.MissingResourceException; | ||
1135 | 16 | import javax.swing.DefaultListCellRenderer; | ||
1136 | 17 | import javax.swing.JList; | ||
1137 | 18 | import javax.swing.BoxLayout; | ||
1138 | 19 | import javax.swing.ButtonGroup; | ||
1139 | 20 | import javax.swing.JButton; | ||
1140 | 21 | import javax.swing.JCheckBox; | ||
1141 | 22 | import javax.swing.JComboBox; | ||
1142 | 23 | import javax.swing.JFrame; | ||
1143 | 24 | import javax.swing.JLabel; | ||
1144 | 25 | import javax.swing.JPanel; | ||
1145 | 26 | import javax.swing.JRadioButton; | ||
1146 | 27 | import javax.swing.JSpinner; | ||
1147 | 28 | import javax.swing.JTabbedPane; | ||
1148 | 29 | import javax.swing.JTextField; | ||
1149 | 30 | import javax.swing.SpinnerNumberModel; | ||
1150 | 31 | import javax.swing.SwingConstants; | ||
1151 | 32 | import javax.swing.border.EmptyBorder; | ||
1152 | 33 | import javax.swing.event.ChangeEvent; | ||
1153 | 34 | import javax.swing.event.ChangeListener; | ||
1154 | 35 | import com.jgoodies.forms.factories.DefaultComponentFactory; | ||
1155 | 36 | import org.jdesktop.layout.*; | ||
1156 | 37 | |||
1157 | 38 | import org.sikuli.script.Debug; | ||
1158 | 39 | |||
1159 | 40 | /* | ||
1160 | 41 | * Created by JFormDesigner on Mon Nov 16 10:13:52 EST 2009 | ||
1161 | 42 | */ | ||
1162 | 43 | |||
1163 | 44 | |||
1164 | 45 | public class PreferencesWin extends JFrame { | ||
1165 | 46 | UserPreferences pref = UserPreferences.getInstance(); | ||
1166 | 47 | int _cap_hkey, _cap_mod; | ||
1167 | 48 | int _old_cap_hkey, _old_cap_mod; | ||
1168 | 49 | |||
1169 | 50 | public PreferencesWin() { | ||
1170 | 51 | super( SikuliIDE._I("winPreferences") ); | ||
1171 | 52 | initComponents(); | ||
1172 | 53 | loadPrefs(); | ||
1173 | 54 | } | ||
1174 | 55 | |||
1175 | 56 | private void loadPrefs(){ | ||
1176 | 57 | SikuliIDE ide = SikuliIDE.getInstance(); | ||
1177 | 58 | double delay = pref.getCaptureDelay(); | ||
1178 | 59 | _spnDelay.setValue(delay); | ||
1179 | 60 | _old_cap_hkey = _cap_hkey = pref.getCaptureHotkey(); | ||
1180 | 61 | _old_cap_mod = _cap_mod = pref.getCaptureHotkeyModifiers(); | ||
1181 | 62 | setTxtHotkey(_cap_hkey, _cap_mod); | ||
1182 | 63 | switch(pref.getAutoNamingMethod()){ | ||
1183 | 64 | case UserPreferences.AUTO_NAMING_TIMESTAMP: | ||
1184 | 65 | _radTimestamp.setSelected(true); | ||
1185 | 66 | break; | ||
1186 | 67 | case UserPreferences.AUTO_NAMING_OCR: | ||
1187 | 68 | _radOCR.setSelected(true); | ||
1188 | 69 | break; | ||
1189 | 70 | case UserPreferences.AUTO_NAMING_OFF: | ||
1190 | 71 | _radOff.setSelected(true); | ||
1191 | 72 | break; | ||
1192 | 73 | default: | ||
1193 | 74 | Debug.error("Error in reading auto naming method preferences"); | ||
1194 | 75 | } | ||
1195 | 76 | _chkAutoUpdate.setSelected(pref.getCheckUpdate()); | ||
1196 | 77 | |||
1197 | 78 | _chkExpandTab.setSelected(pref.getExpandTab()); | ||
1198 | 79 | _spnTabWidth.setValue(pref.getTabWidth()); | ||
1199 | 80 | initFontPrefs(); | ||
1200 | 81 | initLangPrefs(); | ||
1201 | 82 | } | ||
1202 | 83 | |||
1203 | 84 | private void initLangPrefs(){ | ||
1204 | 85 | String[] SUPPORT_LOCALES = { | ||
1205 | 86 | "es", "pt_BR", "ar", "fr", "ru", "bg", "he", "sv", "ca", "ja", "tr", | ||
1206 | 87 | "da", "ko", "uk", "de", "nl", "zh_CN", "en_US", "pl", "zh_TW" | ||
1207 | 88 | }; | ||
1208 | 89 | Locale[] sortedLocales = new Locale[SUPPORT_LOCALES.length]; | ||
1209 | 90 | UserPreferences pref = UserPreferences.getInstance(); | ||
1210 | 91 | int count = 0; | ||
1211 | 92 | for (String locale_code: SUPPORT_LOCALES){ | ||
1212 | 93 | Locale l; | ||
1213 | 94 | if( locale_code.indexOf("_")>=0 ){ | ||
1214 | 95 | String[] lang_country = locale_code.split("_"); | ||
1215 | 96 | l = new Locale(lang_country[0], lang_country[1]); | ||
1216 | 97 | } | ||
1217 | 98 | else | ||
1218 | 99 | l = new Locale(locale_code); | ||
1219 | 100 | sortedLocales[count++] = l; | ||
1220 | 101 | } | ||
1221 | 102 | Arrays.sort(sortedLocales, new Comparator<Locale>(){ | ||
1222 | 103 | public int compare(Locale l1, Locale l2) { | ||
1223 | 104 | return l1.getDisplayLanguage().compareTo(l2.getDisplayLanguage()); | ||
1224 | 105 | } | ||
1225 | 106 | }); | ||
1226 | 107 | |||
1227 | 108 | for(Locale l : sortedLocales){ | ||
1228 | 109 | _cmbLang.addItem(l); | ||
1229 | 110 | } | ||
1230 | 111 | _cmbLang.setRenderer(new LocaleListCellRenderer()); | ||
1231 | 112 | Locale curLocale = pref.getLocale(); | ||
1232 | 113 | _cmbLang.setSelectedItem(curLocale); | ||
1233 | 114 | if(!_cmbLang.getSelectedItem().equals(curLocale)){ | ||
1234 | 115 | if(curLocale.getVariant().length() > 0){ | ||
1235 | 116 | curLocale = new Locale(curLocale.getLanguage(), curLocale.getCountry()); | ||
1236 | 117 | _cmbLang.setSelectedItem(curLocale); | ||
1237 | 118 | } | ||
1238 | 119 | if(!_cmbLang.getSelectedItem().equals(curLocale)) | ||
1239 | 120 | _cmbLang.setSelectedItem(new Locale(curLocale.getLanguage())); | ||
1240 | 121 | } | ||
1241 | 122 | } | ||
1242 | 123 | |||
1243 | 124 | |||
1244 | 125 | private void initFontPrefs(){ | ||
1245 | 126 | UserPreferences pref = UserPreferences.getInstance(); | ||
1246 | 127 | String[] fontList = GraphicsEnvironment.getLocalGraphicsEnvironment() | ||
1247 | 128 | .getAvailableFontFamilyNames(); | ||
1248 | 129 | for (String font: fontList) | ||
1249 | 130 | _cmbFontName.addItem(font); | ||
1250 | 131 | _cmbFontName.setSelectedItem(pref.getFontName()); | ||
1251 | 132 | _spnFontSize.setValue(pref.getFontSize()); | ||
1252 | 133 | } | ||
1253 | 134 | |||
1254 | 135 | private void savePrefs(){ | ||
1255 | 136 | SikuliIDE ide = SikuliIDE.getInstance(); | ||
1256 | 137 | pref.setCaptureDelay((Double)_spnDelay.getValue()); | ||
1257 | 138 | pref.setCaptureHotkey(_cap_hkey); | ||
1258 | 139 | pref.setCaptureHotkeyModifiers(_cap_mod); | ||
1259 | 140 | pref.setAutoNamingMethod( | ||
1260 | 141 | _radTimestamp.isSelected()?UserPreferences.AUTO_NAMING_TIMESTAMP: | ||
1261 | 142 | _radOCR.isSelected()?UserPreferences.AUTO_NAMING_OCR: | ||
1262 | 143 | UserPreferences.AUTO_NAMING_OFF); | ||
1263 | 144 | if(_old_cap_hkey != _cap_hkey || _old_cap_mod != _cap_mod){ | ||
1264 | 145 | ide.removeCaptureHotkey(_old_cap_hkey, _old_cap_mod); | ||
1265 | 146 | ide.installCaptureHotkey(_cap_hkey, _cap_mod); | ||
1266 | 147 | } | ||
1267 | 148 | pref.setCheckUpdate(_chkAutoUpdate.isSelected()); | ||
1268 | 149 | |||
1269 | 150 | pref.setExpandTab(_chkExpandTab.isSelected()); | ||
1270 | 151 | pref.setTabWidth((Integer)_spnTabWidth.getValue()); | ||
1271 | 152 | |||
1272 | 153 | pref.setFontName( (String)_cmbFontName.getSelectedItem() ); | ||
1273 | 154 | pref.setFontSize( (Integer)_spnFontSize.getValue() ); | ||
1274 | 155 | |||
1275 | 156 | Locale locale = (Locale)_cmbLang.getSelectedItem(); | ||
1276 | 157 | pref.setLocale(locale); | ||
1277 | 158 | I18N.setLocale(locale); | ||
1278 | 159 | } | ||
1279 | 160 | |||
1280 | 161 | private void setTxtHotkey(int code, int mod){ | ||
1281 | 162 | _cap_hkey = code; | ||
1282 | 163 | _cap_mod = mod; | ||
1283 | 164 | _txtHotkey.setText( Utils.convertKeyToText(code, mod) ); | ||
1284 | 165 | } | ||
1285 | 166 | |||
1286 | 167 | private void btnOkActionPerformed(ActionEvent e) { | ||
1287 | 168 | savePrefs(); | ||
1288 | 169 | this.dispose(); | ||
1289 | 170 | } | ||
1290 | 171 | |||
1291 | 172 | private void btnCancelActionPerformed(ActionEvent e) { | ||
1292 | 173 | this.dispose(); | ||
1293 | 174 | } | ||
1294 | 175 | |||
1295 | 176 | private void txtHotkeyFocusGained(FocusEvent e) { | ||
1296 | 177 | _txtHotkey.setEditable(true); | ||
1297 | 178 | } | ||
1298 | 179 | |||
1299 | 180 | private void txtHotkeyKeyPressed(KeyEvent e) { | ||
1300 | 181 | int code = e.getKeyCode(); | ||
1301 | 182 | int mod = e.getModifiers(); | ||
1302 | 183 | Debug.log(7, "" + code + " " + mod); | ||
1303 | 184 | setTxtHotkey(code, mod); | ||
1304 | 185 | _txtHotkey.setEditable(false); | ||
1305 | 186 | } | ||
1306 | 187 | |||
1307 | 188 | private void updateFontPreview(){ | ||
1308 | 189 | SikuliIDE ide = SikuliIDE.getInstance(); | ||
1309 | 190 | Font font = new Font((String)_cmbFontName.getSelectedItem(), Font.PLAIN, | ||
1310 | 191 | (Integer)_spnFontSize.getValue()); | ||
1311 | 192 | ide.getCurrentCodePane().setFont(font); | ||
1312 | 193 | } | ||
1313 | 194 | |||
1314 | 195 | private void fontNameItemStateChanged(ItemEvent e) { | ||
1315 | 196 | updateFontPreview(); | ||
1316 | 197 | } | ||
1317 | 198 | |||
1318 | 199 | private void fontSizeStateChanged(ChangeEvent e) { | ||
1319 | 200 | updateFontPreview(); | ||
1320 | 201 | } | ||
1321 | 202 | |||
1322 | 203 | private void initComponents() { | ||
1323 | 204 | // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents | ||
1324 | 205 | DefaultComponentFactory compFactory = DefaultComponentFactory.getInstance(); | ||
1325 | 206 | _tabPane = new JTabbedPane(); | ||
1326 | 207 | JPanel paneCapture = new JPanel(); | ||
1327 | 208 | _txtHotkey = new JTextField(); | ||
1328 | 209 | _lblHotkey = new JLabel(); | ||
1329 | 210 | _lblDelay = new JLabel(); | ||
1330 | 211 | _spnDelay = new JSpinner(); | ||
1331 | 212 | _lblDelaySecs = new JLabel(); | ||
1332 | 213 | _lblNaming = new JLabel(); | ||
1333 | 214 | _radTimestamp = new JRadioButton(); | ||
1334 | 215 | _radOCR = new JRadioButton(); | ||
1335 | 216 | _radOff = new JRadioButton(); | ||
1336 | 217 | _paneTextEditing = new JPanel(); | ||
1337 | 218 | _chkExpandTab = new JCheckBox(); | ||
1338 | 219 | _lblTabWidth = new JLabel(); | ||
1339 | 220 | _cmbFontName = new JComboBox(); | ||
1340 | 221 | _lblFont = new JLabel(); | ||
1341 | 222 | _titleAppearance = compFactory.createTitle(""); | ||
1342 | 223 | _titleIndentation = compFactory.createTitle(""); | ||
1343 | 224 | _spnTabWidth = new JSpinner(); | ||
1344 | 225 | _lblFontSize = new JLabel(); | ||
1345 | 226 | _spnFontSize = new JSpinner(); | ||
1346 | 227 | JPanel paneGeneral = new JPanel(); | ||
1347 | 228 | _chkAutoUpdate = new JCheckBox(); | ||
1348 | 229 | _cmbLang = new JComboBox(); | ||
1349 | 230 | _lblUpdates = new JLabel(); | ||
1350 | 231 | _lblLanguage = new JLabel(); | ||
1351 | 232 | JPanel paneOkCancel = new JPanel(); | ||
1352 | 233 | JPanel hSpacer1 = new JPanel(null); | ||
1353 | 234 | _btnOk = new JButton(); | ||
1354 | 235 | _btnCancel = new JButton(); | ||
1355 | 236 | |||
1356 | 237 | //======== this ======== | ||
1357 | 238 | Container contentPane = getContentPane(); | ||
1358 | 239 | contentPane.setLayout(new BorderLayout()); | ||
1359 | 240 | |||
1360 | 241 | //======== _tabPane ======== | ||
1361 | 242 | { | ||
1362 | 243 | _tabPane.setBorder(new EmptyBorder(10, 10, 0, 10)); | ||
1363 | 244 | |||
1364 | 245 | //======== paneCapture ======== | ||
1365 | 246 | { | ||
1366 | 247 | |||
1367 | 248 | //---- _txtHotkey ---- | ||
1368 | 249 | _txtHotkey.setHorizontalAlignment(SwingConstants.RIGHT); | ||
1369 | 250 | _txtHotkey.addFocusListener(new FocusAdapter() { | ||
1370 | 251 | @Override | ||
1371 | 252 | public void focusGained(FocusEvent e) { | ||
1372 | 253 | txtHotkeyFocusGained(e); | ||
1373 | 254 | } | ||
1374 | 255 | }); | ||
1375 | 256 | _txtHotkey.addKeyListener(new KeyAdapter() { | ||
1376 | 257 | @Override | ||
1377 | 258 | public void keyPressed(KeyEvent e) { | ||
1378 | 259 | txtHotkeyKeyPressed(e); | ||
1379 | 260 | } | ||
1380 | 261 | }); | ||
1381 | 262 | |||
1382 | 263 | //---- _lblHotkey ---- | ||
1383 | 264 | _lblHotkey.setLabelFor(_txtHotkey); | ||
1384 | 265 | |||
1385 | 266 | //---- _lblDelay ---- | ||
1386 | 267 | _lblDelay.setLabelFor(_spnDelay); | ||
1387 | 268 | |||
1388 | 269 | //---- _spnDelay ---- | ||
1389 | 270 | _spnDelay.setModel(new SpinnerNumberModel(1.0, 0.0, null, 0.1)); | ||
1390 | 271 | |||
1391 | 272 | //---- _radTimestamp ---- | ||
1392 | 273 | _radTimestamp.setSelected(true); | ||
1393 | 274 | |||
1394 | 275 | GroupLayout paneCaptureLayout = new GroupLayout(paneCapture); | ||
1395 | 276 | paneCapture.setLayout(paneCaptureLayout); | ||
1396 | 277 | paneCaptureLayout.setHorizontalGroup( | ||
1397 | 278 | paneCaptureLayout.createParallelGroup() | ||
1398 | 279 | .add(paneCaptureLayout.createSequentialGroup() | ||
1399 | 280 | .add(26, 26, 26) | ||
1400 | 281 | .add(paneCaptureLayout.createParallelGroup() | ||
1401 | 282 | .add(GroupLayout.TRAILING, _lblDelay) | ||
1402 | 283 | .add(GroupLayout.TRAILING, _lblHotkey) | ||
1403 | 284 | .add(GroupLayout.TRAILING, _lblNaming)) | ||
1404 | 285 | .addPreferredGap(LayoutStyle.RELATED) | ||
1405 | 286 | .add(paneCaptureLayout.createParallelGroup() | ||
1406 | 287 | .add(_radTimestamp) | ||
1407 | 288 | .add(_radOCR) | ||
1408 | 289 | .add(_radOff) | ||
1409 | 290 | .add(paneCaptureLayout.createSequentialGroup() | ||
1410 | 291 | .add(_spnDelay, GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE) | ||
1411 | 292 | .addPreferredGap(LayoutStyle.RELATED) | ||
1412 | 293 | .add(_lblDelaySecs, GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)) | ||
1413 | 294 | .add(_txtHotkey, GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)) | ||
1414 | 295 | .add(69, 69, 69)) | ||
1415 | 296 | ); | ||
1416 | 297 | paneCaptureLayout.setVerticalGroup( | ||
1417 | 298 | paneCaptureLayout.createParallelGroup() | ||
1418 | 299 | .add(paneCaptureLayout.createSequentialGroup() | ||
1419 | 300 | .add(34, 34, 34) | ||
1420 | 301 | .add(paneCaptureLayout.createParallelGroup(GroupLayout.BASELINE) | ||
1421 | 302 | .add(_lblHotkey, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE) | ||
1422 | 303 | .add(_txtHotkey, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) | ||
1423 | 304 | .addPreferredGap(LayoutStyle.RELATED) | ||
1424 | 305 | .add(paneCaptureLayout.createParallelGroup() | ||
1425 | 306 | .add(_lblDelay, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE) | ||
1426 | 307 | .add(_spnDelay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) | ||
1427 | 308 | .add(_lblDelaySecs, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)) | ||
1428 | 309 | .addPreferredGap(LayoutStyle.RELATED) | ||
1429 | 310 | .add(paneCaptureLayout.createParallelGroup(GroupLayout.LEADING, false) | ||
1430 | 311 | .add(paneCaptureLayout.createSequentialGroup() | ||
1431 | 312 | .add(paneCaptureLayout.createParallelGroup(GroupLayout.BASELINE) | ||
1432 | 313 | .add(_lblNaming, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE) | ||
1433 | 314 | .add(_radTimestamp)) | ||
1434 | 315 | .add(18, 18, 18) | ||
1435 | 316 | .add(_radOff) | ||
1436 | 317 | .addPreferredGap(LayoutStyle.RELATED)) | ||
1437 | 318 | .add(GroupLayout.TRAILING, paneCaptureLayout.createSequentialGroup() | ||
1438 | 319 | .add(_radOCR) | ||
1439 | 320 | .add(21, 21, 21))) | ||
1440 | 321 | .add(80, 80, 80)) | ||
1441 | 322 | ); | ||
1442 | 323 | } | ||
1443 | 324 | _tabPane.addTab(I18N._I("prefTabScreenCapturing"), paneCapture); | ||
1444 | 325 | |||
1445 | 326 | |||
1446 | 327 | //======== _paneTextEditing ======== | ||
1447 | 328 | { | ||
1448 | 329 | |||
1449 | 330 | //---- _lblTabWidth ---- | ||
1450 | 331 | _lblTabWidth.setLabelFor(_spnTabWidth); | ||
1451 | 332 | |||
1452 | 333 | //---- _cmbFontName ---- | ||
1453 | 334 | _cmbFontName.addItemListener(new ItemListener() { | ||
1454 | 335 | public void itemStateChanged(ItemEvent e) { | ||
1455 | 336 | fontNameItemStateChanged(e); | ||
1456 | 337 | } | ||
1457 | 338 | }); | ||
1458 | 339 | |||
1459 | 340 | //---- _lblFont ---- | ||
1460 | 341 | _lblFont.setLabelFor(_cmbFontName); | ||
1461 | 342 | |||
1462 | 343 | //---- _lblFontSize ---- | ||
1463 | 344 | _lblFontSize.setLabelFor(_cmbFontName); | ||
1464 | 345 | |||
1465 | 346 | //---- _spnFontSize ---- | ||
1466 | 347 | _spnFontSize.addChangeListener(new ChangeListener() { | ||
1467 | 348 | public void stateChanged(ChangeEvent e) { | ||
1468 | 349 | fontSizeStateChanged(e); | ||
1469 | 350 | } | ||
1470 | 351 | }); | ||
1471 | 352 | |||
1472 | 353 | GroupLayout _paneTextEditingLayout = new GroupLayout(_paneTextEditing); | ||
1473 | 354 | _paneTextEditing.setLayout(_paneTextEditingLayout); | ||
1474 | 355 | _paneTextEditingLayout.setHorizontalGroup( | ||
1475 | 356 | _paneTextEditingLayout.createParallelGroup() | ||
1476 | 357 | .add(GroupLayout.TRAILING, _paneTextEditingLayout.createSequentialGroup() | ||
1477 | 358 | .add(95, 95, 95) | ||
1478 | 359 | .add(_paneTextEditingLayout.createParallelGroup() | ||
1479 | 360 | .add(_titleIndentation, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) | ||
1480 | 361 | .add(_paneTextEditingLayout.createSequentialGroup() | ||
1481 | 362 | .add(_titleAppearance, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) | ||
1482 | 363 | .addPreferredGap(LayoutStyle.RELATED) | ||
1483 | 364 | .add(_paneTextEditingLayout.createParallelGroup() | ||
1484 | 365 | .add(_paneTextEditingLayout.createSequentialGroup() | ||
1485 | 366 | .add(29, 29, 29) | ||
1486 | 367 | .add(_paneTextEditingLayout.createParallelGroup() | ||
1487 | 368 | .add(GroupLayout.TRAILING, _lblTabWidth) | ||
1488 | 369 | .add(GroupLayout.TRAILING, _lblFont) | ||
1489 | 370 | .add(GroupLayout.TRAILING, _lblFontSize)) | ||
1490 | 371 | .addPreferredGap(LayoutStyle.RELATED) | ||
1491 | 372 | .add(_paneTextEditingLayout.createParallelGroup() | ||
1492 | 373 | .add(_cmbFontName, 0, 218, Short.MAX_VALUE) | ||
1493 | 374 | .add(_spnFontSize, GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE) | ||
1494 | 375 | .add(_spnTabWidth, GroupLayout.PREFERRED_SIZE, 52, GroupLayout.PREFERRED_SIZE)) | ||
1495 | 376 | .addPreferredGap(LayoutStyle.RELATED, 97, Short.MAX_VALUE)) | ||
1496 | 377 | .add(_chkExpandTab, GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)))) | ||
1497 | 378 | .addContainerGap()) | ||
1498 | 379 | ); | ||
1499 | 380 | _paneTextEditingLayout.setVerticalGroup( | ||
1500 | 381 | _paneTextEditingLayout.createParallelGroup() | ||
1501 | 382 | .add(_paneTextEditingLayout.createSequentialGroup() | ||
1502 | 383 | .add(21, 21, 21) | ||
1503 | 384 | .add(_titleIndentation, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) | ||
1504 | 385 | .add(_paneTextEditingLayout.createParallelGroup() | ||
1505 | 386 | .add(_paneTextEditingLayout.createSequentialGroup() | ||
1506 | 387 | .add(81, 81, 81) | ||
1507 | 388 | .add(_titleAppearance, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) | ||
1508 | 389 | .add(_paneTextEditingLayout.createSequentialGroup() | ||
1509 | 390 | .addPreferredGap(LayoutStyle.RELATED) | ||
1510 | 391 | .add(_chkExpandTab) | ||
1511 | 392 | .addPreferredGap(LayoutStyle.RELATED) | ||
1512 | 393 | .add(_paneTextEditingLayout.createParallelGroup() | ||
1513 | 394 | .add(_lblTabWidth, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE) | ||
1514 | 395 | .add(_spnTabWidth, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) | ||
1515 | 396 | .add(40, 40, 40) | ||
1516 | 397 | .add(_paneTextEditingLayout.createParallelGroup(GroupLayout.BASELINE) | ||
1517 | 398 | .add(_lblFont) | ||
1518 | 399 | .add(_cmbFontName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) | ||
1519 | 400 | .addPreferredGap(LayoutStyle.RELATED) | ||
1520 | 401 | .add(_paneTextEditingLayout.createParallelGroup(GroupLayout.TRAILING) | ||
1521 | 402 | .add(_lblFontSize, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE) | ||
1522 | 403 | .add(_spnFontSize, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))) | ||
1523 | 404 | .addContainerGap(154, Short.MAX_VALUE)) | ||
1524 | 405 | ); | ||
1525 | 406 | _paneTextEditingLayout.linkSize(new Component[] {_lblTabWidth, _spnTabWidth}, GroupLayout.VERTICAL); | ||
1526 | 407 | _paneTextEditingLayout.linkSize(new Component[] {_cmbFontName, _lblFont}, GroupLayout.VERTICAL); | ||
1527 | 408 | } | ||
1528 | 409 | _tabPane.addTab(I18N._I("PreferencesWin.paneTextEditing.tab.title"), _paneTextEditing); | ||
1529 | 410 | |||
1530 | 411 | |||
1531 | 412 | //======== paneGeneral ======== | ||
1532 | 413 | { | ||
1533 | 414 | |||
1534 | 415 | //---- _lblUpdates ---- | ||
1535 | 416 | _lblUpdates.setFont(_lblUpdates.getFont().deriveFont(_lblUpdates.getFont().getStyle() | Font.BOLD)); | ||
1536 | 417 | |||
1537 | 418 | //---- _lblLanguage ---- | ||
1538 | 419 | _lblLanguage.setFont(_lblLanguage.getFont().deriveFont(_lblLanguage.getFont().getStyle() | Font.BOLD)); | ||
1539 | 420 | |||
1540 | 421 | GroupLayout paneGeneralLayout = new GroupLayout(paneGeneral); | ||
1541 | 422 | paneGeneral.setLayout(paneGeneralLayout); | ||
1542 | 423 | paneGeneralLayout.setHorizontalGroup( | ||
1543 | 424 | paneGeneralLayout.createParallelGroup() | ||
1544 | 425 | .add(paneGeneralLayout.createSequentialGroup() | ||
1545 | 426 | .add(137, 137, 137) | ||
1546 | 427 | .add(paneGeneralLayout.createParallelGroup() | ||
1547 | 428 | .add(paneGeneralLayout.createSequentialGroup() | ||
1548 | 429 | .add(_lblLanguage) | ||
1549 | 430 | .add(185, 185, 185)) | ||
1550 | 431 | .add(paneGeneralLayout.createSequentialGroup() | ||
1551 | 432 | .add(38, 38, 38) | ||
1552 | 433 | .add(_cmbLang, GroupLayout.PREFERRED_SIZE, 215, GroupLayout.PREFERRED_SIZE)) | ||
1553 | 434 | .add(paneGeneralLayout.createSequentialGroup() | ||
1554 | 435 | .add(_lblUpdates) | ||
1555 | 436 | .add(318, 318, 318)) | ||
1556 | 437 | .add(GroupLayout.TRAILING, paneGeneralLayout.createSequentialGroup() | ||
1557 | 438 | .add(38, 38, 38) | ||
1558 | 439 | .add(_chkAutoUpdate, GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE))) | ||
1559 | 440 | .addContainerGap()) | ||
1560 | 441 | ); | ||
1561 | 442 | paneGeneralLayout.setVerticalGroup( | ||
1562 | 443 | paneGeneralLayout.createParallelGroup() | ||
1563 | 444 | .add(paneGeneralLayout.createSequentialGroup() | ||
1564 | 445 | .add(26, 26, 26) | ||
1565 | 446 | .add(_lblUpdates) | ||
1566 | 447 | .addPreferredGap(LayoutStyle.RELATED) | ||
1567 | 448 | .add(_chkAutoUpdate) | ||
1568 | 449 | .add(40, 40, 40) | ||
1569 | 450 | .add(_lblLanguage) | ||
1570 | 451 | .addPreferredGap(LayoutStyle.RELATED) | ||
1571 | 452 | .add(_cmbLang, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) | ||
1572 | 453 | .addContainerGap(196, Short.MAX_VALUE)) | ||
1573 | 454 | ); | ||
1574 | 455 | } | ||
1575 | 456 | _tabPane.addTab(I18N._I("prefTabGeneralSettings"), paneGeneral); | ||
1576 | 457 | |||
1577 | 458 | } | ||
1578 | 459 | contentPane.add(_tabPane, BorderLayout.CENTER); | ||
1579 | 460 | |||
1580 | 461 | //======== paneOkCancel ======== | ||
1581 | 462 | { | ||
1582 | 463 | paneOkCancel.setBorder(new EmptyBorder(5, 5, 5, 5)); | ||
1583 | 464 | paneOkCancel.setLayout(new BoxLayout(paneOkCancel, BoxLayout.X_AXIS)); | ||
1584 | 465 | paneOkCancel.add(hSpacer1); | ||
1585 | 466 | |||
1586 | 467 | //---- _btnOk ---- | ||
1587 | 468 | _btnOk.addActionListener(new ActionListener() { | ||
1588 | 469 | public void actionPerformed(ActionEvent e) { | ||
1589 | 470 | btnOkActionPerformed(e); | ||
1590 | 471 | } | ||
1591 | 472 | }); | ||
1592 | 473 | paneOkCancel.add(_btnOk); | ||
1593 | 474 | |||
1594 | 475 | //---- _btnCancel ---- | ||
1595 | 476 | _btnCancel.addActionListener(new ActionListener() { | ||
1596 | 477 | public void actionPerformed(ActionEvent e) { | ||
1597 | 478 | btnCancelActionPerformed(e); | ||
1598 | 479 | } | ||
1599 | 480 | }); | ||
1600 | 481 | paneOkCancel.add(_btnCancel); | ||
1601 | 482 | } | ||
1602 | 483 | contentPane.add(paneOkCancel, BorderLayout.SOUTH); | ||
1603 | 484 | setSize(600, 475); | ||
1604 | 485 | setLocationRelativeTo(getOwner()); | ||
1605 | 486 | |||
1606 | 487 | //---- btngrpNaming ---- | ||
1607 | 488 | ButtonGroup btngrpNaming = new ButtonGroup(); | ||
1608 | 489 | btngrpNaming.add(_radTimestamp); | ||
1609 | 490 | btngrpNaming.add(_radOCR); | ||
1610 | 491 | btngrpNaming.add(_radOff); | ||
1611 | 492 | |||
1612 | 493 | initComponentsI18n(); | ||
1613 | 494 | // JFormDesigner - End of component initialization //GEN-END:initComponents | ||
1614 | 495 | } | ||
1615 | 496 | |||
1616 | 497 | private void initComponentsI18n() { | ||
1617 | 498 | // JFormDesigner - Component i18n initialization - DO NOT MODIFY //GEN-BEGIN:initI18n | ||
1618 | 499 | DefaultComponentFactory.setTextAndMnemonic(_titleAppearance, I18N._I("PreferencesWin.titleAppearance.textWithMnemonic")); | ||
1619 | 500 | DefaultComponentFactory.setTextAndMnemonic(_titleIndentation, I18N._I("PreferencesWin.titleIndentation.textWithMnemonic")); | ||
1620 | 501 | _lblHotkey.setText(I18N._I("prefCaptureHotkey")); | ||
1621 | 502 | _lblDelay.setText(I18N._I("prefCaptureDelay")); | ||
1622 | 503 | _lblDelaySecs.setText(I18N._I("prefSeconds")); | ||
1623 | 504 | _lblNaming.setText(I18N._I("prefAutoNaming")); | ||
1624 | 505 | _radTimestamp.setText(I18N._I("prefTimestamp")); | ||
1625 | 506 | _radOCR.setText(I18N._I("prefRecognizedText")); | ||
1626 | 507 | _radOff.setText(I18N._I("prefManualInput")); | ||
1627 | 508 | _tabPane.setTitleAt(0, I18N._I("prefTabScreenCapturing")); | ||
1628 | 509 | _chkExpandTab.setText(I18N._I("PreferencesWin.chkExpandTab.text")); | ||
1629 | 510 | _lblTabWidth.setText(I18N._I("PreferencesWin.lblTabWidth.text")); | ||
1630 | 511 | _lblFont.setText(I18N._I("PreferencesWin.lblFont.text")); | ||
1631 | 512 | _lblFontSize.setText(I18N._I("PreferencesWin.lblFontSize.text")); | ||
1632 | 513 | _tabPane.setTitleAt(1, I18N._I("PreferencesWin.paneTextEditing.tab.title")); | ||
1633 | 514 | _chkAutoUpdate.setText(I18N._I("prefGeneralAutoCheck")); | ||
1634 | 515 | _lblUpdates.setText(I18N._I("PreferencesWin.lblUpdates.text")); | ||
1635 | 516 | _lblLanguage.setText(I18N._I("PreferencesWin.lblLanguage.text")); | ||
1636 | 517 | _tabPane.setTitleAt(2, I18N._I("prefTabGeneralSettings")); | ||
1637 | 518 | _btnOk.setText(I18N._I("ok")); | ||
1638 | 519 | _btnCancel.setText(I18N._I("cancel")); | ||
1639 | 520 | // JFormDesigner - End of component i18n initialization //GEN-END:initI18n | ||
1640 | 521 | } | ||
1641 | 522 | |||
1642 | 523 | // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables | ||
1643 | 524 | private JTabbedPane _tabPane; | ||
1644 | 525 | private JTextField _txtHotkey; | ||
1645 | 526 | private JLabel _lblHotkey; | ||
1646 | 527 | private JLabel _lblDelay; | ||
1647 | 528 | private JSpinner _spnDelay; | ||
1648 | 529 | private JLabel _lblDelaySecs; | ||
1649 | 530 | private JLabel _lblNaming; | ||
1650 | 531 | private JRadioButton _radTimestamp; | ||
1651 | 532 | private JRadioButton _radOCR; | ||
1652 | 533 | private JRadioButton _radOff; | ||
1653 | 534 | private JPanel _paneTextEditing; | ||
1654 | 535 | private JCheckBox _chkExpandTab; | ||
1655 | 536 | private JLabel _lblTabWidth; | ||
1656 | 537 | private JComboBox _cmbFontName; | ||
1657 | 538 | private JLabel _lblFont; | ||
1658 | 539 | private JLabel _titleAppearance; | ||
1659 | 540 | private JLabel _titleIndentation; | ||
1660 | 541 | private JSpinner _spnTabWidth; | ||
1661 | 542 | private JLabel _lblFontSize; | ||
1662 | 543 | private JSpinner _spnFontSize; | ||
1663 | 544 | private JCheckBox _chkAutoUpdate; | ||
1664 | 545 | private JComboBox _cmbLang; | ||
1665 | 546 | private JLabel _lblUpdates; | ||
1666 | 547 | private JLabel _lblLanguage; | ||
1667 | 548 | private JButton _btnOk; | ||
1668 | 549 | private JButton _btnCancel; | ||
1669 | 550 | // JFormDesigner - End of variables declaration //GEN-END:variables | ||
1670 | 551 | } | ||
1671 | 552 | |||
1672 | 553 | class LocaleListCellRenderer extends DefaultListCellRenderer { | ||
1673 | 554 | public Component getListCellRendererComponent(JList list, | ||
1674 | 555 | Object value, int index, boolean isSelected, boolean hasFocus) { | ||
1675 | 556 | Locale locale = (Locale) (value); | ||
1676 | 557 | return super.getListCellRendererComponent(list, | ||
1677 | 558 | locale.getDisplayName(locale), index, isSelected, hasFocus); | ||
1678 | 559 | } | ||
1679 | 560 | } | ||
1680 | 561 | |||
1681 | 562 | 0 | ||
1682 | === removed directory '.pc/native.patch' | |||
1683 | === removed directory '.pc/native.patch/sikuli-script' | |||
1684 | === removed directory '.pc/native.patch/sikuli-script/src' | |||
1685 | === removed directory '.pc/native.patch/sikuli-script/src/main' | |||
1686 | === removed directory '.pc/native.patch/sikuli-script/src/main/java' | |||
1687 | === removed directory '.pc/native.patch/sikuli-script/src/main/java/org' | |||
1688 | === removed directory '.pc/native.patch/sikuli-script/src/main/java/org/sikuli' | |||
1689 | === removed directory '.pc/native.patch/sikuli-script/src/main/java/org/sikuli/script' | |||
1690 | === removed file '.pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/Finder.java' | |||
1691 | --- .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/Finder.java 2012-02-15 15:17:58 +0000 | |||
1692 | +++ .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/Finder.java 1970-01-01 00:00:00 +0000 | |||
1693 | @@ -1,195 +0,0 @@ | |||
1694 | 1 | /* | ||
1695 | 2 | * Copyright 2010-2011, Sikuli.org | ||
1696 | 3 | * Released under the MIT License. | ||
1697 | 4 | * | ||
1698 | 5 | */ | ||
1699 | 6 | package org.sikuli.script; | ||
1700 | 7 | |||
1701 | 8 | import java.awt.*; | ||
1702 | 9 | import java.util.Iterator; | ||
1703 | 10 | import java.io.File; | ||
1704 | 11 | import java.io.IOException; | ||
1705 | 12 | import java.io.FileNotFoundException; | ||
1706 | 13 | |||
1707 | 14 | import org.sikuli.script.natives.FindInput; | ||
1708 | 15 | import org.sikuli.script.natives.FindResult; | ||
1709 | 16 | import org.sikuli.script.natives.FindResults; | ||
1710 | 17 | import org.sikuli.script.natives.Mat; | ||
1711 | 18 | import org.sikuli.script.natives.TARGET_TYPE; | ||
1712 | 19 | import org.sikuli.script.natives.Vision; | ||
1713 | 20 | |||
1714 | 21 | import com.wapmx.nativeutils.jniloader.NativeLoader; | ||
1715 | 22 | |||
1716 | 23 | public class Finder implements Iterator<Match>{ | ||
1717 | 24 | private Region _region = null; | ||
1718 | 25 | private Pattern _pattern = null; | ||
1719 | 26 | private FindInput _findInput = new FindInput(); | ||
1720 | 27 | private FindResults _results = null; | ||
1721 | 28 | private ImageLocator _imgLocator = null; | ||
1722 | 29 | private int _cur_result_i; | ||
1723 | 30 | |||
1724 | 31 | static { | ||
1725 | 32 | try{ | ||
1726 | 33 | NativeLoader.loadLibrary("VisionProxy"); | ||
1727 | 34 | Debug.info("Sikuli vision engine loaded."); | ||
1728 | 35 | } | ||
1729 | 36 | catch(IOException e){ | ||
1730 | 37 | e.printStackTrace(); | ||
1731 | 38 | } | ||
1732 | 39 | //Vision.setParameter("GPU", 1); | ||
1733 | 40 | } | ||
1734 | 41 | |||
1735 | 42 | public Finder __enter__(){ | ||
1736 | 43 | return this; | ||
1737 | 44 | } | ||
1738 | 45 | |||
1739 | 46 | public void __exit__(Object type, Object value, Object trackback){ | ||
1740 | 47 | destroy(); | ||
1741 | 48 | } | ||
1742 | 49 | |||
1743 | 50 | /** | ||
1744 | 51 | * Finder constructor (finding within the desktop screen). | ||
1745 | 52 | */ | ||
1746 | 53 | public Finder(String screenFilename) throws IOException{ | ||
1747 | 54 | this(screenFilename, null); | ||
1748 | 55 | } | ||
1749 | 56 | |||
1750 | 57 | /** | ||
1751 | 58 | * Finder constructor (finding within the given region). | ||
1752 | 59 | */ | ||
1753 | 60 | public Finder(String screenFilename, Region region) throws IOException{ | ||
1754 | 61 | String fname = findImageFile(screenFilename); | ||
1755 | 62 | _findInput.setSource(fname); | ||
1756 | 63 | _region = region; | ||
1757 | 64 | } | ||
1758 | 65 | |||
1759 | 66 | /** | ||
1760 | 67 | * Finder constructor (finding within the given region). | ||
1761 | 68 | */ | ||
1762 | 69 | public Finder(ScreenImage img, Region region){ | ||
1763 | 70 | Mat target = OpenCV.convertBufferedImageToMat(img.getImage()); | ||
1764 | 71 | _findInput.setSource(target); | ||
1765 | 72 | _region = region; | ||
1766 | 73 | } | ||
1767 | 74 | |||
1768 | 75 | public void __del__(){ | ||
1769 | 76 | destroy(); | ||
1770 | 77 | } | ||
1771 | 78 | |||
1772 | 79 | protected void finalize() throws Throwable { | ||
1773 | 80 | destroy(); | ||
1774 | 81 | } | ||
1775 | 82 | |||
1776 | 83 | protected String findImageFile(String file) throws IOException{ | ||
1777 | 84 | if(_imgLocator == null) | ||
1778 | 85 | _imgLocator = new ImageLocator(); | ||
1779 | 86 | return _imgLocator.locate(file); | ||
1780 | 87 | } | ||
1781 | 88 | |||
1782 | 89 | protected <PSC> void setFindInput(PSC ptn) throws IOException{ | ||
1783 | 90 | if( ptn instanceof Pattern ){ | ||
1784 | 91 | _pattern = (Pattern)ptn; | ||
1785 | 92 | Mat targetMat = OpenCV.convertBufferedImageToMat(_pattern.getImage()); | ||
1786 | 93 | _findInput.setTarget(targetMat); | ||
1787 | 94 | _findInput.setSimilarity(_pattern.similarity); | ||
1788 | 95 | } | ||
1789 | 96 | else if( ptn instanceof String){ | ||
1790 | 97 | setTargetSmartly(_findInput, (String)ptn); | ||
1791 | 98 | _findInput.setSimilarity(Settings.MinSimilarity); | ||
1792 | 99 | } | ||
1793 | 100 | } | ||
1794 | 101 | |||
1795 | 102 | protected void setTargetSmartly(FindInput fin, String target){ | ||
1796 | 103 | try{ | ||
1797 | 104 | //assume it's a file first | ||
1798 | 105 | String filename = findImageFile(target); | ||
1799 | 106 | fin.setTarget(TARGET_TYPE.IMAGE, filename); | ||
1800 | 107 | } | ||
1801 | 108 | catch(IOException e){ | ||
1802 | 109 | if(Util.isImageFile(target)) | ||
1803 | 110 | Debug.error(target + " looks like a file, but can't be found on the disk. Assume it's text." ); | ||
1804 | 111 | // this will init text recognizer on demand | ||
1805 | 112 | TextRecognizer tr = TextRecognizer.getInstance(); | ||
1806 | 113 | //assume it's text | ||
1807 | 114 | fin.setTarget(TARGET_TYPE.TEXT, target); | ||
1808 | 115 | } | ||
1809 | 116 | } | ||
1810 | 117 | |||
1811 | 118 | |||
1812 | 119 | |||
1813 | 120 | /** | ||
1814 | 121 | * void find( Pattern/String/PatternClass ) | ||
1815 | 122 | * finds the given pattern in the given ScreenImage. | ||
1816 | 123 | */ | ||
1817 | 124 | public <PSC> void find(PSC ptn) throws IOException{ | ||
1818 | 125 | setFindInput(ptn); | ||
1819 | 126 | _results = Vision.find(_findInput); | ||
1820 | 127 | _cur_result_i = 0; | ||
1821 | 128 | } | ||
1822 | 129 | |||
1823 | 130 | public void find(String templateFilename, double minSimilarity) throws IOException{ | ||
1824 | 131 | setTargetSmartly(_findInput, templateFilename); | ||
1825 | 132 | _findInput.setSimilarity(minSimilarity); | ||
1826 | 133 | _results = Vision.find(_findInput); | ||
1827 | 134 | _cur_result_i = 0; | ||
1828 | 135 | } | ||
1829 | 136 | |||
1830 | 137 | public <PSC> void findAll(PSC ptn) throws IOException { | ||
1831 | 138 | Debug timing = new Debug(); | ||
1832 | 139 | timing.startTiming("Finder.findAll"); | ||
1833 | 140 | |||
1834 | 141 | setFindInput(ptn); | ||
1835 | 142 | _findInput.setFindAll(true); | ||
1836 | 143 | _results = Vision.find(_findInput); | ||
1837 | 144 | _cur_result_i = 0; | ||
1838 | 145 | |||
1839 | 146 | timing.endTiming("Finder.findAll"); | ||
1840 | 147 | } | ||
1841 | 148 | |||
1842 | 149 | public void findAll(String templateFilename, double minSimilarity) throws IOException { | ||
1843 | 150 | Debug timing = new Debug(); | ||
1844 | 151 | timing.startTiming("Finder.findAll"); | ||
1845 | 152 | |||
1846 | 153 | setTargetSmartly(_findInput, templateFilename); | ||
1847 | 154 | _findInput.setSimilarity(minSimilarity); | ||
1848 | 155 | _findInput.setFindAll(true); | ||
1849 | 156 | _results = Vision.find(_findInput); | ||
1850 | 157 | _cur_result_i = 0; | ||
1851 | 158 | |||
1852 | 159 | timing.endTiming("Finder.findAll"); | ||
1853 | 160 | } | ||
1854 | 161 | |||
1855 | 162 | public boolean hasNext(){ | ||
1856 | 163 | if(_results != null && _results.size() > _cur_result_i) | ||
1857 | 164 | return true; | ||
1858 | 165 | return false; | ||
1859 | 166 | } | ||
1860 | 167 | |||
1861 | 168 | |||
1862 | 169 | public Match next(){ | ||
1863 | 170 | Match ret = null; | ||
1864 | 171 | if(hasNext()){ | ||
1865 | 172 | FindResult fr = _results.get(_cur_result_i++); | ||
1866 | 173 | IScreen parentScreen = null; | ||
1867 | 174 | if(_region != null) | ||
1868 | 175 | parentScreen = _region.getScreen(); | ||
1869 | 176 | ret = new Match(fr, parentScreen); | ||
1870 | 177 | if(_region != null){ | ||
1871 | 178 | ret = _region.toGlobalCoord(ret); | ||
1872 | 179 | } | ||
1873 | 180 | if(_pattern != null){ | ||
1874 | 181 | Location offset = _pattern.getTargetOffset(); | ||
1875 | 182 | ret.setTargetOffset(offset); | ||
1876 | 183 | } | ||
1877 | 184 | } | ||
1878 | 185 | return ret; | ||
1879 | 186 | } | ||
1880 | 187 | |||
1881 | 188 | public void remove(){ | ||
1882 | 189 | } | ||
1883 | 190 | |||
1884 | 191 | public void destroy(){ | ||
1885 | 192 | } | ||
1886 | 193 | |||
1887 | 194 | } | ||
1888 | 195 | |||
1889 | 196 | 0 | ||
1890 | === removed file '.pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/TextRecognizer.java' | |||
1891 | --- .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/TextRecognizer.java 2012-02-15 15:17:58 +0000 | |||
1892 | +++ .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/TextRecognizer.java 1970-01-01 00:00:00 +0000 | |||
1893 | @@ -1,120 +0,0 @@ | |||
1894 | 1 | /* | ||
1895 | 2 | * Copyright 2010-2011, Sikuli.org | ||
1896 | 3 | * Released under the MIT License. | ||
1897 | 4 | * | ||
1898 | 5 | */ | ||
1899 | 6 | package org.sikuli.script; | ||
1900 | 7 | |||
1901 | 8 | import java.awt.image.*; | ||
1902 | 9 | import java.io.*; | ||
1903 | 10 | import java.net.URL; | ||
1904 | 11 | import java.util.Enumeration; | ||
1905 | 12 | import java.util.List; | ||
1906 | 13 | import java.util.LinkedList; | ||
1907 | 14 | |||
1908 | 15 | import org.sikuli.script.natives.Mat; | ||
1909 | 16 | import org.sikuli.script.natives.Vision; | ||
1910 | 17 | import org.sikuli.script.natives.OCRWord; | ||
1911 | 18 | import org.sikuli.script.natives.OCRWords; | ||
1912 | 19 | |||
1913 | 20 | import com.wapmx.nativeutils.jniloader.NativeLoader; | ||
1914 | 21 | |||
1915 | 22 | // Singleton | ||
1916 | 23 | public class TextRecognizer { | ||
1917 | 24 | protected static TextRecognizer _instance = null; | ||
1918 | 25 | |||
1919 | 26 | static { | ||
1920 | 27 | try{ | ||
1921 | 28 | NativeLoader.loadLibrary("VisionProxy"); | ||
1922 | 29 | TextRecognizer tr = TextRecognizer.getInstance(); | ||
1923 | 30 | } | ||
1924 | 31 | catch(IOException e){ | ||
1925 | 32 | e.printStackTrace(); | ||
1926 | 33 | } | ||
1927 | 34 | } | ||
1928 | 35 | |||
1929 | 36 | protected TextRecognizer(){ | ||
1930 | 37 | init(); | ||
1931 | 38 | } | ||
1932 | 39 | |||
1933 | 40 | boolean _init_succeeded = false; | ||
1934 | 41 | |||
1935 | 42 | public void init(){ | ||
1936 | 43 | Debug.info("Text Recognizer inited."); | ||
1937 | 44 | try{ | ||
1938 | 45 | String path = ResourceExtractor.extract("tessdata"); | ||
1939 | 46 | // TESSDATA_PREFIX doesn't contain tessdata/ | ||
1940 | 47 | if(path.endsWith("tessdata/")) | ||
1941 | 48 | path = path.substring(0,path.length()-9); | ||
1942 | 49 | Settings.OcrDataPath = path; | ||
1943 | 50 | Debug.log(3, "OCR data path: " + path); | ||
1944 | 51 | |||
1945 | 52 | Vision.initOCR(Settings.OcrDataPath); | ||
1946 | 53 | _init_succeeded = true; | ||
1947 | 54 | } | ||
1948 | 55 | catch(IOException e){ | ||
1949 | 56 | e.printStackTrace(); | ||
1950 | 57 | }catch(Exception e){ | ||
1951 | 58 | e.printStackTrace(); | ||
1952 | 59 | } | ||
1953 | 60 | } | ||
1954 | 61 | |||
1955 | 62 | public static TextRecognizer getInstance(){ | ||
1956 | 63 | if(_instance==null) | ||
1957 | 64 | _instance = new TextRecognizer(); | ||
1958 | 65 | return _instance; | ||
1959 | 66 | } | ||
1960 | 67 | |||
1961 | 68 | public enum ListTextMode { | ||
1962 | 69 | WORD, LINE, PARAGRAPH | ||
1963 | 70 | }; | ||
1964 | 71 | |||
1965 | 72 | public List<Match> listText(ScreenImage simg, Region parent){ | ||
1966 | 73 | return listText(simg, parent, ListTextMode.WORD); | ||
1967 | 74 | } | ||
1968 | 75 | |||
1969 | 76 | //TODO: support LINE and PARAGRAPH | ||
1970 | 77 | // listText only supports WORD mode now. | ||
1971 | 78 | public List<Match> listText(ScreenImage simg, Region parent, ListTextMode mode){ | ||
1972 | 79 | Mat mat = OpenCV.convertBufferedImageToMat(simg.getImage()); | ||
1973 | 80 | OCRWords words = Vision.recognize_as_ocrtext(mat).getWords(); | ||
1974 | 81 | List<Match> ret = new LinkedList<Match>(); | ||
1975 | 82 | for(int i=0;i<words.size();i++){ | ||
1976 | 83 | OCRWord w = words.get(i); | ||
1977 | 84 | Match m = new Match(parent.x+w.getX(), parent.y+w.getY(), w.getWidth(), w.getHeight(), | ||
1978 | 85 | w.getScore(), parent.getScreen(), w.getString()); | ||
1979 | 86 | ret.add(m); | ||
1980 | 87 | } | ||
1981 | 88 | return ret; | ||
1982 | 89 | } | ||
1983 | 90 | |||
1984 | 91 | |||
1985 | 92 | public String recognize(ScreenImage simg){ | ||
1986 | 93 | BufferedImage img = simg.getImage(); | ||
1987 | 94 | return recognize(img); | ||
1988 | 95 | } | ||
1989 | 96 | |||
1990 | 97 | public String recognize(BufferedImage img){ | ||
1991 | 98 | if (_init_succeeded){ | ||
1992 | 99 | Mat mat = OpenCV.convertBufferedImageToMat(img); | ||
1993 | 100 | return Vision.recognize(mat).trim(); | ||
1994 | 101 | }else{ | ||
1995 | 102 | return ""; | ||
1996 | 103 | } | ||
1997 | 104 | } | ||
1998 | 105 | |||
1999 | 106 | public String recognizeWord(ScreenImage simg){ | ||
2000 | 107 | BufferedImage img = simg.getImage(); | ||
2001 | 108 | return recognizeWord(img); | ||
2002 | 109 | } | ||
2003 | 110 | |||
2004 | 111 | public String recognizeWord(BufferedImage img){ | ||
2005 | 112 | if (_init_succeeded){ | ||
2006 | 113 | Mat mat = OpenCV.convertBufferedImageToMat(img); | ||
2007 | 114 | return Vision.recognizeWord(mat).trim(); | ||
2008 | 115 | }else{ | ||
2009 | 116 | return ""; | ||
2010 | 117 | } | ||
2011 | 118 | } | ||
2012 | 119 | } | ||
2013 | 120 | |||
2014 | 121 | 0 | ||
2015 | === removed file '.pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/VDictProxy.java' | |||
2016 | --- .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/VDictProxy.java 2011-10-04 00:57:09 +0000 | |||
2017 | +++ .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/VDictProxy.java 1970-01-01 00:00:00 +0000 | |||
2018 | @@ -1,118 +0,0 @@ | |||
2019 | 1 | /* | ||
2020 | 2 | * Copyright 2010-2011, Sikuli.org | ||
2021 | 3 | * Released under the MIT License. | ||
2022 | 4 | * | ||
2023 | 5 | */ | ||
2024 | 6 | package org.sikuli.script; | ||
2025 | 7 | |||
2026 | 8 | import java.io.File; | ||
2027 | 9 | import java.io.IOException; | ||
2028 | 10 | import java.io.FileNotFoundException; | ||
2029 | 11 | import java.util.Vector; | ||
2030 | 12 | import java.util.HashMap; | ||
2031 | 13 | import java.util.Map; | ||
2032 | 14 | import java.util.List; | ||
2033 | 15 | import com.wapmx.nativeutils.jniloader.NativeLoader; | ||
2034 | 16 | |||
2035 | 17 | public class VDictProxy<T> { | ||
2036 | 18 | private long _instance; | ||
2037 | 19 | private Map<Integer, T> _i2obj = new HashMap<Integer, T>(); | ||
2038 | 20 | |||
2039 | 21 | static { | ||
2040 | 22 | // load libScreenMatchProxy.{so,jnilib} | ||
2041 | 23 | //System.loadLibrary("ScreenMatchProxy"); | ||
2042 | 24 | try{ | ||
2043 | 25 | NativeLoader.loadLibrary("VDictProxy"); | ||
2044 | 26 | Debug.info("VDictProxy loaded."); | ||
2045 | 27 | } | ||
2046 | 28 | catch(IOException e){ | ||
2047 | 29 | e.printStackTrace(); | ||
2048 | 30 | } | ||
2049 | 31 | } | ||
2050 | 32 | |||
2051 | 33 | public VDictProxy(){ | ||
2052 | 34 | _instance = getInstance(); | ||
2053 | 35 | } | ||
2054 | 36 | |||
2055 | 37 | private native long getInstance(); | ||
2056 | 38 | |||
2057 | 39 | private String getAbsolutePath(String filename) throws FileNotFoundException{ | ||
2058 | 40 | if(new File(filename).exists()) | ||
2059 | 41 | return filename; | ||
2060 | 42 | filename = Settings.BundlePath + File.separator + filename; | ||
2061 | 43 | if(new File(filename).exists()) | ||
2062 | 44 | return filename; | ||
2063 | 45 | throw new FileNotFoundException("No such file: " + filename); | ||
2064 | 46 | } | ||
2065 | 47 | |||
2066 | 48 | // insert an (key,value) entry using an image key | ||
2067 | 49 | public void insert(String imagekey_filename, T value) throws FileNotFoundException { | ||
2068 | 50 | imagekey_filename = getAbsolutePath(imagekey_filename); | ||
2069 | 51 | int hash = value.hashCode(); | ||
2070 | 52 | while(true){ | ||
2071 | 53 | if( hash != -1 && !_i2obj.containsKey(hash) ){ | ||
2072 | 54 | _i2obj.put(hash, value); | ||
2073 | 55 | break; | ||
2074 | 56 | } | ||
2075 | 57 | else{ | ||
2076 | 58 | hash += (int)(Math.random()*100); | ||
2077 | 59 | } | ||
2078 | 60 | } | ||
2079 | 61 | _insert(_instance, imagekey_filename, hash); | ||
2080 | 62 | } | ||
2081 | 63 | |||
2082 | 64 | public native void _insert(long instance, String imagekey_filename, int value); | ||
2083 | 65 | |||
2084 | 66 | // lookup the entry using an image key (exact match) | ||
2085 | 67 | public T lookup(String imagekey_filename) throws FileNotFoundException{ | ||
2086 | 68 | imagekey_filename = getAbsolutePath(imagekey_filename); | ||
2087 | 69 | int hash = _lookup(_instance, imagekey_filename); | ||
2088 | 70 | if(hash==-1) return null; | ||
2089 | 71 | return _i2obj.get(hash); | ||
2090 | 72 | } | ||
2091 | 73 | |||
2092 | 74 | private native int _lookup(long instance, String imagekey_filename); | ||
2093 | 75 | |||
2094 | 76 | // lookup the first entry with a similar image key | ||
2095 | 77 | public T lookup_similar(String imagekey_filename, double similarity_threshold) throws FileNotFoundException{ | ||
2096 | 78 | imagekey_filename = getAbsolutePath(imagekey_filename); | ||
2097 | 79 | int hash = _lookup_similar(_instance, imagekey_filename, similarity_threshold); | ||
2098 | 80 | if(hash==-1) return null; | ||
2099 | 81 | return _i2obj.get(hash); | ||
2100 | 82 | } | ||
2101 | 83 | |||
2102 | 84 | private native int _lookup_similar(long instance, String imagekey_filename, double similarity_threshold); | ||
2103 | 85 | |||
2104 | 86 | // lookup at most n entries with keys similar to the given image (n = 0 : all) | ||
2105 | 87 | public List<T> lookup_similar_n(String imagekey_filename, double similarity_threshold, int n) throws FileNotFoundException{ | ||
2106 | 88 | imagekey_filename = getAbsolutePath(imagekey_filename); | ||
2107 | 89 | int h[] = _lookup_similar_n(_instance, imagekey_filename, similarity_threshold, n); | ||
2108 | 90 | List<T> ret = new Vector<T>(h.length); | ||
2109 | 91 | for(int i=0;i<h.length;i++){ | ||
2110 | 92 | if(h[i] == -1) | ||
2111 | 93 | ret.add(i, null); | ||
2112 | 94 | else | ||
2113 | 95 | ret.add(i, _i2obj.get(h[i])); | ||
2114 | 96 | } | ||
2115 | 97 | return ret; | ||
2116 | 98 | } | ||
2117 | 99 | |||
2118 | 100 | private native int[] _lookup_similar_n(long instance, String imagekey_filename, double similarity_threshold, int n); | ||
2119 | 101 | |||
2120 | 102 | // erase the entry associated with the image | ||
2121 | 103 | public void erase(String imagekey_filename) throws FileNotFoundException{ | ||
2122 | 104 | imagekey_filename = getAbsolutePath(imagekey_filename); | ||
2123 | 105 | int h = _lookup(_instance, imagekey_filename); | ||
2124 | 106 | if(h!=-1) _i2obj.remove(h); | ||
2125 | 107 | _erase(_instance, imagekey_filename); | ||
2126 | 108 | } | ||
2127 | 109 | |||
2128 | 110 | private native void _erase(long _instance, String imagekey_filename); | ||
2129 | 111 | |||
2130 | 112 | public int size(){ return _size(_instance); } | ||
2131 | 113 | private native int _size(long instance); // return the number of image keys stored | ||
2132 | 114 | |||
2133 | 115 | public boolean empty(){ return _empty(_instance); } | ||
2134 | 116 | private native boolean _empty(long instance); // test whether it is empty | ||
2135 | 117 | } | ||
2136 | 118 | |||
2137 | 119 | 0 | ||
2138 | === removed directory '.pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/internal' | |||
2139 | === removed directory '.pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/internal/hotkey' | |||
2140 | === removed file '.pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/internal/hotkey/LinuxHotkeyManager.java' | |||
2141 | --- .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/internal/hotkey/LinuxHotkeyManager.java 2011-10-04 00:57:09 +0000 | |||
2142 | +++ .pc/native.patch/sikuli-script/src/main/java/org/sikuli/script/internal/hotkey/LinuxHotkeyManager.java 1970-01-01 00:00:00 +0000 | |||
2143 | @@ -1,106 +0,0 @@ | |||
2144 | 1 | /* | ||
2145 | 2 | * Copyright 2010-2011, Sikuli.org | ||
2146 | 3 | * Released under the MIT License. | ||
2147 | 4 | * | ||
2148 | 5 | */ | ||
2149 | 6 | package org.sikuli.script.internal.hotkey; | ||
2150 | 7 | |||
2151 | 8 | import java.lang.reflect.*; | ||
2152 | 9 | import java.awt.Event; | ||
2153 | 10 | import java.awt.event.*; | ||
2154 | 11 | import java.util.*; | ||
2155 | 12 | import java.io.IOException; | ||
2156 | 13 | |||
2157 | 14 | import org.sikuli.script.Debug; | ||
2158 | 15 | import org.sikuli.script.HotkeyListener; | ||
2159 | 16 | import org.sikuli.script.HotkeyEvent; | ||
2160 | 17 | |||
2161 | 18 | import com.wapmx.nativeutils.jniloader.NativeLoader; | ||
2162 | 19 | import jxgrabkey.HotkeyConflictException; | ||
2163 | 20 | import jxgrabkey.JXGrabKey; | ||
2164 | 21 | |||
2165 | 22 | public class LinuxHotkeyManager extends HotkeyManager { | ||
2166 | 23 | static{ | ||
2167 | 24 | try{ | ||
2168 | 25 | NativeLoader.loadLibrary("JXGrabKey"); | ||
2169 | 26 | } | ||
2170 | 27 | catch(IOException e){ | ||
2171 | 28 | Debug.error("Can't load native lib JXGrabKey"); | ||
2172 | 29 | e.printStackTrace(); | ||
2173 | 30 | } | ||
2174 | 31 | } | ||
2175 | 32 | |||
2176 | 33 | class HotkeyData { | ||
2177 | 34 | int key, modifiers; | ||
2178 | 35 | HotkeyListener listener; | ||
2179 | 36 | |||
2180 | 37 | public HotkeyData(int key_, int mod_, HotkeyListener l_){ | ||
2181 | 38 | key = key_; | ||
2182 | 39 | modifiers = mod_; | ||
2183 | 40 | listener = l_; | ||
2184 | 41 | } | ||
2185 | 42 | }; | ||
2186 | 43 | |||
2187 | 44 | class MyHotkeyHandler implements jxgrabkey.HotkeyListener{ | ||
2188 | 45 | public void onHotkey(int id){ | ||
2189 | 46 | Debug.log(4, "Hotkey pressed"); | ||
2190 | 47 | HotkeyData data = _idCallbackMap.get(id); | ||
2191 | 48 | HotkeyEvent e = new HotkeyEvent(data.key, data.modifiers); | ||
2192 | 49 | data.listener.invokeHotkeyPressed(e); | ||
2193 | 50 | } | ||
2194 | 51 | }; | ||
2195 | 52 | |||
2196 | 53 | private Map<Integer, HotkeyData> _idCallbackMap = new HashMap<Integer,HotkeyData >(); | ||
2197 | 54 | private int _gHotkeyId = 1; | ||
2198 | 55 | |||
2199 | 56 | public boolean _addHotkey(int keyCode, int modifiers, HotkeyListener listener){ | ||
2200 | 57 | JXGrabKey grabKey = JXGrabKey.getInstance(); | ||
2201 | 58 | |||
2202 | 59 | if(_gHotkeyId == 1){ | ||
2203 | 60 | grabKey.addHotkeyListener(new MyHotkeyHandler()); | ||
2204 | 61 | } | ||
2205 | 62 | |||
2206 | 63 | _removeHotkey(keyCode, modifiers); | ||
2207 | 64 | int id = _gHotkeyId++; | ||
2208 | 65 | HotkeyData data = new HotkeyData(keyCode, modifiers, listener); | ||
2209 | 66 | _idCallbackMap.put(id, data); | ||
2210 | 67 | |||
2211 | 68 | try{ | ||
2212 | 69 | //JXGrabKey.setDebugOutput(true); | ||
2213 | 70 | grabKey.registerAwtHotkey(id, modifiers, keyCode); | ||
2214 | 71 | }catch(HotkeyConflictException e){ | ||
2215 | 72 | Debug.error("Hot key conflicts"); | ||
2216 | 73 | return false; | ||
2217 | 74 | } | ||
2218 | 75 | return true; | ||
2219 | 76 | } | ||
2220 | 77 | |||
2221 | 78 | public boolean _removeHotkey(int keyCode, int modifiers){ | ||
2222 | 79 | for( Map.Entry<Integer, HotkeyData> entry : _idCallbackMap.entrySet() ){ | ||
2223 | 80 | HotkeyData data = entry.getValue(); | ||
2224 | 81 | if(data.key == keyCode && data.modifiers == modifiers){ | ||
2225 | 82 | JXGrabKey grabKey = JXGrabKey.getInstance(); | ||
2226 | 83 | int id = entry.getKey(); | ||
2227 | 84 | grabKey.unregisterHotKey(id); | ||
2228 | 85 | _idCallbackMap.remove(id); | ||
2229 | 86 | return true; | ||
2230 | 87 | } | ||
2231 | 88 | } | ||
2232 | 89 | return false; | ||
2233 | 90 | } | ||
2234 | 91 | |||
2235 | 92 | |||
2236 | 93 | public void cleanUp(){ | ||
2237 | 94 | JXGrabKey grabKey = JXGrabKey.getInstance(); | ||
2238 | 95 | for( Map.Entry<Integer, HotkeyData> entry : _idCallbackMap.entrySet() ){ | ||
2239 | 96 | int id = entry.getKey(); | ||
2240 | 97 | grabKey.unregisterHotKey(id); | ||
2241 | 98 | } | ||
2242 | 99 | _gHotkeyId = 1; | ||
2243 | 100 | _idCallbackMap.clear(); | ||
2244 | 101 | grabKey.getInstance().cleanUp(); | ||
2245 | 102 | } | ||
2246 | 103 | |||
2247 | 104 | } | ||
2248 | 105 | |||
2249 | 106 | |||
2250 | 107 | 0 | ||
2251 | === removed directory '.pc/native.patch/sikuli-script/src/main/native' | |||
2252 | === removed file '.pc/native.patch/sikuli-script/src/main/native/vision.i' | |||
2253 | --- .pc/native.patch/sikuli-script/src/main/native/vision.i 2012-02-15 15:17:58 +0000 | |||
2254 | +++ .pc/native.patch/sikuli-script/src/main/native/vision.i 1970-01-01 00:00:00 +0000 | |||
2255 | @@ -1,264 +0,0 @@ | |||
2256 | 1 | %module VisionProxy | ||
2257 | 2 | %{ | ||
2258 | 3 | #include "vision.h" | ||
2259 | 4 | #include "sikuli-debug.h" | ||
2260 | 5 | #include <iostream> | ||
2261 | 6 | #include "opencv.hpp" | ||
2262 | 7 | #include "cvgui.h" | ||
2263 | 8 | #include "tessocr.h" | ||
2264 | 9 | %} | ||
2265 | 10 | |||
2266 | 11 | %include "std_vector.i" | ||
2267 | 12 | %include "std_string.i" | ||
2268 | 13 | %include "typemaps.i" | ||
2269 | 14 | %include "various.i" | ||
2270 | 15 | |||
2271 | 16 | %pragma(java) jniclassimports=%{ | ||
2272 | 17 | import com.wapmx.nativeutils.jniloader.NativeLoader; | ||
2273 | 18 | %} | ||
2274 | 19 | |||
2275 | 20 | %pragma(java) jniclasscode=%{ | ||
2276 | 21 | static { | ||
2277 | 22 | try { | ||
2278 | 23 | NativeLoader.loadLibrary("VisionProxy"); | ||
2279 | 24 | } catch (Exception e) { | ||
2280 | 25 | System.err.println("Failed to load VisionProxy.\n" + e); | ||
2281 | 26 | } | ||
2282 | 27 | } | ||
2283 | 28 | %} | ||
2284 | 29 | |||
2285 | 30 | |||
2286 | 31 | %template(FindResults) std::vector<FindResult>; | ||
2287 | 32 | |||
2288 | 33 | %template(OCRChars) std::vector<OCRChar>; | ||
2289 | 34 | %template(OCRWords) std::vector<OCRWord>; | ||
2290 | 35 | %template(OCRLines) std::vector<OCRLine>; | ||
2291 | 36 | %template(OCRParagraphs) std::vector<OCRParagraph>; | ||
2292 | 37 | |||
2293 | 38 | %typemap(jni) unsigned char* "jbyteArray" | ||
2294 | 39 | %typemap(jtype) unsigned char* "byte[]" | ||
2295 | 40 | %typemap(jstype) unsigned char* "byte[]" | ||
2296 | 41 | |||
2297 | 42 | // Map input argument: java byte[] -> C++ unsigned char * | ||
2298 | 43 | %typemap(in) unsigned char* { | ||
2299 | 44 | long len = JCALL1(GetArrayLength, jenv, $input); | ||
2300 | 45 | $1 = (unsigned char *)malloc(len + 1); | ||
2301 | 46 | if ($1 == 0) { | ||
2302 | 47 | std::cerr << "out of memory\n"; | ||
2303 | 48 | return 0; | ||
2304 | 49 | } | ||
2305 | 50 | JCALL4(GetByteArrayRegion, jenv, $input, 0, len, (jbyte *)$1); | ||
2306 | 51 | } | ||
2307 | 52 | |||
2308 | 53 | %typemap(freearg) unsigned char* %{ | ||
2309 | 54 | free($1); | ||
2310 | 55 | %} | ||
2311 | 56 | |||
2312 | 57 | // change Java wrapper output mapping for unsigned char* | ||
2313 | 58 | %typemap(javaout) unsigned char* { | ||
2314 | 59 | return $jnicall; | ||
2315 | 60 | } | ||
2316 | 61 | |||
2317 | 62 | %typemap(javain) unsigned char* "$javainput" | ||
2318 | 63 | |||
2319 | 64 | |||
2320 | 65 | struct FindResult { | ||
2321 | 66 | int x, y; | ||
2322 | 67 | int w, h; | ||
2323 | 68 | double score; | ||
2324 | 69 | FindResult(){ | ||
2325 | 70 | x=0;y=0;w=0;h=0;score=-1;text = ""; | ||
2326 | 71 | } | ||
2327 | 72 | FindResult(int _x, int _y, int _w, int _h, double _score){ | ||
2328 | 73 | x = _x; y = _y; | ||
2329 | 74 | w = _w; h = _h; | ||
2330 | 75 | score = _score; | ||
2331 | 76 | text = ""; | ||
2332 | 77 | } | ||
2333 | 78 | |||
2334 | 79 | std::string text; | ||
2335 | 80 | }; | ||
2336 | 81 | |||
2337 | 82 | class OCRRect { | ||
2338 | 83 | |||
2339 | 84 | public: | ||
2340 | 85 | |||
2341 | 86 | OCRRect(); | ||
2342 | 87 | OCRRect(int x_, int y_, int width_, int height_); | ||
2343 | 88 | |||
2344 | 89 | int x; | ||
2345 | 90 | int y; | ||
2346 | 91 | int height; | ||
2347 | 92 | int width; | ||
2348 | 93 | |||
2349 | 94 | }; | ||
2350 | 95 | |||
2351 | 96 | class OCRChar : public OCRRect{ | ||
2352 | 97 | |||
2353 | 98 | public: | ||
2354 | 99 | |||
2355 | 100 | OCRChar(const std::string& ch_, int x_, int y_, int width_, int height_) | ||
2356 | 101 | : ch(ch_), OCRRect(x_,y_,width_,height_){}; | ||
2357 | 102 | |||
2358 | 103 | std::string ch; | ||
2359 | 104 | }; | ||
2360 | 105 | |||
2361 | 106 | class OCRWord : public OCRRect { | ||
2362 | 107 | |||
2363 | 108 | public: | ||
2364 | 109 | float score; | ||
2365 | 110 | std::string getString(); | ||
2366 | 111 | |||
2367 | 112 | std::vector<OCRChar> getChars(); | ||
2368 | 113 | }; | ||
2369 | 114 | |||
2370 | 115 | class OCRLine : public OCRRect{ | ||
2371 | 116 | public: | ||
2372 | 117 | |||
2373 | 118 | std::string getString(); | ||
2374 | 119 | std::vector<OCRWord> getWords(); | ||
2375 | 120 | |||
2376 | 121 | }; | ||
2377 | 122 | |||
2378 | 123 | class OCRParagraph : public OCRRect{ | ||
2379 | 124 | public: | ||
2380 | 125 | |||
2381 | 126 | std::vector<OCRLine> getLines(); | ||
2382 | 127 | |||
2383 | 128 | }; | ||
2384 | 129 | |||
2385 | 130 | class OCRText : public OCRRect{ | ||
2386 | 131 | |||
2387 | 132 | public: | ||
2388 | 133 | |||
2389 | 134 | std::string getString(); | ||
2390 | 135 | |||
2391 | 136 | std::vector<OCRWord> getWords(); | ||
2392 | 137 | std::vector<OCRParagraph> getParagraphs(); | ||
2393 | 138 | |||
2394 | 139 | }; | ||
2395 | 140 | |||
2396 | 141 | class Blob : public cv::Rect{ | ||
2397 | 142 | |||
2398 | 143 | public: | ||
2399 | 144 | |||
2400 | 145 | Blob(){}; | ||
2401 | 146 | Blob(const cv::Rect& rect); | ||
2402 | 147 | |||
2403 | 148 | bool isContainedBy(Blob& b); | ||
2404 | 149 | |||
2405 | 150 | double area; | ||
2406 | 151 | int mb; | ||
2407 | 152 | int mg; | ||
2408 | 153 | int mr; | ||
2409 | 154 | int score; | ||
2410 | 155 | }; | ||
2411 | 156 | |||
2412 | 157 | %include "enumtypeunsafe.swg" | ||
2413 | 158 | %javaconst(1); | ||
2414 | 159 | enum TARGET_TYPE{ | ||
2415 | 160 | IMAGE, | ||
2416 | 161 | TEXT, | ||
2417 | 162 | BUTTON | ||
2418 | 163 | }; | ||
2419 | 164 | |||
2420 | 165 | namespace sikuli { | ||
2421 | 166 | |||
2422 | 167 | class FindInput{ | ||
2423 | 168 | |||
2424 | 169 | public: | ||
2425 | 170 | |||
2426 | 171 | FindInput(); | ||
2427 | 172 | FindInput(cv::Mat source, cv::Mat target); | ||
2428 | 173 | FindInput(cv::Mat source, int target_type, const char* target); | ||
2429 | 174 | |||
2430 | 175 | FindInput(const char* source_filename, int target_type, const char* target); | ||
2431 | 176 | |||
2432 | 177 | FindInput(cv::Mat source, int target_type); | ||
2433 | 178 | FindInput(const char* source_filename, int target_type); | ||
2434 | 179 | |||
2435 | 180 | // copy everything in 'other' except for the source image | ||
2436 | 181 | FindInput(cv::Mat source, const FindInput other); | ||
2437 | 182 | |||
2438 | 183 | void setSource(const char* source_filename); | ||
2439 | 184 | void setTarget(int target_type, const char* target_string); | ||
2440 | 185 | |||
2441 | 186 | void setSource(cv::Mat source); | ||
2442 | 187 | void setTarget(cv::Mat target); | ||
2443 | 188 | |||
2444 | 189 | cv::Mat getSourceMat(); | ||
2445 | 190 | cv::Mat getTargetMat(); | ||
2446 | 191 | |||
2447 | 192 | void setFindAll(bool all); | ||
2448 | 193 | bool isFindingAll(); | ||
2449 | 194 | |||
2450 | 195 | void setLimit(int limit); | ||
2451 | 196 | int getLimit(); | ||
2452 | 197 | |||
2453 | 198 | void setSimilarity(double similarity); | ||
2454 | 199 | double getSimilarity(); | ||
2455 | 200 | |||
2456 | 201 | int getTargetType(); | ||
2457 | 202 | |||
2458 | 203 | std::string getTargetText(); | ||
2459 | 204 | }; | ||
2460 | 205 | |||
2461 | 206 | class Vision{ | ||
2462 | 207 | public: | ||
2463 | 208 | |||
2464 | 209 | static std::vector<FindResult> find(FindInput q); | ||
2465 | 210 | static std::vector<FindResult> findChanges(FindInput q); | ||
2466 | 211 | |||
2467 | 212 | static double compare(cv::Mat m1, cv::Mat m2); | ||
2468 | 213 | |||
2469 | 214 | static void initOCR(const char* ocrDataPath); | ||
2470 | 215 | |||
2471 | 216 | static std::string query(const char* index_filename, cv::Mat image); | ||
2472 | 217 | |||
2473 | 218 | static OCRText recognize_as_ocrtext(cv::Mat image); | ||
2474 | 219 | |||
2475 | 220 | static std::vector<FindResult> findBlobs(const cv::Mat& image, bool textOnly=false); | ||
2476 | 221 | |||
2477 | 222 | static std::vector<FindResult> findTextBlobs(const cv::Mat& image); | ||
2478 | 223 | |||
2479 | 224 | static std::string recognize(cv::Mat image); | ||
2480 | 225 | static std::string recognizeWord(cv::Mat image); | ||
2481 | 226 | |||
2482 | 227 | //helper functions | ||
2483 | 228 | static cv::Mat createMat(int _rows, int _cols, unsigned char* _data); | ||
2484 | 229 | |||
2485 | 230 | static void setParameter(std::string param, float val); | ||
2486 | 231 | static float getParameter(std::string param); | ||
2487 | 232 | |||
2488 | 233 | private: | ||
2489 | 234 | |||
2490 | 235 | }; | ||
2491 | 236 | |||
2492 | 237 | |||
2493 | 238 | enum DebugCategories { | ||
2494 | 239 | OCR, FINDER | ||
2495 | 240 | }; | ||
2496 | 241 | void setDebug(DebugCategories cat, int level); | ||
2497 | 242 | |||
2498 | 243 | |||
2499 | 244 | |||
2500 | 245 | } | ||
2501 | 246 | |||
2502 | 247 | class OCR { | ||
2503 | 248 | public: | ||
2504 | 249 | static void setParameter(std::string param, std::string value); | ||
2505 | 250 | }; | ||
2506 | 251 | |||
2507 | 252 | |||
2508 | 253 | namespace cv{ | ||
2509 | 254 | class Mat { | ||
2510 | 255 | int _w, _h; | ||
2511 | 256 | unsigned char* _data; | ||
2512 | 257 | |||
2513 | 258 | public: | ||
2514 | 259 | //Mat(int _rows, int _cols, int _type, unsigned char* _data); | ||
2515 | 260 | }; | ||
2516 | 261 | |||
2517 | 262 | } | ||
2518 | 263 | |||
2519 | 264 | |||
2520 | 265 | 0 | ||
2521 | === removed directory '.pc/no-opencv-surf-module.patch' | |||
2522 | === removed directory '.pc/no-opencv-surf-module.patch/sikuli-script' | |||
2523 | === removed directory '.pc/no-opencv-surf-module.patch/sikuli-script/src' | |||
2524 | === removed directory '.pc/no-opencv-surf-module.patch/sikuli-script/src/main' | |||
2525 | === removed directory '.pc/no-opencv-surf-module.patch/sikuli-script/src/main/native' | |||
2526 | === removed file '.pc/no-opencv-surf-module.patch/sikuli-script/src/main/native/cvgui.cpp' | |||
2527 | --- .pc/no-opencv-surf-module.patch/sikuli-script/src/main/native/cvgui.cpp 2012-06-25 12:33:23 +0000 | |||
2528 | +++ .pc/no-opencv-surf-module.patch/sikuli-script/src/main/native/cvgui.cpp 1970-01-01 00:00:00 +0000 | |||
2529 | @@ -1,2508 +0,0 @@ | |||
2530 | 1 | /* | ||
2531 | 2 | * Copyright 2010-2011, Sikuli.org | ||
2532 | 3 | * Released under the MIT License. | ||
2533 | 4 | * | ||
2534 | 5 | */ | ||
2535 | 6 | #include "cvgui.h" | ||
2536 | 7 | #include "sikuli-debug.h" | ||
2537 | 8 | #include <iostream> | ||
2538 | 9 | using namespace std; | ||
2539 | 10 | using namespace sikuli; | ||
2540 | 11 | |||
2541 | 12 | |||
2542 | 13 | Scalar Color::RED(0,0,255); | ||
2543 | 14 | Scalar Color::WHITE(255,255,255); | ||
2544 | 15 | |||
2545 | 16 | Scalar Color::RANDOM() { | ||
2546 | 17 | return Scalar(rand()&255, rand()&255, rand()&255); | ||
2547 | 18 | }; | ||
2548 | 19 | |||
2549 | 20 | static bool sort_by_x (Rect a, Rect b){ | ||
2550 | 21 | return (a.x < b.x); | ||
2551 | 22 | } | ||
2552 | 23 | |||
2553 | 24 | static bool sort_blob_by_x(Blob a, Blob b){ | ||
2554 | 25 | return (a.x < b.x); | ||
2555 | 26 | } | ||
2556 | 27 | |||
2557 | 28 | static bool sort_blob_by_y(Blob a, Blob b){ | ||
2558 | 29 | return (a.y < b.y); | ||
2559 | 30 | } | ||
2560 | 31 | |||
2561 | 32 | #define SHOW(x) namedWindow(#x,1); imshow(#x,x); | ||
2562 | 33 | #define SHOW0(x) namedWindow(#x,1); imshow(#x,x); waitKey(0); | ||
2563 | 34 | |||
2564 | 35 | //class VisualLogger{ | ||
2565 | 36 | // | ||
2566 | 37 | // | ||
2567 | 38 | // int image_i; | ||
2568 | 39 | // int step_i; | ||
2569 | 40 | // char* prefix; | ||
2570 | 41 | // | ||
2571 | 42 | //public: | ||
2572 | 43 | // | ||
2573 | 44 | // VisualLogger(){ | ||
2574 | 45 | // } | ||
2575 | 46 | // | ||
2576 | 47 | // static void newImage(){ | ||
2577 | 48 | // image_i++; | ||
2578 | 49 | // step_i = 0; | ||
2579 | 50 | // } | ||
2580 | 51 | // | ||
2581 | 52 | // static void log(const char* name, const Mat& image){ | ||
2582 | 53 | // char buf[200]; | ||
2583 | 54 | // | ||
2584 | 55 | // if (prefix){ | ||
2585 | 56 | // | ||
2586 | 57 | // sprintf(buf, "%s-%02d-%s.vlog.png", prefix, step_i, name); | ||
2587 | 58 | // | ||
2588 | 59 | // }else{ | ||
2589 | 60 | // sprintf(buf, "%03d-%02d-%s.vlog.png",image_i,step_i,name); | ||
2590 | 61 | // } | ||
2591 | 62 | // | ||
2592 | 63 | // imwrite(buf, image); | ||
2593 | 64 | // | ||
2594 | 65 | // step_i++; | ||
2595 | 66 | // } | ||
2596 | 67 | //}; | ||
2597 | 68 | // | ||
2598 | 69 | //static VisualLogger vlog; | ||
2599 | 70 | |||
2600 | 71 | int VisualLogger::image_i = 0; | ||
2601 | 72 | int VisualLogger::step_i = 0; | ||
2602 | 73 | //bool VisualLogger::enabled = false; | ||
2603 | 74 | char* VisualLogger::prefix = 0; | ||
2604 | 75 | |||
2605 | 76 | //#define VLOG(x,y) | ||
2606 | 77 | |||
2607 | 78 | void | ||
2608 | 79 | Util::rgb2grayC3(const Mat& input, Mat& output){ | ||
2609 | 80 | Mat g; | ||
2610 | 81 | cvtColor(input, g, CV_RGB2GRAY); | ||
2611 | 82 | Mat ss[3] = {g,g,g}; | ||
2612 | 83 | merge(ss,3,output); | ||
2613 | 84 | } | ||
2614 | 85 | |||
2615 | 86 | void | ||
2616 | 87 | Util::growRect(Rect& rect, int xd, int yd, Rect bounds){ | ||
2617 | 88 | |||
2618 | 89 | |||
2619 | 90 | Rect in = rect; | ||
2620 | 91 | in.x -= xd; | ||
2621 | 92 | in.width += 2*xd; | ||
2622 | 93 | in.y -= yd; | ||
2623 | 94 | in.height += 2*yd; | ||
2624 | 95 | |||
2625 | 96 | int x1 = max(bounds.x, in.x); | ||
2626 | 97 | int y1 = max(bounds.y, in.y); | ||
2627 | 98 | int x2 = min(in.x + in.width, bounds.width); | ||
2628 | 99 | int y2 = min(in.y + in.height, bounds.height); | ||
2629 | 100 | |||
2630 | 101 | if (x2 < x1 || y2 < y1) | ||
2631 | 102 | rect = Rect(0,0,0,0); | ||
2632 | 103 | else | ||
2633 | 104 | rect = Rect(x1,y1,x2-x1+1,y2-y1+1); | ||
2634 | 105 | |||
2635 | 106 | } | ||
2636 | 107 | |||
2637 | 108 | void | ||
2638 | 109 | Util::growRect(Rect& rect, int xd, int yd, cv::Mat image){ | ||
2639 | 110 | growRect(rect, xd, yd, Rect(0,0, image.cols-1, image.rows-1)); | ||
2640 | 111 | } | ||
2641 | 112 | |||
2642 | 113 | |||
2643 | 114 | |||
2644 | 115 | void | ||
2645 | 116 | Painter::drawRect(Mat& image, Rect r, Scalar color){ | ||
2646 | 117 | rectangle(image, | ||
2647 | 118 | Point(r.x, r.y), | ||
2648 | 119 | Point(r.x + r.width, r.y + r.height), | ||
2649 | 120 | color); | ||
2650 | 121 | } | ||
2651 | 122 | |||
2652 | 123 | void | ||
2653 | 124 | Painter::drawRect(Mat& image, OCRRect r, Scalar color){ | ||
2654 | 125 | rectangle(image, | ||
2655 | 126 | Point(r.x, r.y), | ||
2656 | 127 | Point(r.x + r.width, r.y + r.height), | ||
2657 | 128 | color); | ||
2658 | 129 | } | ||
2659 | 130 | |||
2660 | 131 | void | ||
2661 | 132 | Painter::drawRects(Mat& image, vector<Rect>& rects, Scalar color){ | ||
2662 | 133 | for (vector<Rect>::iterator r = rects.begin(); | ||
2663 | 134 | r != rects.end(); ++r){ | ||
2664 | 135 | |||
2665 | 136 | rectangle(image, | ||
2666 | 137 | Point(r->x, r->y), | ||
2667 | 138 | Point(r->x + r->width, r->y + r->height), | ||
2668 | 139 | color); | ||
2669 | 140 | } | ||
2670 | 141 | } | ||
2671 | 142 | |||
2672 | 143 | |||
2673 | 144 | |||
2674 | 145 | void | ||
2675 | 146 | Painter::drawBlobsRandomShading(Mat& image, vector<Blob>& blobs){ | ||
2676 | 147 | |||
2677 | 148 | |||
2678 | 149 | Mat blank = image.clone(); | ||
2679 | 150 | blank = 0.0; | ||
2680 | 151 | |||
2681 | 152 | Mat shading = blank; | ||
2682 | 153 | for (vector<Blob>::iterator it = blobs.begin(); | ||
2683 | 154 | it != blobs.end(); ++it){ | ||
2684 | 155 | Blob& box = *it; | ||
2685 | 156 | rectangle(shading, Point(box.x,box.y), Point(box.x+box.width,box.y+box.height), Color::RANDOM(), CV_FILLED); | ||
2686 | 157 | } | ||
2687 | 158 | |||
2688 | 159 | image = image * 0.5 + shading * 0.7; | ||
2689 | 160 | |||
2690 | 161 | Painter::drawBlobs(image, blobs, Color::WHITE); | ||
2691 | 162 | } | ||
2692 | 163 | |||
2693 | 164 | void | ||
2694 | 165 | Painter::drawRects(Mat& image, vector<Rect>& rects){ | ||
2695 | 166 | drawRects(image, rects, Scalar(0,0,255)); | ||
2696 | 167 | } | ||
2697 | 168 | |||
2698 | 169 | void | ||
2699 | 170 | Painter::drawBlobs(Mat& image, vector<Blob>& blobs){ | ||
2700 | 171 | for (vector<Blob>::iterator it = blobs.begin(); | ||
2701 | 172 | it != blobs.end(); ++it){ | ||
2702 | 173 | |||
2703 | 174 | Blob& blob = *it; | ||
2704 | 175 | |||
2705 | 176 | Scalar color(blob.mr,blob.mg,blob.mb); | ||
2706 | 177 | vector<Rect> rs; | ||
2707 | 178 | rs.push_back(blob); | ||
2708 | 179 | drawRects(image, rs, color); | ||
2709 | 180 | } | ||
2710 | 181 | } | ||
2711 | 182 | |||
2712 | 183 | void | ||
2713 | 184 | Painter::drawBlobs(Mat& image, vector<Blob>& blobs, Scalar color){ | ||
2714 | 185 | vector<Rect> rs; | ||
2715 | 186 | |||
2716 | 187 | for (vector<Blob>::iterator it = blobs.begin(); | ||
2717 | 188 | it != blobs.end(); ++it){ | ||
2718 | 189 | |||
2719 | 190 | Blob& blob = *it; | ||
2720 | 191 | rs.push_back(blob); | ||
2721 | 192 | } | ||
2722 | 193 | drawRects(image, rs, color); | ||
2723 | 194 | } | ||
2724 | 195 | |||
2725 | 196 | void | ||
2726 | 197 | Painter::drawLineBlobs(Mat& image, vector<LineBlob>& lineblobs, Scalar color){ | ||
2727 | 198 | for (vector<LineBlob>::iterator it1 = lineblobs.begin(); | ||
2728 | 199 | it1 != lineblobs.end(); ++it1){ | ||
2729 | 200 | |||
2730 | 201 | LineBlob& lineblob = *it1; | ||
2731 | 202 | |||
2732 | 203 | |||
2733 | 204 | if (lineblob.blobs.size()>=2){ | ||
2734 | 205 | |||
2735 | 206 | for (vector<Blob>::iterator r = lineblob.blobs.begin() + 1; | ||
2736 | 207 | r != lineblob.blobs.end(); ++r){ | ||
2737 | 208 | |||
2738 | 209 | Rect previous = *(r-1); | ||
2739 | 210 | Rect current = *r; | ||
2740 | 211 | |||
2741 | 212 | Point from(previous.x+previous.width,previous.y); | ||
2742 | 213 | Point to(current.x,current.y); | ||
2743 | 214 | cv::line(image, from, to, Scalar(255,255,255)); | ||
2744 | 215 | } | ||
2745 | 216 | } | ||
2746 | 217 | |||
2747 | 218 | drawRect(image, lineblob, color); | ||
2748 | 219 | } | ||
2749 | 220 | } | ||
2750 | 221 | |||
2751 | 222 | void | ||
2752 | 223 | Painter::drawParagraphBlobs(Mat& image, vector<ParagraphBlob> blobs, Scalar color){ | ||
2753 | 224 | for (vector<ParagraphBlob>::iterator it = blobs.begin(); | ||
2754 | 225 | it != blobs.end(); ++it){ | ||
2755 | 226 | |||
2756 | 227 | ParagraphBlob& parablob = *it; | ||
2757 | 228 | for (vector<LineBlob>::iterator it1 = parablob.lineblobs.begin(); | ||
2758 | 229 | it1 != parablob.lineblobs.end(); ++it1){ | ||
2759 | 230 | |||
2760 | 231 | LineBlob& lineblob = *it1; | ||
2761 | 232 | drawRect(image, lineblob, Scalar(255,255,0)); | ||
2762 | 233 | } | ||
2763 | 234 | |||
2764 | 235 | drawRect(image, parablob, Scalar(0,0,255)); | ||
2765 | 236 | |||
2766 | 237 | } | ||
2767 | 238 | } | ||
2768 | 239 | |||
2769 | 240 | void | ||
2770 | 241 | Painter::drawOCRWord(Mat& ocr_result_image, OCRWord ocrword){ | ||
2771 | 242 | |||
2772 | 243 | cout << ocrword.x << " " << ocrword.y << " " << ocrword.width << " " << ocrword.height << ": "; | ||
2773 | 244 | cout << ocrword.getString() << endl; | ||
2774 | 245 | |||
2775 | 246 | drawRect(ocr_result_image, ocrword, Scalar(255,255,0)); | ||
2776 | 247 | Point pt(ocrword.x, ocrword.y + ocrword.height - 10); | ||
2777 | 248 | putText(ocr_result_image, ocrword.getString(), pt, | ||
2778 | 249 | FONT_HERSHEY_SIMPLEX, 0.4, Color::RED); | ||
2779 | 250 | |||
2780 | 251 | } | ||
2781 | 252 | |||
2782 | 253 | void | ||
2783 | 254 | Painter::drawOCRLine(Mat& ocr_result_image, OCRLine ocrline){ | ||
2784 | 255 | vector<OCRWord> ocrwords = ocrline.getWords(); | ||
2785 | 256 | for (vector<OCRWord>::iterator it = ocrwords.begin(); it != ocrwords.end(); ++it){ | ||
2786 | 257 | OCRWord& ocrword = *it; | ||
2787 | 258 | drawOCRWord(ocr_result_image, ocrword); | ||
2788 | 259 | } | ||
2789 | 260 | } | ||
2790 | 261 | |||
2791 | 262 | void | ||
2792 | 263 | Painter::drawOCRParagraph(Mat& ocr_result_image, OCRParagraph ocrpara){ | ||
2793 | 264 | vector<OCRLine> ocrlines = ocrpara.getLines(); | ||
2794 | 265 | for (vector<OCRLine>::iterator it = ocrlines.begin(); it != ocrlines.end(); ++it){ | ||
2795 | 266 | OCRLine& ocrline = *it; | ||
2796 | 267 | drawOCRLine(ocr_result_image, ocrline); | ||
2797 | 268 | } | ||
2798 | 269 | } | ||
2799 | 270 | |||
2800 | 271 | void | ||
2801 | 272 | Painter::drawOCRText(Mat& ocr_result_image, OCRText ocrtext){ | ||
2802 | 273 | vector<OCRParagraph> ocrparas = ocrtext.getParagraphs(); | ||
2803 | 274 | for (vector<OCRParagraph>::iterator it = ocrparas.begin(); it != ocrparas.end(); ++it){ | ||
2804 | 275 | OCRParagraph& ocrpara = *it; | ||
2805 | 276 | drawOCRParagraph(ocr_result_image, ocrpara); | ||
2806 | 277 | } | ||
2807 | 278 | } | ||
2808 | 279 | |||
2809 | 280 | |||
2810 | 281 | |||
2811 | 282 | |||
2812 | 283 | void | ||
2813 | 284 | LineBlob::merge(LineBlob& blob){ | ||
2814 | 285 | |||
2815 | 286 | for (vector<Blob>::iterator it = blob.blobs.begin(); | ||
2816 | 287 | it != blob.blobs.end(); ++it){ | ||
2817 | 288 | add(*it); | ||
2818 | 289 | } | ||
2819 | 290 | |||
2820 | 291 | } | ||
2821 | 292 | |||
2822 | 293 | void | ||
2823 | 294 | LineBlob::updateBoundingRect(Blob& blob){ | ||
2824 | 295 | if (blobs.size() == 0){ | ||
2825 | 296 | x = blob.x; | ||
2826 | 297 | y = blob.y; | ||
2827 | 298 | height = blob.height; | ||
2828 | 299 | width = blob.width; | ||
2829 | 300 | |||
2830 | 301 | }else{ | ||
2831 | 302 | |||
2832 | 303 | int x1,y1,x2,y2; | ||
2833 | 304 | x1 = min(x, blob.x); | ||
2834 | 305 | y1 = min(y, blob.y); | ||
2835 | 306 | x2 = max(x+width, blob.x + blob.width); | ||
2836 | 307 | y2 = max(y+height, blob.y + blob.height); | ||
2837 | 308 | |||
2838 | 309 | x = x1; | ||
2839 | 310 | y = y1; | ||
2840 | 311 | height = y2 - y1; | ||
2841 | 312 | width = x2 - x1; | ||
2842 | 313 | } | ||
2843 | 314 | } | ||
2844 | 315 | |||
2845 | 316 | void | ||
2846 | 317 | LineBlob::add(Blob& blob){ | ||
2847 | 318 | updateBoundingRect(blob); | ||
2848 | 319 | blobs.push_back(blob); | ||
2849 | 320 | } | ||
2850 | 321 | |||
2851 | 322 | void | ||
2852 | 323 | LineBlob::calculateBoundingRectangle(){ | ||
2853 | 324 | int x1,y1,x2,y2; | ||
2854 | 325 | Blob& first_blob = blobs.front(); | ||
2855 | 326 | x1 = first_blob.x; | ||
2856 | 327 | x2 = first_blob.x + first_blob.width; | ||
2857 | 328 | y1 = first_blob.y; | ||
2858 | 329 | y2 = first_blob.y + first_blob.height; | ||
2859 | 330 | |||
2860 | 331 | for (vector<Blob>::iterator it_line = blobs.begin()+1; | ||
2861 | 332 | it_line != blobs.end(); ++it_line){ | ||
2862 | 333 | Blob& b = *it_line; | ||
2863 | 334 | x1 = min(x1, b.x); | ||
2864 | 335 | y1 = min(y1, b.y); | ||
2865 | 336 | x2 = max(x2, b.x + b.width); | ||
2866 | 337 | y2 = max(y2, b.y + b.height); | ||
2867 | 338 | } | ||
2868 | 339 | |||
2869 | 340 | x = x1; | ||
2870 | 341 | y = y1; | ||
2871 | 342 | height = y2 - y1; | ||
2872 | 343 | width = x2 - x1; | ||
2873 | 344 | } | ||
2874 | 345 | |||
2875 | 346 | void | ||
2876 | 347 | ParagraphBlob::add(LineBlob& blob){ | ||
2877 | 348 | |||
2878 | 349 | if (lineblobs.size() == 0){ | ||
2879 | 350 | x = blob.x; | ||
2880 | 351 | y = blob.y; | ||
2881 | 352 | height = blob.height; | ||
2882 | 353 | width = blob.width; | ||
2883 | 354 | |||
2884 | 355 | }else{ | ||
2885 | 356 | |||
2886 | 357 | int x1,y1,x2,y2; | ||
2887 | 358 | x1 = min(x, blob.x); | ||
2888 | 359 | y1 = min(y, blob.y); | ||
2889 | 360 | x2 = max(x+width, blob.x + blob.width); | ||
2890 | 361 | y2 = max(y+height, blob.y + blob.height); | ||
2891 | 362 | |||
2892 | 363 | x = x1; | ||
2893 | 364 | y = y1; | ||
2894 | 365 | height = y2 - y1; | ||
2895 | 366 | width = x2 - x1; | ||
2896 | 367 | } | ||
2897 | 368 | lineblobs.push_back(blob); | ||
2898 | 369 | } | ||
2899 | 370 | |||
2900 | 371 | |||
2901 | 372 | |||
2902 | 373 | void denoise(Mat& src){ | ||
2903 | 374 | |||
2904 | 375 | //src = src * 0.1; | ||
2905 | 376 | |||
2906 | 377 | Mat kernel = Mat::ones(3,3,CV_32FC1); | ||
2907 | 378 | kernel.at<float>(2,2) = 0; | ||
2908 | 379 | |||
2909 | 380 | Mat srcF, destF; | ||
2910 | 381 | src.convertTo(srcF, CV_32FC1, 0.1); | ||
2911 | 382 | |||
2912 | 383 | filter2D(srcF, destF, -1, kernel); | ||
2913 | 384 | |||
2914 | 385 | Mat destU; | ||
2915 | 386 | destF.convertTo(destU, CV_8UC1); | ||
2916 | 387 | |||
2917 | 388 | threshold(destU, destU, 60, 255, THRESH_BINARY); | ||
2918 | 389 | |||
2919 | 390 | bitwise_and(src, destU, src); | ||
2920 | 391 | } | ||
2921 | 392 | |||
2922 | 393 | |||
2923 | 394 | |||
2924 | 395 | |||
2925 | 396 | void | ||
2926 | 397 | cvgui::linkLineBlobsIntoPagagraphBlobs(vector<LineBlob>& blobs, vector<ParagraphBlob>& parablobs){ | ||
2927 | 398 | |||
2928 | 399 | sort(blobs, sort_blob_by_y); | ||
2929 | 400 | |||
2930 | 401 | for (vector<LineBlob>::iterator it = blobs.begin(); | ||
2931 | 402 | it != blobs.end(); ++it){ | ||
2932 | 403 | |||
2933 | 404 | LineBlob& blob = *it; | ||
2934 | 405 | |||
2935 | 406 | vector<ParagraphBlob>::iterator it1; | ||
2936 | 407 | for (it1 = parablobs.begin(); | ||
2937 | 408 | it1 != parablobs.end(); ++it1){ | ||
2938 | 409 | |||
2939 | 410 | ParagraphBlob& parablob = *it1; | ||
2940 | 411 | |||
2941 | 412 | bool left_aligned = abs(parablob.x - blob.x) < 10; | ||
2942 | 413 | bool small_vertical_spacing = abs(blob.y - (parablob.y + parablob.height)) < 15; | ||
2943 | 414 | |||
2944 | 415 | bool same_paragraph = left_aligned & small_vertical_spacing; | ||
2945 | 416 | |||
2946 | 417 | if (same_paragraph){ | ||
2947 | 418 | parablob.add(blob); | ||
2948 | 419 | break; | ||
2949 | 420 | } | ||
2950 | 421 | } | ||
2951 | 422 | |||
2952 | 423 | if (it1 == parablobs.end()){ | ||
2953 | 424 | ParagraphBlob new_parablob; | ||
2954 | 425 | new_parablob.add(blob); | ||
2955 | 426 | parablobs.push_back(new_parablob); | ||
2956 | 427 | } | ||
2957 | 428 | } | ||
2958 | 429 | } | ||
2959 | 430 | |||
2960 | 431 | void | ||
2961 | 432 | cvgui::mergeLineBlobs(vector<LineBlob>& blobs, vector<LineBlob>& merged_blobs){ | ||
2962 | 433 | |||
2963 | 434 | sort(blobs, sort_blob_by_x); | ||
2964 | 435 | |||
2965 | 436 | for (vector<LineBlob>::iterator it = blobs.begin(); | ||
2966 | 437 | it != blobs.end(); ++it){ | ||
2967 | 438 | |||
2968 | 439 | LineBlob& blob = *it; | ||
2969 | 440 | |||
2970 | 441 | vector<LineBlob>::iterator l; | ||
2971 | 442 | for (l = merged_blobs.begin(); l != merged_blobs.end(); ++l){ | ||
2972 | 443 | |||
2973 | 444 | LineBlob& merged_blob = *l; | ||
2974 | 445 | |||
2975 | 446 | bool similar_baseline = abs((merged_blob.y + merged_blob.height) - (blob.y + blob.height)) < 5; | ||
2976 | 447 | bool small_spacing = (blob.x - (merged_blob.x + merged_blob.width)) < 10; | ||
2977 | 448 | |||
2978 | 449 | bool cond1 = merged_blob.isContainedBy(blob) || blob.isContainedBy(merged_blob); | ||
2979 | 450 | |||
2980 | 451 | bool same_line = cond1 || (similar_baseline && small_spacing); | ||
2981 | 452 | |||
2982 | 453 | if (same_line){ | ||
2983 | 454 | merged_blob.merge(blob); | ||
2984 | 455 | break; | ||
2985 | 456 | } | ||
2986 | 457 | } | ||
2987 | 458 | |||
2988 | 459 | if (l == merged_blobs.end()){ | ||
2989 | 460 | merged_blobs.push_back(blob); | ||
2990 | 461 | } | ||
2991 | 462 | |||
2992 | 463 | } | ||
2993 | 464 | } | ||
2994 | 465 | |||
2995 | 466 | void | ||
2996 | 467 | cvgui::linkBlobsIntoLineBlobs(vector<Blob>& blobs, vector<LineBlob>& lines, int max_spacing){ | ||
2997 | 468 | |||
2998 | 469 | |||
2999 | 470 | sort(blobs, sort_blob_by_x); | ||
3000 | 471 | for (vector<Blob>::iterator it = blobs.begin(); | ||
3001 | 472 | it != blobs.end(); ++it){ | ||
3002 | 473 | |||
3003 | 474 | Blob& blob = *it; | ||
3004 | 475 | |||
3005 | 476 | vector<LineBlob>::iterator l; | ||
3006 | 477 | for (l = lines.begin(); l != lines.end(); ++l){ | ||
3007 | 478 | |||
3008 | 479 | LineBlob& line = *l; | ||
3009 | 480 | Blob& last = line.blobs.back(); | ||
3010 | 481 | |||
3011 | 482 | bool similar_baseline = abs((last.y + last.height) - (blob.y + blob.height)) < 5; | ||
3012 | 483 | bool similar_centerline = abs((last.y + last.height/2) - (blob.y + blob.height/2)) < 5; | ||
3013 | 484 | bool similar_height = 1.0*min(last.height,blob.height)/max(last.height,blob.height) > 0.5; | ||
3014 | 485 | bool similar_width = 1.0*min(last.width,blob.width)/max(last.width,blob.width) > 0.5; | ||
3015 | 486 | |||
3016 | 487 | bool small_overlap = blob.x > ((last.x + last.width)-2); | ||
3017 | 488 | |||
3018 | 489 | |||
3019 | 490 | bool small_spacing = (blob.x - (last.x + last.width)) < max_spacing; | ||
3020 | 491 | |||
3021 | 492 | bool is_dot = blob.height < 3 && blob.width < 3 && similar_baseline && small_spacing; | ||
3022 | 493 | |||
3023 | 494 | int th = 40; | ||
3024 | 495 | bool similar_foreground_color = | ||
3025 | 496 | abs(last.mr - blob.mr) < th && abs(last.mg - blob.mg) < th && abs(last.mb - blob.mb) < th; | ||
3026 | 497 | |||
3027 | 498 | |||
3028 | 499 | //bool is_probably_i = blob.width < 2 || last.width < 2; | ||
3029 | 500 | |||
3030 | 501 | |||
3031 | 502 | bool same_line = (similar_centerline || similar_baseline) | ||
3032 | 503 | && similar_height | ||
3033 | 504 | && small_overlap | ||
3034 | 505 | //&& similar_width | ||
3035 | 506 | && small_spacing | ||
3036 | 507 | && similar_foreground_color; //|| is_probably_i); | ||
3037 | 508 | |||
3038 | 509 | |||
3039 | 510 | bool very_close = (blob.x - (last.x + last.width)) < 3; | ||
3040 | 511 | |||
3041 | 512 | // bool vertically_overlap = similar_baseline; | ||
3042 | 513 | |||
3043 | 514 | if (same_line || (very_close && similar_height && similar_baseline)){ | ||
3044 | 515 | line.add(blob); | ||
3045 | 516 | break; | ||
3046 | 517 | } | ||
3047 | 518 | } | ||
3048 | 519 | |||
3049 | 520 | if (l == lines.end()){ | ||
3050 | 521 | |||
3051 | 522 | LineBlob newline; | ||
3052 | 523 | newline.add(blob); | ||
3053 | 524 | lines.push_back(newline); | ||
3054 | 525 | } | ||
3055 | 526 | |||
3056 | 527 | } | ||
3057 | 528 | } | ||
3058 | 529 | |||
3059 | 530 | |||
3060 | 531 | void | ||
3061 | 532 | cvgui::run_ocr_on_lineblobs(vector<LineBlob>& ocr_input_lineblobs, | ||
3062 | 533 | Mat& input_image, | ||
3063 | 534 | vector<OCRLine>& ocrlines){ | ||
3064 | 535 | |||
3065 | 536 | |||
3066 | 537 | for (vector<LineBlob>::iterator it = ocr_input_lineblobs.begin(); | ||
3067 | 538 | it != ocr_input_lineblobs.end(); ++it){ | ||
3068 | 539 | |||
3069 | 540 | LineBlob& lineblob = *it; | ||
3070 | 541 | OCRLine ocrline; | ||
3071 | 542 | OCRWord ocrword; | ||
3072 | 543 | |||
3073 | 544 | // if (lineblob.blobs.size()<10) | ||
3074 | 545 | // continue; | ||
3075 | 546 | // | ||
3076 | 547 | |||
3077 | 548 | |||
3078 | 549 | Mat wordImage(input_image,lineblob); | ||
3079 | 550 | |||
3080 | 551 | Mat ocrImage; // the image passed to tesseract | ||
3081 | 552 | bool upsampled = false; | ||
3082 | 553 | if (wordImage.rows < 20){ | ||
3083 | 554 | upsampled = true; | ||
3084 | 555 | resize(wordImage, ocrImage, Size(wordImage.cols*2,wordImage.rows*2)); | ||
3085 | 556 | }else { | ||
3086 | 557 | ocrImage = wordImage.clone(); | ||
3087 | 558 | } | ||
3088 | 559 | |||
3089 | 560 | vector<OCRChar> ocr_chars; | ||
3090 | 561 | ocr_chars = OCR::recognize((unsigned char*)ocrImage.data, | ||
3091 | 562 | ocrImage.cols, | ||
3092 | 563 | ocrImage.rows, | ||
3093 | 564 | 8); | ||
3094 | 565 | |||
3095 | 566 | for (vector<OCRChar>::iterator iter = ocr_chars.begin(); | ||
3096 | 567 | iter != ocr_chars.end(); iter++){ | ||
3097 | 568 | |||
3098 | 569 | |||
3099 | 570 | OCRChar& ocrchar = *iter; | ||
3100 | 571 | |||
3101 | 572 | |||
3102 | 573 | if (upsampled){ | ||
3103 | 574 | // scale back the coordinates in the OCR result | ||
3104 | 575 | |||
3105 | 576 | ocrchar.x = ocrchar.x/2; | ||
3106 | 577 | ocrchar.y = ocrchar.y/2; | ||
3107 | 578 | ocrchar.width = ocrchar.width/2; | ||
3108 | 579 | ocrchar.height = ocrchar.height/2; | ||
3109 | 580 | } | ||
3110 | 581 | |||
3111 | 582 | |||
3112 | 583 | ocrchar.x += lineblob.x; | ||
3113 | 584 | ocrchar.y += lineblob.y; | ||
3114 | 585 | |||
3115 | 586 | |||
3116 | 587 | |||
3117 | 588 | if (iter > ocr_chars.begin()){ | ||
3118 | 589 | OCRChar& previous_ocrchar = *(iter-1); | ||
3119 | 590 | |||
3120 | 591 | int spacing = ocrchar.x - (previous_ocrchar.x + previous_ocrchar.width); | ||
3121 | 592 | //dout() << '[' << ocrchar.height << ':' << spacing << ']'; | ||
3122 | 593 | //dout() << '[' << spacing << ']'; | ||
3123 | 594 | |||
3124 | 595 | |||
3125 | 596 | if (lineblob.height > 6 && spacing >= 4){// || spacing >= 2){ | ||
3126 | 597 | ocrline.addWord(ocrword); | ||
3127 | 598 | ocrword.clear(); | ||
3128 | 599 | //dout() << ' '; | ||
3129 | 600 | } | ||
3130 | 601 | } | ||
3131 | 602 | |||
3132 | 603 | //dout() << ocrchar.ch; | ||
3133 | 604 | |||
3134 | 605 | ocrword.add(ocrchar); | ||
3135 | 606 | ocrword.y = lineblob.y; | ||
3136 | 607 | ocrword.height = lineblob.height; | ||
3137 | 608 | |||
3138 | 609 | |||
3139 | 610 | |||
3140 | 611 | |||
3141 | 612 | |||
3142 | 613 | } | ||
3143 | 614 | |||
3144 | 615 | |||
3145 | 616 | ocrline.addWord(ocrword); | ||
3146 | 617 | |||
3147 | 618 | //dout() << endl; | ||
3148 | 619 | |||
3149 | 620 | |||
3150 | 621 | ocrlines.push_back(ocrline); | ||
3151 | 622 | |||
3152 | 623 | } | ||
3153 | 624 | } | ||
3154 | 625 | |||
3155 | 626 | void getLeafBlobs(vector<Blob>& blobs, vector<Blob>& leaf_blobs){ | ||
3156 | 627 | |||
3157 | 628 | leaf_blobs.clear(); | ||
3158 | 629 | |||
3159 | 630 | for (vector<Blob>::iterator it = blobs.begin(); | ||
3160 | 631 | it != blobs.end(); ++it){ | ||
3161 | 632 | |||
3162 | 633 | Blob& a = *it; | ||
3163 | 634 | |||
3164 | 635 | // check if blob 'a' contains any other blob | ||
3165 | 636 | vector<Blob>::iterator it1; | ||
3166 | 637 | for (it1 = blobs.begin(); | ||
3167 | 638 | it1 != blobs.end(); ++it1){ | ||
3168 | 639 | |||
3169 | 640 | Blob& b = *it1; | ||
3170 | 641 | |||
3171 | 642 | if (it != it1 && b.isContainedBy(a)) | ||
3172 | 643 | break; | ||
3173 | 644 | } | ||
3174 | 645 | |||
3175 | 646 | // if not, it is a leave blob | ||
3176 | 647 | if (it1 == blobs.end()) | ||
3177 | 648 | leaf_blobs.push_back(a); | ||
3178 | 649 | |||
3179 | 650 | } | ||
3180 | 651 | } | ||
3181 | 652 | |||
3182 | 653 | |||
3183 | 654 | Mat | ||
3184 | 655 | cvgui::findBoxesByVoting(const Mat& screen, | ||
3185 | 656 | int bw, int bh, | ||
3186 | 657 | vector<Blob>& output_blobs){ | ||
3187 | 658 | |||
3188 | 659 | Mat dark; | ||
3189 | 660 | Util::rgb2grayC3(screen,dark); | ||
3190 | 661 | dark = dark * 0.5; | ||
3191 | 662 | |||
3192 | 663 | |||
3193 | 664 | VLOG("Input", screen); | ||
3194 | 665 | |||
3195 | 666 | Mat gray; | ||
3196 | 667 | cvtColor(screen,gray,CV_RGB2GRAY); | ||
3197 | 668 | |||
3198 | 669 | |||
3199 | 670 | // Code for experimenting differenty parameters for Canny | ||
3200 | 671 | // for (int c=10;c<=100;c=c+10){ | ||
3201 | 672 | // char buf[50]; | ||
3202 | 673 | // Mat test; | ||
3203 | 674 | // sprintf(buf,"Canny%d",c); | ||
3204 | 675 | // Canny(gray,test,0.66*c,1.33*c,3,true); | ||
3205 | 676 | // VLOG(buf, test); | ||
3206 | 677 | // } | ||
3207 | 678 | |||
3208 | 679 | Mat canny; | ||
3209 | 680 | int s = 200; | ||
3210 | 681 | Canny(gray,canny,0.66*s,1.33*s,3,true); | ||
3211 | 682 | VLOG("Canny", canny); | ||
3212 | 683 | |||
3213 | 684 | Mat edges; | ||
3214 | 685 | Mat v = Mat::ones(2,2,CV_8UC1); | ||
3215 | 686 | |||
3216 | 687 | dilate(canny, edges, v); | ||
3217 | 688 | erode(edges, edges, v); | ||
3218 | 689 | |||
3219 | 690 | dilate(edges, edges, Mat::ones(3,3,CV_8UC1)); | ||
3220 | 691 | VLOG("Dilated", edges); | ||
3221 | 692 | |||
3222 | 693 | double k = 0.85; | ||
3223 | 694 | double tol = 0.10; | ||
3224 | 695 | Mat q = Mat::ones(5,5,CV_8UC1); | ||
3225 | 696 | |||
3226 | 697 | Mat h1,h2,hvotes; | ||
3227 | 698 | voteCenter_Horizontal(edges, h1, bw*k, bw*tol, bh/2); | ||
3228 | 699 | dilate(h1, h1, q); | ||
3229 | 700 | voteCenter_Horizontal(edges, h2, bw*k, bw*tol, -bh/2); | ||
3230 | 701 | dilate(h2, h2, q); | ||
3231 | 702 | |||
3232 | 703 | bitwise_and(h1,h2,hvotes); | ||
3233 | 704 | VLOG("H-votes", hvotes); | ||
3234 | 705 | |||
3235 | 706 | |||
3236 | 707 | Mat v1,v2,vvotes; | ||
3237 | 708 | voteCenter_Vertical(edges, v1, bh*k, bh*tol, bw/2); | ||
3238 | 709 | dilate(v1, v1, q); | ||
3239 | 710 | |||
3240 | 711 | voteCenter_Vertical(edges, v2, bh*k, bh*tol, -bw/2); | ||
3241 | 712 | dilate(v2, v2, q); | ||
3242 | 713 | |||
3243 | 714 | bitwise_and(v1,v2,vvotes); | ||
3244 | 715 | VLOG("V-votes", vvotes); | ||
3245 | 716 | |||
3246 | 717 | Mat hvvotes; | ||
3247 | 718 | bitwise_and(vvotes,hvotes,hvvotes); | ||
3248 | 719 | VLOG("HV-votes", hvvotes); | ||
3249 | 720 | |||
3250 | 721 | |||
3251 | 722 | |||
3252 | 723 | |||
3253 | 724 | Mat copy = hvvotes.clone(); | ||
3254 | 725 | |||
3255 | 726 | |||
3256 | 727 | vector<vector<Point> > contours; | ||
3257 | 728 | vector<Vec4i> hierarchy; | ||
3258 | 729 | |||
3259 | 730 | findContours( copy, contours, hierarchy, | ||
3260 | 731 | CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE ); | ||
3261 | 732 | |||
3262 | 733 | vector<Blob> blobs; | ||
3263 | 734 | |||
3264 | 735 | Mat blank = dark.clone(); | ||
3265 | 736 | blank = 0.0; | ||
3266 | 737 | |||
3267 | 738 | Mat contour_shading = blank; | ||
3268 | 739 | |||
3269 | 740 | |||
3270 | 741 | // define a perfect box for back-proj verification | ||
3271 | 742 | Mat pbox = Mat::zeros(bh,bw,CV_8UC1); | ||
3272 | 743 | pbox.row(0).setTo(255); | ||
3273 | 744 | pbox.row(bh-1).setTo(255); | ||
3274 | 745 | pbox.col(0).setTo(255); | ||
3275 | 746 | pbox.col(bw-1).setTo(255); | ||
3276 | 747 | int pscore = countNonZero(pbox); | ||
3277 | 748 | |||
3278 | 749 | for (vector<vector<Point> >::iterator it = contours.begin(); | ||
3279 | 750 | it != contours.end(); ++it){ | ||
3280 | 751 | |||
3281 | 752 | vector<Point>& contour = *it; | ||
3282 | 753 | |||
3283 | 754 | Rect r = boundingRect(Mat(contour)); | ||
3284 | 755 | |||
3285 | 756 | double a1 = contourArea(Mat(contour)); | ||
3286 | 757 | double a2 = r.height * r.width; | ||
3287 | 758 | |||
3288 | 759 | int cx = r.x + r.width/2; | ||
3289 | 760 | int cy = r.y + r.height/2; | ||
3290 | 761 | |||
3291 | 762 | |||
3292 | 763 | Rect box(cx-bw/2,cy-bh/2,bw,bh); | ||
3293 | 764 | |||
3294 | 765 | Mat e(edges, box); | ||
3295 | 766 | // calculate the score by comparing each hypothesized box to the ideal box | ||
3296 | 767 | Mat sc; | ||
3297 | 768 | bitwise_and(e,pbox,sc); | ||
3298 | 769 | int score = countNonZero(sc); | ||
3299 | 770 | |||
3300 | 771 | // ignore those boxes with fewer than this percentage | ||
3301 | 772 | // of edge pixels | ||
3302 | 773 | if ((1.0 * score) / (1.0 * pscore) < 0.90) | ||
3303 | 774 | continue; | ||
3304 | 775 | |||
3305 | 776 | // rectangle(contour_shading, Point(box.x,box.y), Point(box.x+box.width,box.y+box.height), Color::RANDOM(), CV_FILLED); | ||
3306 | 777 | |||
3307 | 778 | |||
3308 | 779 | Blob blob(box); | ||
3309 | 780 | blob.score = score; | ||
3310 | 781 | blobs.push_back(blob); | ||
3311 | 782 | |||
3312 | 783 | } | ||
3313 | 784 | |||
3314 | 785 | |||
3315 | 786 | Mat blobs_image = dark.clone(); | ||
3316 | 787 | |||
3317 | 788 | Painter::drawBlobsRandomShading(blobs_image, blobs); | ||
3318 | 789 | VLOG("BlobHypotheses", blobs_image); | ||
3319 | 790 | |||
3320 | 791 | |||
3321 | 792 | // remove overlapping blobs | ||
3322 | 793 | // and do non-maximal suppression | ||
3323 | 794 | vector<Blob> nonoverlapping_blobs; | ||
3324 | 795 | |||
3325 | 796 | for (vector<Blob>::iterator it = blobs.begin(); | ||
3326 | 797 | it != blobs.end(); ++it){ | ||
3327 | 798 | |||
3328 | 799 | Blob& b = *it; | ||
3329 | 800 | |||
3330 | 801 | bool not_overlap = true; | ||
3331 | 802 | int tolerance = 3; | ||
3332 | 803 | vector<Blob>::iterator ito; | ||
3333 | 804 | for (ito = nonoverlapping_blobs.begin(); | ||
3334 | 805 | ito != nonoverlapping_blobs.end(); ++ito){ | ||
3335 | 806 | |||
3336 | 807 | Blob& bo = *ito; | ||
3337 | 808 | |||
3338 | 809 | not_overlap = b.x >= bo.x + bo.width - tolerance || b.y >= bo.y + bo.height - tolerance|| | ||
3339 | 810 | b.x + b.width <= bo.x + tolerance|| b.y + b.height <= bo.y + tolerance; | ||
3340 | 811 | |||
3341 | 812 | if (!not_overlap) | ||
3342 | 813 | break; | ||
3343 | 814 | |||
3344 | 815 | } | ||
3345 | 816 | |||
3346 | 817 | if (not_overlap){ | ||
3347 | 818 | |||
3348 | 819 | nonoverlapping_blobs.push_back(b); | ||
3349 | 820 | |||
3350 | 821 | }else{ | ||
3351 | 822 | // replace it if the score is better | ||
3352 | 823 | |||
3353 | 824 | if (it->score > ito->score){ | ||
3354 | 825 | |||
3355 | 826 | (*ito) = (*it); | ||
3356 | 827 | } | ||
3357 | 828 | |||
3358 | 829 | } | ||
3359 | 830 | |||
3360 | 831 | } | ||
3361 | 832 | |||
3362 | 833 | |||
3363 | 834 | vector<Blob>& result_blobs = nonoverlapping_blobs; | ||
3364 | 835 | |||
3365 | 836 | |||
3366 | 837 | Mat result_blobs_image = dark.clone(); | ||
3367 | 838 | Painter::drawBlobsRandomShading(result_blobs_image, result_blobs); | ||
3368 | 839 | VLOG("OutputBlobs", result_blobs_image); | ||
3369 | 840 | |||
3370 | 841 | // print output to stdout | ||
3371 | 842 | for (vector<Blob>::iterator it = result_blobs.begin(); | ||
3372 | 843 | it != result_blobs.end(); ++it){ | ||
3373 | 844 | Blob& b = *it; | ||
3374 | 845 | dout() << b.x << " " << b.y << " " << b.width << " " << b.height << " " << b.score << endl; | ||
3375 | 846 | } | ||
3376 | 847 | |||
3377 | 848 | |||
3378 | 849 | return result_blobs_image; | ||
3379 | 850 | } | ||
3380 | 851 | |||
3381 | 852 | Mat | ||
3382 | 853 | cvgui::findPokerBoxes(const Mat& screen, vector<Blob>& output_blobs){ | ||
3383 | 854 | |||
3384 | 855 | |||
3385 | 856 | //return findBoxesByVoting(screen, 70, 90, output_blobs); | ||
3386 | 857 | return findBoxesByVoting(screen, 40, 50, output_blobs); | ||
3387 | 858 | |||
3388 | 859 | |||
3389 | 860 | // old algorithm | ||
3390 | 861 | #if 0 | ||
3391 | 862 | Mat dark; | ||
3392 | 863 | Util::rgb2grayC3(screen,dark); | ||
3393 | 864 | dark = dark * 0.5; | ||
3394 | 865 | |||
3395 | 866 | |||
3396 | 867 | VLOG("Input", screen); | ||
3397 | 868 | |||
3398 | 869 | Mat gray; | ||
3399 | 870 | cvtColor(screen,gray,CV_RGB2GRAY); | ||
3400 | 871 | |||
3401 | 872 | //medianBlur(gray, gray, 3); | ||
3402 | 873 | //VLOG("Blurred", gray); | ||
3403 | 874 | |||
3404 | 875 | Mat edges; | ||
3405 | 876 | |||
3406 | 877 | // Code for experimenting differenty parameters for Canny | ||
3407 | 878 | // for (int c=10;c<=100;c=c+10){ | ||
3408 | 879 | // char buf[50]; | ||
3409 | 880 | // Mat test; | ||
3410 | 881 | // sprintf(buf,"Canny%d",c); | ||
3411 | 882 | // Canny(gray,test,0.66*c,1.33*c,3,true); | ||
3412 | 883 | // VLOG(buf, test); | ||
3413 | 884 | // } | ||
3414 | 885 | |||
3415 | 886 | int s = 100; | ||
3416 | 887 | Canny(gray,edges,0.66*s,1.33*s,3,true); | ||
3417 | 888 | VLOG("Canny", edges); | ||
3418 | 889 | |||
3419 | 890 | |||
3420 | 891 | Mat v = Mat::ones(2,2,CV_8UC1); | ||
3421 | 892 | |||
3422 | 893 | dilate(edges, edges, v); | ||
3423 | 894 | erode(edges, edges, v); | ||
3424 | 895 | |||
3425 | 896 | VLOG("Dilated", edges); | ||
3426 | 897 | |||
3427 | 898 | // experimental | ||
3428 | 899 | Mat hlines,vlines; | ||
3429 | 900 | dilate(edges, edges, Mat::ones(3,2,CV_8UC1)); | ||
3430 | 901 | |||
3431 | 902 | |||
3432 | 903 | findLongLines_Vertical(edges,vlines, 50, 2); | ||
3433 | 904 | VLOG("V-lines", vlines); | ||
3434 | 905 | |||
3435 | 906 | findLongLines_Horizontal(edges,hlines, 50, 2); | ||
3436 | 907 | VLOG("H-lines", hlines); | ||
3437 | 908 | |||
3438 | 909 | |||
3439 | 910 | int bw = 70; | ||
3440 | 911 | int bh = 20; | ||
3441 | 912 | double k = 0.90; | ||
3442 | 913 | |||
3443 | 914 | Mat q = Mat::ones(5,5,CV_8UC1); | ||
3444 | 915 | |||
3445 | 916 | Mat h1,h2,hvotes; | ||
3446 | 917 | voteCenter_Horizontal(edges, h1, bw*k, 2, bh/2); | ||
3447 | 918 | dilate(h1, h1, q); | ||
3448 | 919 | voteCenter_Horizontal(edges, h2, bw*k, 2, -bh/2); | ||
3449 | 920 | dilate(h2, h2, q); | ||
3450 | 921 | |||
3451 | 922 | bitwise_and(h1,h2,hvotes); | ||
3452 | 923 | VLOG("H-votes", hvotes); | ||
3453 | 924 | |||
3454 | 925 | |||
3455 | 926 | Mat v1,v2,vvotes; | ||
3456 | 927 | voteCenter_Vertical(edges, v1, bh*k, 2, bw/2); | ||
3457 | 928 | dilate(v1, v1, q); | ||
3458 | 929 | |||
3459 | 930 | voteCenter_Vertical(edges, v2, bh*k, 2, -bw/2); | ||
3460 | 931 | dilate(v2, v2, q); | ||
3461 | 932 | |||
3462 | 933 | bitwise_and(v1,v2,vvotes); | ||
3463 | 934 | VLOG("V-votes", vvotes); | ||
3464 | 935 | |||
3465 | 936 | Mat hvvotes; | ||
3466 | 937 | bitwise_and(vvotes,hvotes,hvvotes); | ||
3467 | 938 | VLOG("HV-votes", hvvotes); | ||
3468 | 939 | |||
3469 | 940 | |||
3470 | 941 | // Mat hvlines; | ||
3471 | 942 | // bitwise_or(hlines, vlines, hvlines); | ||
3472 | 943 | // VLOG("HV-lines", hvlines); | ||
3473 | 944 | |||
3474 | 945 | // | ||
3475 | 946 | |||
3476 | 947 | Mat lines; | ||
3477 | 948 | findLongLines(edges, lines, 15); | ||
3478 | 949 | |||
3479 | 950 | Mat w = Mat::ones(5,5,CV_8UC1); | ||
3480 | 951 | dilate(lines, lines, w); | ||
3481 | 952 | erode(lines, lines, w); | ||
3482 | 953 | |||
3483 | 954 | VLOG("Lines", lines); | ||
3484 | 955 | |||
3485 | 956 | |||
3486 | 957 | Mat lines2; | ||
3487 | 958 | Mat z = Mat::ones(2,2,CV_8UC1); | ||
3488 | 959 | |||
3489 | 960 | dilate(lines, lines, z); | ||
3490 | 961 | |||
3491 | 962 | findLongLines(lines, lines2, 30, 15); | ||
3492 | 963 | |||
3493 | 964 | //dilate(lines2, lines2, z); | ||
3494 | 965 | //erode(lines2, lines2, z); | ||
3495 | 966 | |||
3496 | 967 | VLOG("Lines2", lines2); | ||
3497 | 968 | |||
3498 | 969 | |||
3499 | 970 | |||
3500 | 971 | Mat result = dark.clone(); | ||
3501 | 972 | //Mat copy = edges.clone(); | ||
3502 | 973 | //Mat copy = lines.clone(); | ||
3503 | 974 | |||
3504 | 975 | Mat copy = lines2.clone(); | ||
3505 | 976 | |||
3506 | 977 | |||
3507 | 978 | vector<vector<Point> > contours; | ||
3508 | 979 | vector<Vec4i> hierarchy; | ||
3509 | 980 | |||
3510 | 981 | findContours( copy, contours, hierarchy, | ||
3511 | 982 | CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE ); | ||
3512 | 983 | |||
3513 | 984 | vector<Blob> blobs; | ||
3514 | 985 | |||
3515 | 986 | Mat blank = dark.clone(); | ||
3516 | 987 | blank = 0.0; | ||
3517 | 988 | |||
3518 | 989 | Mat contour_shading = blank;//dark.clone(); | ||
3519 | 990 | |||
3520 | 991 | for (vector<vector<Point> >::iterator it = contours.begin(); | ||
3521 | 992 | it != contours.end(); ++it){ | ||
3522 | 993 | |||
3523 | 994 | vector<Point>& contour = *it; | ||
3524 | 995 | |||
3525 | 996 | Rect r = boundingRect(Mat(contour)); | ||
3526 | 997 | |||
3527 | 998 | double a1 = contourArea(Mat(contour)); | ||
3528 | 999 | double a2 = r.height * r.width; | ||
3529 | 1000 | |||
3530 | 1001 | |||
3531 | 1002 | if (a2 < 100) | ||
3532 | 1003 | continue; | ||
3533 | 1004 | |||
3534 | 1005 | |||
3535 | 1006 | if (abs(r.width - 65) > 5) | ||
3536 | 1007 | continue; | ||
3537 | 1008 | |||
3538 | 1009 | //if ( min(a1,a2)/max(a1,a2) > 0.80){ | ||
3539 | 1010 | |||
3540 | 1011 | vector<vector<Point> > cs; | ||
3541 | 1012 | cs.push_back(contour); | ||
3542 | 1013 | drawContours(contour_shading, cs, -1, Color::RANDOM(), CV_FILLED); | ||
3543 | 1014 | |||
3544 | 1015 | |||
3545 | 1016 | Blob blob(r); | ||
3546 | 1017 | blobs.push_back(blob); | ||
3547 | 1018 | //} | ||
3548 | 1019 | |||
3549 | 1020 | } | ||
3550 | 1021 | |||
3551 | 1022 | Mat contours_image = contour_shading*0.7 + dark*0.5; | ||
3552 | 1023 | |||
3553 | 1024 | Painter::drawBlobs(contours_image, blobs, Color::WHITE); | ||
3554 | 1025 | |||
3555 | 1026 | VLOG("ColoredSelectedContours", contours_image); | ||
3556 | 1027 | |||
3557 | 1028 | |||
3558 | 1029 | |||
3559 | 1030 | |||
3560 | 1031 | vector<Blob> nonoverlapping_blobs; | ||
3561 | 1032 | |||
3562 | 1033 | // print output to stdout | ||
3563 | 1034 | for (vector<Blob>::iterator it = blobs.begin(); | ||
3564 | 1035 | it != blobs.end(); ++it){ | ||
3565 | 1036 | |||
3566 | 1037 | Blob& b = *it; | ||
3567 | 1038 | bool not_overlap = true; | ||
3568 | 1039 | for (vector<Blob>::iterator ito = nonoverlapping_blobs.begin(); | ||
3569 | 1040 | ito != nonoverlapping_blobs.end(); ++ito){ | ||
3570 | 1041 | |||
3571 | 1042 | Blob& bo = *ito; | ||
3572 | 1043 | |||
3573 | 1044 | not_overlap = b.x >= bo.x + bo.width || b.y >= bo.y + bo.height || | ||
3574 | 1045 | b.x + b.width <= bo.x || b.y + b.height <= bo.y; | ||
3575 | 1046 | |||
3576 | 1047 | if (!not_overlap) | ||
3577 | 1048 | break; | ||
3578 | 1049 | |||
3579 | 1050 | } | ||
3580 | 1051 | |||
3581 | 1052 | if (not_overlap){ | ||
3582 | 1053 | nonoverlapping_blobs.push_back(b); | ||
3583 | 1054 | } | ||
3584 | 1055 | |||
3585 | 1056 | } | ||
3586 | 1057 | |||
3587 | 1058 | |||
3588 | 1059 | vector<Blob>& result_blobs = nonoverlapping_blobs | ||
3589 | 1060 | |||
3590 | 1061 | |||
3591 | 1062 | Mat blobs_result = dark.clone(); | ||
3592 | 1063 | Painter::drawBlobs(blobs_result, result_blobs, Color::RED); | ||
3593 | 1064 | |||
3594 | 1065 | VLOG("OutputBlobs", blobs_result); | ||
3595 | 1066 | |||
3596 | 1067 | // print output to stdout | ||
3597 | 1068 | for (vector<Blob>::iterator it = result_blobs.begin(); | ||
3598 | 1069 | it != result_blobs.end(); ++it){ | ||
3599 | 1070 | |||
3600 | 1071 | dout() << b.x << " " << b.y << " " << b.width << " " << b.height << endl; | ||
3601 | 1072 | } | ||
3602 | 1073 | |||
3603 | 1074 | |||
3604 | 1075 | return contours_image; | ||
3605 | 1076 | #endif | ||
3606 | 1077 | } | ||
3607 | 1078 | |||
3608 | 1079 | void | ||
3609 | 1080 | cvgui::findBoxes(const Mat& screen, vector<Blob>& output_blobs){ | ||
3610 | 1081 | |||
3611 | 1082 | Mat dark; | ||
3612 | 1083 | Util::rgb2grayC3(screen,dark); | ||
3613 | 1084 | dark = dark * 0.5; | ||
3614 | 1085 | |||
3615 | 1086 | |||
3616 | 1087 | VLOG("Input", screen); | ||
3617 | 1088 | |||
3618 | 1089 | Mat gray; | ||
3619 | 1090 | cvtColor(screen,gray,CV_RGB2GRAY); | ||
3620 | 1091 | |||
3621 | 1092 | //medianBlur(gray, gray, 3); | ||
3622 | 1093 | //VLOG("Blurred", gray); | ||
3623 | 1094 | |||
3624 | 1095 | Mat edges; | ||
3625 | 1096 | |||
3626 | 1097 | // Code for experimenting differenty parameters for Canny | ||
3627 | 1098 | // for (int c=10;c<=100;c=c+10){ | ||
3628 | 1099 | // char buf[50]; | ||
3629 | 1100 | // Mat test; | ||
3630 | 1101 | // sprintf(buf,"Canny%d",c); | ||
3631 | 1102 | // Canny(gray,test,0.66*c,1.33*c,3,true); | ||
3632 | 1103 | // VLOG(buf, test); | ||
3633 | 1104 | // } | ||
3634 | 1105 | |||
3635 | 1106 | int s = 100; | ||
3636 | 1107 | Canny(gray,edges,0.66*s,1.33*s,3,true); | ||
3637 | 1108 | VLOG("Canny", edges); | ||
3638 | 1109 | |||
3639 | 1110 | |||
3640 | 1111 | dilate(edges, edges, Mat::ones(2,2,CV_8UC1)); | ||
3641 | 1112 | VLOG("Dilated", edges); | ||
3642 | 1113 | |||
3643 | 1114 | |||
3644 | 1115 | |||
3645 | 1116 | |||
3646 | 1117 | Mat result = dark.clone(); | ||
3647 | 1118 | Mat copy = edges.clone(); | ||
3648 | 1119 | |||
3649 | 1120 | |||
3650 | 1121 | vector<vector<Point> > contours; | ||
3651 | 1122 | vector<Vec4i> hierarchy; | ||
3652 | 1123 | |||
3653 | 1124 | findContours( copy, contours, hierarchy, | ||
3654 | 1125 | CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE ); | ||
3655 | 1126 | |||
3656 | 1127 | // findContours(edges, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); | ||
3657 | 1128 | |||
3658 | 1129 | //findContours( copy, contours, hierarchy, | ||
3659 | 1130 | // CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE ); | ||
3660 | 1131 | |||
3661 | 1132 | // cout << contours.size() << " " << hierarchy.size() << endl; | ||
3662 | 1133 | // iterate through all the top-level contours, | ||
3663 | 1134 | // draw each connected component with its own random color | ||
3664 | 1135 | // int idx = 0; | ||
3665 | 1136 | // for( ; idx >= 0; idx = hierarchy[idx][0]){ | ||
3666 | 1137 | // | ||
3667 | 1138 | // vector<Point>& contour = contours[idx]; | ||
3668 | 1139 | // | ||
3669 | 1140 | // | ||
3670 | 1141 | // //Scalar color( rand()&255, rand()&255, rand()&255 ); | ||
3671 | 1142 | // Scalar cyan(255,255,0); | ||
3672 | 1143 | // vector<vector<Point> > cs; | ||
3673 | 1144 | // cs.push_back(contour); | ||
3674 | 1145 | // drawContours( result, cs, -1, cyan, 2);//, CV_FILLED); | ||
3675 | 1146 | // | ||
3676 | 1147 | // // drawContours( result, contours, idx, color, CV_FILLED, 8, hierarchy ); | ||
3677 | 1148 | // | ||
3678 | 1149 | // } | ||
3679 | 1150 | |||
3680 | 1151 | vector<Blob> blobs; | ||
3681 | 1152 | |||
3682 | 1153 | |||
3683 | 1154 | Mat box_contour_image = dark.clone(); | ||
3684 | 1155 | |||
3685 | 1156 | for (vector<vector<Point> >::iterator it = contours.begin(); | ||
3686 | 1157 | it != contours.end(); ++it){ | ||
3687 | 1158 | |||
3688 | 1159 | vector<Point>& contour = *it; | ||
3689 | 1160 | |||
3690 | 1161 | Rect r = boundingRect(Mat(contour)); | ||
3691 | 1162 | |||
3692 | 1163 | double a1 = contourArea(Mat(contour)); | ||
3693 | 1164 | double a2 = r.height * r.width; | ||
3694 | 1165 | |||
3695 | 1166 | |||
3696 | 1167 | |||
3697 | 1168 | |||
3698 | 1169 | if ( min(a1,a2)/max(a1,a2) > 0.80){ | ||
3699 | 1170 | |||
3700 | 1171 | vector<vector<Point> > cs; | ||
3701 | 1172 | cs.push_back(contour); | ||
3702 | 1173 | drawContours(box_contour_image, cs, -1, Color::RANDOM(), 2);//, CV_FILLED); | ||
3703 | 1174 | |||
3704 | 1175 | |||
3705 | 1176 | Blob blob(r); | ||
3706 | 1177 | blobs.push_back(blob); | ||
3707 | 1178 | } | ||
3708 | 1179 | |||
3709 | 1180 | } | ||
3710 | 1181 | |||
3711 | 1182 | |||
3712 | 1183 | VLOG("Box-shaped contours", box_contour_image); | ||
3713 | 1184 | |||
3714 | 1185 | |||
3715 | 1186 | Mat blobs_result = dark.clone(); | ||
3716 | 1187 | Painter::drawBlobs(blobs_result, blobs, Color::RED); | ||
3717 | 1188 | |||
3718 | 1189 | VLOG("Blobs", blobs_result); | ||
3719 | 1190 | |||
3720 | 1191 | |||
3721 | 1192 | vector<Blob> unique_blobs; | ||
3722 | 1193 | for (vector<Blob>::iterator it = blobs.begin(); | ||
3723 | 1194 | it != blobs.end(); ++it){ | ||
3724 | 1195 | |||
3725 | 1196 | Blob& a = *it; | ||
3726 | 1197 | |||
3727 | 1198 | |||
3728 | 1199 | vector<Blob>::iterator it1; | ||
3729 | 1200 | for (it1 = unique_blobs.begin(); | ||
3730 | 1201 | it1 != unique_blobs.end(); ++it1){ | ||
3731 | 1202 | |||
3732 | 1203 | Blob& b = *it1; | ||
3733 | 1204 | |||
3734 | 1205 | int d = 5; | ||
3735 | 1206 | bool similar_bounding_box = | ||
3736 | 1207 | abs(a.x-b.x) < d && abs(a.y-b.y) < d && | ||
3737 | 1208 | abs(a.height-b.height) < 2*d && | ||
3738 | 1209 | abs(a.width-b.width) < 2*d; | ||
3739 | 1210 | |||
3740 | 1211 | |||
3741 | 1212 | if (similar_bounding_box) | ||
3742 | 1213 | break; | ||
3743 | 1214 | |||
3744 | 1215 | } | ||
3745 | 1216 | |||
3746 | 1217 | // if no blob whose bounding box is similar | ||
3747 | 1218 | if (it1 == unique_blobs.end()){ | ||
3748 | 1219 | |||
3749 | 1220 | // add this blob to the list of unique blobs | ||
3750 | 1221 | unique_blobs.push_back(a); | ||
3751 | 1222 | } | ||
3752 | 1223 | } | ||
3753 | 1224 | |||
3754 | 1225 | Mat unique_blobs_result = dark.clone(); | ||
3755 | 1226 | Painter::drawBlobs(unique_blobs_result, unique_blobs, Color::RED); | ||
3756 | 1227 | |||
3757 | 1228 | VLOG("UniqueBlobs", unique_blobs_result); | ||
3758 | 1229 | |||
3759 | 1230 | |||
3760 | 1231 | vector<Blob> leaf_blobs; | ||
3761 | 1232 | getLeafBlobs(unique_blobs, leaf_blobs); | ||
3762 | 1233 | |||
3763 | 1234 | |||
3764 | 1235 | Mat leaf_blobs_result = dark.clone(); | ||
3765 | 1236 | Painter::drawBlobs(leaf_blobs_result, leaf_blobs, Color::RED); | ||
3766 | 1237 | VLOG("LeafBlobs", leaf_blobs_result); | ||
3767 | 1238 | |||
3768 | 1239 | output_blobs = leaf_blobs; | ||
3769 | 1240 | } | ||
3770 | 1241 | |||
3771 | 1242 | |||
3772 | 1243 | |||
3773 | 1244 | |||
3774 | 1245 | void | ||
3775 | 1246 | cvgui::computeUnitBlobs(const Mat& screen, Mat& output){ | ||
3776 | 1247 | |||
3777 | 1248 | VLOG("Input", screen); | ||
3778 | 1249 | |||
3779 | 1250 | Mat gray; | ||
3780 | 1251 | cvtColor(screen,gray,CV_RGB2GRAY); | ||
3781 | 1252 | |||
3782 | 1253 | |||
3783 | 1254 | Mat edges; | ||
3784 | 1255 | Canny(gray,edges,0.66*50,1.33*50,3,true); | ||
3785 | 1256 | VLOG("Canny", edges); | ||
3786 | 1257 | |||
3787 | 1258 | // Mat corners; | ||
3788 | 1259 | // cornerHarris(gray,corners,10,5,1.0); | ||
3789 | 1260 | |||
3790 | 1261 | // Mat corners_result = screen.clone(); | ||
3791 | 1262 | // vector<Point2f> corners; | ||
3792 | 1263 | // goodFeaturesToTrack(gray, corners, 50, 0.5, 10); | ||
3793 | 1264 | // for (vector<Point2f>::iterator it = corners.begin(); it != corners.end(); ++it){ | ||
3794 | 1265 | // Point2f& p = *it; | ||
3795 | 1266 | // circle(corners_result, p, 3, Scalar(0,0,255)); | ||
3796 | 1267 | // } | ||
3797 | 1268 | // VLOG("Corners", corners_result); | ||
3798 | 1269 | |||
3799 | 1270 | |||
3800 | 1271 | adaptiveThreshold(gray, gray, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV, 5, 1); | ||
3801 | 1272 | VLOG("AdaptiveThresholded", gray); | ||
3802 | 1273 | |||
3803 | 1274 | Mat lines; | ||
3804 | 1275 | cvgui::findLongLines(gray, lines); | ||
3805 | 1276 | |||
3806 | 1277 | Mat lines_viz = lines.clone(); | ||
3807 | 1278 | dilate(lines_viz, lines_viz, Mat::ones(4,4,CV_8UC1)); | ||
3808 | 1279 | VLOG("LongLinesFound", lines_viz); | ||
3809 | 1280 | |||
3810 | 1281 | Mat not_lines; | ||
3811 | 1282 | bitwise_not(lines, not_lines); | ||
3812 | 1283 | |||
3813 | 1284 | Mat foreground; | ||
3814 | 1285 | bitwise_and(gray, not_lines, foreground); | ||
3815 | 1286 | |||
3816 | 1287 | gray.setTo(0, lines); | ||
3817 | 1288 | VLOG("LongLinesRemoved",gray); | ||
3818 | 1289 | |||
3819 | 1290 | |||
3820 | 1291 | dilate(edges, edges, Mat::ones(3,3,CV_8UC1)); | ||
3821 | 1292 | bitwise_and(gray, edges, gray); | ||
3822 | 1293 | |||
3823 | 1294 | VLOG("NonEdgeRemoved", gray); | ||
3824 | 1295 | |||
3825 | 1296 | //GaussianBlur(gray, gray, Size(3, 3), 3); | ||
3826 | 1297 | //VLOG("Blurred", gray); | ||
3827 | 1298 | |||
3828 | 1299 | output = gray; | ||
3829 | 1300 | } | ||
3830 | 1301 | |||
3831 | 1302 | |||
3832 | 1303 | |||
3833 | 1304 | void | ||
3834 | 1305 | cvgui::getParagraphBlobs(const Mat& screen, vector<ParagraphBlob>& output_parablobs){ | ||
3835 | 1306 | |||
3836 | 1307 | VisualLogger::newImage(); | ||
3837 | 1308 | Mat screen_gray; | ||
3838 | 1309 | cvtColor(screen,screen_gray,CV_RGB2GRAY); | ||
3839 | 1310 | |||
3840 | 1311 | Mat blobs_mask; | ||
3841 | 1312 | cvgui::computeUnitBlobs(screen, blobs_mask); | ||
3842 | 1313 | |||
3843 | 1314 | Mat dark; | ||
3844 | 1315 | Util::rgb2grayC3(screen,dark); | ||
3845 | 1316 | dark = dark * 0.5; | ||
3846 | 1317 | |||
3847 | 1318 | vector<Blob> blobs; | ||
3848 | 1319 | cvgui::extractBlobs(blobs_mask, blobs); | ||
3849 | 1320 | |||
3850 | 1321 | cvgui::calculateColor(blobs, screen, blobs_mask); | ||
3851 | 1322 | |||
3852 | 1323 | // draw blobs | ||
3853 | 1324 | Mat result_blobs = dark.clone(); | ||
3854 | 1325 | Painter::drawBlobs(result_blobs, blobs, Scalar(255,255,0)); | ||
3855 | 1326 | VLOG("blobs-extracted",result_blobs); | ||
3856 | 1327 | |||
3857 | 1328 | |||
3858 | 1329 | vector<Blob> filtered_blobs; | ||
3859 | 1330 | for (vector<Blob>::iterator it = blobs.begin(); | ||
3860 | 1331 | it != blobs.end(); ++it){ | ||
3861 | 1332 | |||
3862 | 1333 | Blob& blob = *it; | ||
3863 | 1334 | |||
3864 | 1335 | // if (blob.height < 3 && blob.width < 3) | ||
3865 | 1336 | // continue; | ||
3866 | 1337 | // | ||
3867 | 1338 | // if (blob.height < 4) | ||
3868 | 1339 | // continue; | ||
3869 | 1340 | |||
3870 | 1341 | filtered_blobs.push_back(blob); | ||
3871 | 1342 | } | ||
3872 | 1343 | |||
3873 | 1344 | Mat result_filtered_blobs = dark.clone(); | ||
3874 | 1345 | Painter::drawBlobs(result_filtered_blobs, filtered_blobs, Scalar(255,255,0)); | ||
3875 | 1346 | |||
3876 | 1347 | VLOG("blobs-filtered",result_filtered_blobs); | ||
3877 | 1348 | |||
3878 | 1349 | |||
3879 | 1350 | Mat result_lineblobs = dark.clone(); | ||
3880 | 1351 | |||
3881 | 1352 | vector<LineBlob> lineblobs; | ||
3882 | 1353 | cvgui::linkBlobsIntoLineBlobs(filtered_blobs, lineblobs, 20); | ||
3883 | 1354 | |||
3884 | 1355 | Painter::drawLineBlobs(result_lineblobs, lineblobs, Scalar(255,255,0)); | ||
3885 | 1356 | VLOG("lineblobs", result_lineblobs); | ||
3886 | 1357 | |||
3887 | 1358 | |||
3888 | 1359 | Mat result_lineblobs_filtered = dark.clone(); | ||
3889 | 1360 | vector<LineBlob> filtered_lineblobs; | ||
3890 | 1361 | |||
3891 | 1362 | // Calculate the bounding rectangle of each line of linked blobs | ||
3892 | 1363 | for (vector<LineBlob>::iterator it_lines = lineblobs.begin(); | ||
3893 | 1364 | it_lines != lineblobs.end(); ++ it_lines){ | ||
3894 | 1365 | |||
3895 | 1366 | LineBlob& line = *it_lines; | ||
3896 | 1367 | |||
3897 | 1368 | // Ignore lines with fewer than X elements | ||
3898 | 1369 | if (line.blobs.size()<2) | ||
3899 | 1370 | continue; | ||
3900 | 1371 | |||
3901 | 1372 | |||
3902 | 1373 | if (line.height < 3) | ||
3903 | 1374 | continue; | ||
3904 | 1375 | |||
3905 | 1376 | filtered_lineblobs.push_back(line); | ||
3906 | 1377 | } | ||
3907 | 1378 | |||
3908 | 1379 | |||
3909 | 1380 | |||
3910 | 1381 | Painter::drawLineBlobs(result_lineblobs_filtered, filtered_lineblobs, Scalar(255,255,0)); | ||
3911 | 1382 | VLOG("lineblobs-filtered", result_lineblobs_filtered); | ||
3912 | 1383 | |||
3913 | 1384 | |||
3914 | 1385 | Mat result_merged_blobs = dark.clone(); | ||
3915 | 1386 | |||
3916 | 1387 | vector<LineBlob> merged_lineblobs; | ||
3917 | 1388 | cvgui::mergeLineBlobs(filtered_lineblobs, merged_lineblobs); | ||
3918 | 1389 | Painter::drawLineBlobs(result_merged_blobs, merged_lineblobs, Scalar(255,255,0)); | ||
3919 | 1390 | VLOG("lineblobs-merged", result_merged_blobs); | ||
3920 | 1391 | |||
3921 | 1392 | |||
3922 | 1393 | vector<ParagraphBlob> parablobs; | ||
3923 | 1394 | cvgui::linkLineBlobsIntoPagagraphBlobs(merged_lineblobs, parablobs); | ||
3924 | 1395 | |||
3925 | 1396 | Mat result_linked_parablobs = dark.clone(); | ||
3926 | 1397 | |||
3927 | 1398 | Painter::drawParagraphBlobs(result_linked_parablobs, parablobs, Scalar(255,0,0)); | ||
3928 | 1399 | |||
3929 | 1400 | VLOG("paragblobs", result_linked_parablobs); | ||
3930 | 1401 | |||
3931 | 1402 | |||
3932 | 1403 | output_parablobs = parablobs; | ||
3933 | 1404 | |||
3934 | 1405 | |||
3935 | 1406 | // Mat screen_dark = screen * 0.2; | ||
3936 | 1407 | // Mat ocr_result_image = screen_dark; | ||
3937 | 1408 | // | ||
3938 | 1409 | // | ||
3939 | 1410 | // for (vector<ParagraphBlob>::iterator it = parablobs.begin(); | ||
3940 | 1411 | // it != parablobs.end(); ++it){ | ||
3941 | 1412 | // | ||
3942 | 1413 | // | ||
3943 | 1414 | // ParagraphBlob& parablob = *it; | ||
3944 | 1415 | // | ||
3945 | 1416 | // vector<OCRLine> ocrlines; | ||
3946 | 1417 | // | ||
3947 | 1418 | // cvgui::run_ocr_on_lineblobs(parablob.lineblobs, screen_gray, ocrlines); | ||
3948 | 1419 | // | ||
3949 | 1420 | // Painter::drawOCRLines(ocr_result_image, ocrlines); | ||
3950 | 1421 | // | ||
3951 | 1422 | // } | ||
3952 | 1423 | // | ||
3953 | 1424 | // VLOG("OCR-Result", ocr_result_image); | ||
3954 | 1425 | |||
3955 | 1426 | |||
3956 | 1427 | } | ||
3957 | 1428 | |||
3958 | 1429 | |||
3959 | 1430 | void | ||
3960 | 1431 | cvgui::getLineBlobsAsIndividualWords(const Mat& screen, vector<LineBlob>& output_lineblobs){ | ||
3961 | 1432 | |||
3962 | 1433 | Mat screen_gray; | ||
3963 | 1434 | cvtColor(screen,screen_gray,CV_RGB2GRAY); | ||
3964 | 1435 | |||
3965 | 1436 | Mat blobs_mask; | ||
3966 | 1437 | cvgui::computeUnitBlobs(screen, blobs_mask); | ||
3967 | 1438 | |||
3968 | 1439 | Mat dark; | ||
3969 | 1440 | Util::rgb2grayC3(screen,dark); | ||
3970 | 1441 | dark = dark * 0.5; | ||
3971 | 1442 | |||
3972 | 1443 | vector<Blob> blobs; | ||
3973 | 1444 | cvgui::extractBlobs(blobs_mask, blobs); | ||
3974 | 1445 | |||
3975 | 1446 | cvgui::calculateColor(blobs, screen, blobs_mask); | ||
3976 | 1447 | |||
3977 | 1448 | // draw blobs | ||
3978 | 1449 | Mat result_blobs = dark.clone(); | ||
3979 | 1450 | Painter::drawBlobs(result_blobs, blobs, Scalar(255,255,0)); | ||
3980 | 1451 | VLOG("blobs-extracted",result_blobs); | ||
3981 | 1452 | |||
3982 | 1453 | |||
3983 | 1454 | vector<Blob> filtered_blobs; | ||
3984 | 1455 | for (vector<Blob>::iterator it = blobs.begin(); | ||
3985 | 1456 | it != blobs.end(); ++it){ | ||
3986 | 1457 | |||
3987 | 1458 | Blob& blob = *it; | ||
3988 | 1459 | |||
3989 | 1460 | // if (blob.height < 3 && blob.width < 3) | ||
3990 | 1461 | // continue; | ||
3991 | 1462 | // | ||
3992 | 1463 | // if (blob.height < 4) | ||
3993 | 1464 | // continue; | ||
3994 | 1465 | |||
3995 | 1466 | filtered_blobs.push_back(blob); | ||
3996 | 1467 | } | ||
3997 | 1468 | |||
3998 | 1469 | Mat result_filtered_blobs = dark.clone(); | ||
3999 | 1470 | Painter::drawBlobs(result_filtered_blobs, filtered_blobs, Scalar(255,255,0)); | ||
4000 | 1471 | |||
4001 | 1472 | VLOG("blobs-filtered",result_filtered_blobs); | ||
4002 | 1473 | |||
4003 | 1474 | |||
4004 | 1475 | Mat result_lineblobs = dark.clone(); | ||
4005 | 1476 | |||
4006 | 1477 | vector<LineBlob> lineblobs; | ||
4007 | 1478 | cvgui::linkBlobsIntoLineBlobs(filtered_blobs, lineblobs, 3); | ||
4008 | 1479 | |||
4009 | 1480 | Painter::drawLineBlobs(result_lineblobs, lineblobs, Scalar(255,255,0)); | ||
4010 | 1481 | VLOG("lineblobs", result_lineblobs); | ||
4011 | 1482 | |||
4012 | 1483 | |||
4013 | 1484 | Mat result_lineblobs_filtered = dark.clone(); | ||
4014 | 1485 | vector<LineBlob> filtered_lineblobs; | ||
4015 | 1486 | |||
4016 | 1487 | // Calculate the bounding rectangle of each line of linked blobs | ||
4017 | 1488 | for (vector<LineBlob>::iterator it_lines = lineblobs.begin(); | ||
4018 | 1489 | it_lines != lineblobs.end(); ++ it_lines){ | ||
4019 | 1490 | |||
4020 | 1491 | LineBlob& line = *it_lines; | ||
4021 | 1492 | |||
4022 | 1493 | // Ignore lines with fewer than X elements | ||
4023 | 1494 | // if (line.blobs.size()<2) | ||
4024 | 1495 | // continue; | ||
4025 | 1496 | |||
4026 | 1497 | if (line.height < 3) | ||
4027 | 1498 | continue; | ||
4028 | 1499 | |||
4029 | 1500 | filtered_lineblobs.push_back(line); | ||
4030 | 1501 | } | ||
4031 | 1502 | |||
4032 | 1503 | |||
4033 | 1504 | |||
4034 | 1505 | Painter::drawLineBlobs(result_lineblobs_filtered, filtered_lineblobs, Scalar(255,255,0)); | ||
4035 | 1506 | VLOG("lineblobs-filtered", result_lineblobs_filtered); | ||
4036 | 1507 | |||
4037 | 1508 | |||
4038 | 1509 | |||
4039 | 1510 | output_lineblobs = filtered_lineblobs; | ||
4040 | 1511 | |||
4041 | 1512 | // Mat result_merged_blobs = dark.clone(); | ||
4042 | 1513 | // | ||
4043 | 1514 | // vector<LineBlob> merged_lineblobs; | ||
4044 | 1515 | // cvgui::mergeLineBlobs(filtered_lineblobs, merged_lineblobs); | ||
4045 | 1516 | // Painter::drawLineBlobs(result_merged_blobs, merged_lineblobs, Scalar(255,255,0)); | ||
4046 | 1517 | // VLOG("lineblobs-merged", result_merged_blobs); | ||
4047 | 1518 | // | ||
4048 | 1519 | // | ||
4049 | 1520 | // vector<ParagraphBlob> parablobs; | ||
4050 | 1521 | // cvgui::linkLineBlobsIntoPagagraphBlobs(merged_lineblobs, parablobs); | ||
4051 | 1522 | // | ||
4052 | 1523 | // Mat result_linked_parablobs = dark.clone(); | ||
4053 | 1524 | // | ||
4054 | 1525 | // Painter::drawParagraphBlobs(result_linked_parablobs, parablobs, Scalar(255,0,0)); | ||
4055 | 1526 | // | ||
4056 | 1527 | // VLOG("paragraph-linked", result_linked_parablobs); | ||
4057 | 1528 | // | ||
4058 | 1529 | // | ||
4059 | 1530 | // Mat screen_dark = screen * 0.2; | ||
4060 | 1531 | // Mat ocr_result_image = screen_dark; | ||
4061 | 1532 | // | ||
4062 | 1533 | // | ||
4063 | 1534 | // for (vector<ParagraphBlob>::iterator it = parablobs.begin(); | ||
4064 | 1535 | // it != parablobs.end(); ++it){ | ||
4065 | 1536 | // | ||
4066 | 1537 | // | ||
4067 | 1538 | // ParagraphBlob& parablob = *it; | ||
4068 | 1539 | // | ||
4069 | 1540 | // vector<OCRLine> ocrlines; | ||
4070 | 1541 | // | ||
4071 | 1542 | // cvgui::run_ocr_on_lineblobs(parablob.lineblobs, screen_gray, ocrlines); | ||
4072 | 1543 | // | ||
4073 | 1544 | // Painter::drawOCRLines(ocr_result_image, ocrlines); | ||
4074 | 1545 | // | ||
4075 | 1546 | // } | ||
4076 | 1547 | // | ||
4077 | 1548 | // VLOG("OCR-Result", ocr_result_image); | ||
4078 | 1549 | } | ||
4079 | 1550 | |||
4080 | 1551 | void | ||
4081 | 1552 | cvgui::segmentScreenshot(const Mat& screen, vector<Blob>& text_blobs, vector<Blob>& image_blobs){ | ||
4082 | 1553 | |||
4083 | 1554 | VLOG("Input", screen); | ||
4084 | 1555 | |||
4085 | 1556 | Mat gray, screen_gray; | ||
4086 | 1557 | if(screen.channels() > 1){ | ||
4087 | 1558 | cvtColor(screen,gray,CV_RGB2GRAY); | ||
4088 | 1559 | } | ||
4089 | 1560 | else | ||
4090 | 1561 | gray = screen; | ||
4091 | 1562 | |||
4092 | 1563 | screen_gray = gray.clone(); | ||
4093 | 1564 | |||
4094 | 1565 | adaptiveThreshold(gray, gray, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV, 5, 1); | ||
4095 | 1566 | VLOG("AdaptiveThresholded", gray); | ||
4096 | 1567 | |||
4097 | 1568 | |||
4098 | 1569 | Mat lines; | ||
4099 | 1570 | cvgui::findLongLines(gray, lines); | ||
4100 | 1571 | |||
4101 | 1572 | Mat lines_viz = lines.clone(); | ||
4102 | 1573 | dilate(lines_viz, lines_viz, Mat::ones(4,4,CV_8UC1)); | ||
4103 | 1574 | VLOG("LongLinesFound", lines_viz); | ||
4104 | 1575 | |||
4105 | 1576 | Mat not_lines; | ||
4106 | 1577 | bitwise_not(lines, not_lines); | ||
4107 | 1578 | |||
4108 | 1579 | Mat foreground; | ||
4109 | 1580 | bitwise_and(gray, not_lines, foreground); | ||
4110 | 1581 | |||
4111 | 1582 | gray.setTo(0, lines); | ||
4112 | 1583 | VLOG("LongLinesRemoved",gray); | ||
4113 | 1584 | |||
4114 | 1585 | |||
4115 | 1586 | denoise(gray); | ||
4116 | 1587 | VLOG("NoiseRemoved", gray); | ||
4117 | 1588 | |||
4118 | 1589 | dilate(gray,gray,Mat::ones(1,3,CV_8UC1)); | ||
4119 | 1590 | VLOG("Dilated",gray); | ||
4120 | 1591 | |||
4121 | 1592 | vector<Rect> rects; | ||
4122 | 1593 | //cvgui::extractRects(gray, rects); | ||
4123 | 1594 | |||
4124 | 1595 | vector<Blob> blobs; | ||
4125 | 1596 | cvgui::extractBlobs(gray, blobs); | ||
4126 | 1597 | |||
4127 | 1598 | |||
4128 | 1599 | Mat dilated = gray.clone(); | ||
4129 | 1600 | |||
4130 | 1601 | |||
4131 | 1602 | // visualization | ||
4132 | 1603 | Mat result; | ||
4133 | 1604 | Mat g; | ||
4134 | 1605 | cvtColor(screen, g, CV_RGB2GRAY); | ||
4135 | 1606 | |||
4136 | 1607 | Mat ss[3] = {g,g,g}; | ||
4137 | 1608 | merge(ss,3,result); | ||
4138 | 1609 | result = result * 0.5; | ||
4139 | 1610 | |||
4140 | 1611 | Mat bg = result.clone(); | ||
4141 | 1612 | Mat screen_darken = bg.clone(); | ||
4142 | 1613 | |||
4143 | 1614 | |||
4144 | 1615 | text_blobs.clear(); | ||
4145 | 1616 | |||
4146 | 1617 | for (vector<Blob>::iterator b = blobs.begin(); b != blobs.end(); ++b){ | ||
4147 | 1618 | |||
4148 | 1619 | Blob& blob = *b; | ||
4149 | 1620 | Rect& bound = blob; | ||
4150 | 1621 | Mat part(screen, bound); | ||
4151 | 1622 | //paste(part, result, r->x, r->y); | ||
4152 | 1623 | |||
4153 | 1624 | Mat p = part.clone(); | ||
4154 | 1625 | Mat g; | ||
4155 | 1626 | cvtColor(p, g, CV_RGB2GRAY); | ||
4156 | 1627 | adaptiveThreshold(g, g, 255, | ||
4157 | 1628 | ADAPTIVE_THRESH_MEAN_C, | ||
4158 | 1629 | THRESH_BINARY_INV, 3, 1); | ||
4159 | 1630 | vector<Rect> rs; | ||
4160 | 1631 | cvgui::extractSmallRects(g, rs); | ||
4161 | 1632 | for (vector<Rect>::iterator r = rs.begin();r != rs.end(); ++r){ | ||
4162 | 1633 | r->x += bound.x; | ||
4163 | 1634 | r->y += bound.y; | ||
4164 | 1635 | } | ||
4165 | 1636 | |||
4166 | 1637 | vector<Rect> rs0; | ||
4167 | 1638 | for (vector<Rect>::iterator q = rs.begin(); | ||
4168 | 1639 | q != rs.end(); ++q){ | ||
4169 | 1640 | |||
4170 | 1641 | // exclude overly short element (e.g., dot of i) | ||
4171 | 1642 | if (q->height < 5) | ||
4172 | 1643 | continue; | ||
4173 | 1644 | |||
4174 | 1645 | rs0.push_back(*q); | ||
4175 | 1646 | } | ||
4176 | 1647 | |||
4177 | 1648 | rs = rs0; | ||
4178 | 1649 | |||
4179 | 1650 | // re-calculate the bounds | ||
4180 | 1651 | int x1,y1,x2,y2; | ||
4181 | 1652 | x1 = bound.x + bound.width; | ||
4182 | 1653 | y1 = bound.y + bound.height; | ||
4183 | 1654 | x2 = bound.x; | ||
4184 | 1655 | y2 = bound.y; | ||
4185 | 1656 | |||
4186 | 1657 | for (vector<Rect>::iterator r = rs.begin(); | ||
4187 | 1658 | r != rs.end(); ++r){ | ||
4188 | 1659 | x1 = min(x1, r->x); | ||
4189 | 1660 | y1 = min(y1, r->y); | ||
4190 | 1661 | x2 = max(x2, r->x + r->width); | ||
4191 | 1662 | y2 = max(y2, r->y + r->height); | ||
4192 | 1663 | } | ||
4193 | 1664 | |||
4194 | 1665 | //blob.bound = Rect(x1-2,y1-2,x2-x1+4,y2-y1+4); | ||
4195 | 1666 | //blob.bound = Rect(x1,y1,x2-x1,y2-y1); | ||
4196 | 1667 | |||
4197 | 1668 | // make the bound bigger to be consistent with the dilated blobs | ||
4198 | 1669 | blob = Blob(Rect(x1-2,y1-1,x2-x1+4,y2-y1+2)); | ||
4199 | 1670 | |||
4200 | 1671 | |||
4201 | 1672 | int MINIMUM_NUM_CHARBLOBS = 2; | ||
4202 | 1673 | |||
4203 | 1674 | if (cvgui::areHorizontallyAligned(rs) && rs.size()>=MINIMUM_NUM_CHARBLOBS) | ||
4204 | 1675 | Painter::drawRects(result, rs, Scalar(0,255,0)); | ||
4205 | 1676 | else | ||
4206 | 1677 | Painter::drawRects(result, rs, Scalar(0,0,255)); | ||
4207 | 1678 | |||
4208 | 1679 | if (cvgui::areHorizontallyAligned(rs) && rs.size()>=MINIMUM_NUM_CHARBLOBS){ | ||
4209 | 1680 | text_blobs.push_back(blob); | ||
4210 | 1681 | } | ||
4211 | 1682 | |||
4212 | 1683 | } | ||
4213 | 1684 | |||
4214 | 1685 | //drawRects(result, rects, Scalar(255,0,0)); | ||
4215 | 1686 | Painter::drawBlobs(result, blobs, Scalar(255,0,0)); | ||
4216 | 1687 | |||
4217 | 1688 | VLOG("TextBlocksExtracted",result); | ||
4218 | 1689 | |||
4219 | 1690 | |||
4220 | 1691 | |||
4221 | 1692 | Mat text_mask = Mat::zeros(screen.size(), CV_8UC1); | ||
4222 | 1693 | |||
4223 | 1694 | |||
4224 | 1695 | for (vector<Blob>::iterator b = text_blobs.begin(); | ||
4225 | 1696 | b != text_blobs.end(); ++b){ | ||
4226 | 1697 | |||
4227 | 1698 | Rect& r = *b; | ||
4228 | 1699 | Mat m(text_mask, | ||
4229 | 1700 | Range(r.y,r.y+r.height), | ||
4230 | 1701 | Range(r.x,r.x+r.width)); | ||
4231 | 1702 | |||
4232 | 1703 | m = 255; | ||
4233 | 1704 | |||
4234 | 1705 | } | ||
4235 | 1706 | |||
4236 | 1707 | VLOG("TextBinaryMaskComputed", text_mask); | ||
4237 | 1708 | |||
4238 | 1709 | |||
4239 | 1710 | |||
4240 | 1711 | |||
4241 | 1712 | gray.setTo(0, text_mask); | ||
4242 | 1713 | VLOG("AfterTextRemoved",gray); | ||
4243 | 1714 | |||
4244 | 1715 | dilate(gray,gray,Mat()); | ||
4245 | 1716 | VLOG("DilatedAgain",gray); | ||
4246 | 1717 | |||
4247 | 1718 | Mat dilated_again = gray.clone(); | ||
4248 | 1719 | |||
4249 | 1720 | vector<Blob> temp; | ||
4250 | 1721 | //cvgui::extractRects(gray, temp); | ||
4251 | 1722 | cvgui::extractBlobs(gray, temp); | ||
4252 | 1723 | |||
4253 | 1724 | // only keep image rects larger than n pixels | ||
4254 | 1725 | |||
4255 | 1726 | const int MIN_IMAGE_RECT_AREA = 150; | ||
4256 | 1727 | |||
4257 | 1728 | image_blobs.clear(); | ||
4258 | 1729 | for (vector<Blob>::iterator b = temp.begin(); | ||
4259 | 1730 | b != temp.end(); ++b){ | ||
4260 | 1731 | |||
4261 | 1732 | if (b->width * b->height < MIN_IMAGE_RECT_AREA) | ||
4262 | 1733 | continue; | ||
4263 | 1734 | |||
4264 | 1735 | // // blob is too big, something is wrong | ||
4265 | 1736 | // if (b->bound.width > 0.8 * screen.width) | ||
4266 | 1737 | // continue; | ||
4267 | 1738 | // if (b->bound.height > 0.8 * screen.height) | ||
4268 | 1739 | // continue; | ||
4269 | 1740 | |||
4270 | 1741 | image_blobs.push_back(*b); | ||
4271 | 1742 | |||
4272 | 1743 | } | ||
4273 | 1744 | |||
4274 | 1745 | Mat image_result = bg.clone(); | ||
4275 | 1746 | |||
4276 | 1747 | Painter::drawBlobs(image_result, image_blobs, Scalar(0,0,255)); | ||
4277 | 1748 | VLOG("ImageRecordsExtracted", image_result); | ||
4278 | 1749 | |||
4279 | 1750 | return; | ||
4280 | 1751 | |||
4281 | 1752 | Mat ui_mask = Mat::zeros(screen.size(), CV_8UC1); | ||
4282 | 1753 | Mat photo_mask = Mat::zeros(screen.size(), CV_8UC1); | ||
4283 | 1754 | for (vector<Blob>::iterator b = image_blobs.begin(); | ||
4284 | 1755 | b != image_blobs.end(); ++b){ | ||
4285 | 1756 | |||
4286 | 1757 | Rect& r = *b; | ||
4287 | 1758 | Mat mask; | ||
4288 | 1759 | if (r.height < 100) | ||
4289 | 1760 | mask = ui_mask; | ||
4290 | 1761 | else | ||
4291 | 1762 | mask = photo_mask; | ||
4292 | 1763 | |||
4293 | 1764 | Mat m(mask, | ||
4294 | 1765 | Range(r.y,r.y+r.height), | ||
4295 | 1766 | Range(r.x,r.x+r.width)); | ||
4296 | 1767 | |||
4297 | 1768 | m = 255; | ||
4298 | 1769 | } | ||
4299 | 1770 | |||
4300 | 1771 | VLOG("UIMask", ui_mask); | ||
4301 | 1772 | VLOG("PhotoMask", photo_mask); | ||
4302 | 1773 | |||
4303 | 1774 | Mat segmap; | ||
4304 | 1775 | Mat segmapr; | ||
4305 | 1776 | Mat segmapg; | ||
4306 | 1777 | Mat segmapb; | ||
4307 | 1778 | |||
4308 | 1779 | bitwise_and(dilated,text_mask,segmapr); | ||
4309 | 1780 | bitwise_and(dilated,ui_mask,segmapg); | ||
4310 | 1781 | bitwise_and(dilated_again,photo_mask,segmapb); | ||
4311 | 1782 | //segmapb = photo_mask; | ||
4312 | 1783 | |||
4313 | 1784 | |||
4314 | 1785 | Mat cs[3] = {segmapb, segmapg,segmapr}; | ||
4315 | 1786 | merge(cs,3,segmap); | ||
4316 | 1787 | VLOG("SegMap", segmap); | ||
4317 | 1788 | |||
4318 | 1789 | |||
4319 | 1790 | //Mat wordmap = screen_darken.clone();//segmap.clone(); | ||
4320 | 1791 | Mat wordmap = Mat::zeros(screen.size(), CV_8UC3); | ||
4321 | 1792 | |||
4322 | 1793 | |||
4323 | 1794 | screen.copyTo(wordmap, segmapg); | ||
4324 | 1795 | screen.copyTo(wordmap, photo_mask); | ||
4325 | 1796 | screen.copyTo(wordmap, text_mask); | ||
4326 | 1797 | |||
4327 | 1798 | |||
4328 | 1799 | |||
4329 | 1800 | Mat random_ids = Mat::ones(1,100,CV_8UC1); | ||
4330 | 1801 | randu(random_ids, 22, 80); | ||
4331 | 1802 | |||
4332 | 1803 | Scalar white(255,255,255); | ||
4333 | 1804 | Scalar black(0,0,0); | ||
4334 | 1805 | Scalar yellow(255,255,0); | ||
4335 | 1806 | |||
4336 | 1807 | |||
4337 | 1808 | int i = 0; | ||
4338 | 1809 | |||
4339 | 1810 | for (vector<Blob>::iterator b = image_blobs.begin(); | ||
4340 | 1811 | b != image_blobs.end(); ++b){ | ||
4341 | 1812 | |||
4342 | 1813 | Rect& r = *b; | ||
4343 | 1814 | |||
4344 | 1815 | |||
4345 | 1816 | char vwstr[100]; | ||
4346 | 1817 | |||
4347 | 1818 | |||
4348 | 1819 | if (r.height < 100){ | ||
4349 | 1820 | |||
4350 | 1821 | int xc = r.x + r.width/2; | ||
4351 | 1822 | int yc = r.y + r.height/2; | ||
4352 | 1823 | |||
4353 | 1824 | |||
4354 | 1825 | // putTextWithBackgroundCentered(black, wordmap, "u12", Point(xc,yc), | ||
4355 | 1826 | // FONT_HERSHEY_SIMPLEX, 0.5, white); | ||
4356 | 1827 | |||
4357 | 1828 | int id = random_ids.at<uchar>(0,i++); | ||
4358 | 1829 | sprintf(vwstr,"u%d",id); | ||
4359 | 1830 | |||
4360 | 1831 | // putTextWithBackgroundCentered(white, wordmap, vwstr, Point(xc,yc), | ||
4361 | 1832 | // FONT_HERSHEY_DUPLEX, 0.5, black); | ||
4362 | 1833 | |||
4363 | 1834 | |||
4364 | 1835 | }else{ | ||
4365 | 1836 | |||
4366 | 1837 | |||
4367 | 1838 | SURF surf_extractor(6.0e3); | ||
4368 | 1839 | vector<KeyPoint> keypoints; | ||
4369 | 1840 | |||
4370 | 1841 | // printf("Extracting keypoints\n"); | ||
4371 | 1842 | surf_extractor(screen_gray, photo_mask, keypoints); | ||
4372 | 1843 | //printf("Extracted %d keypoints from the image\n", (int)keypoints.size()); | ||
4373 | 1844 | |||
4374 | 1845 | for (vector<KeyPoint>::iterator it = keypoints.begin(); it != keypoints.end(); ++it){ | ||
4375 | 1846 | KeyPoint& p = *it; | ||
4376 | 1847 | |||
4377 | 1848 | circle(wordmap, p.pt, p.size*1.5, yellow); | ||
4378 | 1849 | |||
4379 | 1850 | // putTextWithBackgroundCentered(black, wordmap, "v12", p.pt, | ||
4380 | 1851 | // FONT_HERSHEY_SIMPLEX, 0.5, white); | ||
4381 | 1852 | |||
4382 | 1853 | int id = random_ids.at<uchar>(0,i++); | ||
4383 | 1854 | sprintf(vwstr,"s%d",id); | ||
4384 | 1855 | |||
4385 | 1856 | // putTextWithBackgroundCentered(white, wordmap, vwstr, p.pt, | ||
4386 | 1857 | // FONT_HERSHEY_DUPLEX, 0.5, black); | ||
4387 | 1858 | |||
4388 | 1859 | } | ||
4389 | 1860 | } | ||
4390 | 1861 | |||
4391 | 1862 | |||
4392 | 1863 | } | ||
4393 | 1864 | |||
4394 | 1865 | VLOG("WordMap", wordmap); | ||
4395 | 1866 | } | ||
4396 | 1867 | |||
4397 | 1868 | |||
4398 | 1869 | |||
4399 | 1870 | |||
4400 | 1871 | static int L1dist(Vec3b p1, Vec3b p2){ | ||
4401 | 1872 | return max(p1[0],p2[0])-min(p1[0],p2[0])+ | ||
4402 | 1873 | max(p1[1],p2[1])-min(p1[1],p2[1])+ | ||
4403 | 1874 | max(p1[2],p2[2])-min(p1[2],p2[2]); | ||
4404 | 1875 | } | ||
4405 | 1876 | |||
4406 | 1877 | |||
4407 | 1878 | |||
4408 | 1879 | bool | ||
4409 | 1880 | cvgui::areHorizontallyAligned(const vector<Rect>& rects){ | ||
4410 | 1881 | |||
4411 | 1882 | if (rects.size() <= 1) | ||
4412 | 1883 | return true; | ||
4413 | 1884 | |||
4414 | 1885 | vector<Rect> sorted_rects = rects; | ||
4415 | 1886 | sort(sorted_rects, sort_by_x); | ||
4416 | 1887 | |||
4417 | 1888 | int ymin = 10000; | ||
4418 | 1889 | int ymax = 0; | ||
4419 | 1890 | |||
4420 | 1891 | bool no_overlap = true; | ||
4421 | 1892 | for (vector<Rect>::const_iterator r = sorted_rects.begin() + 1; | ||
4422 | 1893 | r != sorted_rects.end(); ++r){ | ||
4423 | 1894 | |||
4424 | 1895 | no_overlap = no_overlap && (r->x >= (r-1)->x + (r-1)->width - 2); | ||
4425 | 1896 | |||
4426 | 1897 | int baseline = r->y + r->height; | ||
4427 | 1898 | ymin = min(baseline, ymin); | ||
4428 | 1899 | ymax = max(baseline, ymax); | ||
4429 | 1900 | } | ||
4430 | 1901 | |||
4431 | 1902 | bool baseline_aligned = (ymax - ymin < 10); | ||
4432 | 1903 | |||
4433 | 1904 | int minv = 10000; | ||
4434 | 1905 | int maxv = 0; | ||
4435 | 1906 | for (vector<Rect>::const_iterator r = sorted_rects.begin(); | ||
4436 | 1907 | r != sorted_rects.end(); ++r){ | ||
4437 | 1908 | |||
4438 | 1909 | int v = r->height; | ||
4439 | 1910 | minv = min(v, minv); | ||
4440 | 1911 | maxv = max(v, maxv); | ||
4441 | 1912 | } | ||
4442 | 1913 | |||
4443 | 1914 | bool height_similar = (maxv - minv < 10); | ||
4444 | 1915 | |||
4445 | 1916 | // if the difference between the highest and lowest baseline | ||
4446 | 1917 | // is too large, it means the rects are not alginged horizontally | ||
4447 | 1918 | |||
4448 | 1919 | return baseline_aligned && height_similar && no_overlap; | ||
4449 | 1920 | } | ||
4450 | 1921 | |||
4451 | 1922 | |||
4452 | 1923 | bool | ||
4453 | 1924 | cvgui::hasMoreThanNUniqueColors(const Mat& src, int n){ | ||
4454 | 1925 | |||
4455 | 1926 | |||
4456 | 1927 | Mat_<Vec3b>::const_iterator it = src.begin<Vec3b>(), | ||
4457 | 1928 | itEnd = src.end<Vec3b>(); | ||
4458 | 1929 | |||
4459 | 1930 | |||
4460 | 1931 | vector< pair<Vec3b,int> > colors; | ||
4461 | 1932 | //vector<int> counts; | ||
4462 | 1933 | colors.push_back( pair<Vec3b,int>(*it,1) ); | ||
4463 | 1934 | ++it; | ||
4464 | 1935 | |||
4465 | 1936 | for(; it != itEnd; ++it){ | ||
4466 | 1937 | |||
4467 | 1938 | bool matched; | ||
4468 | 1939 | matched = false; | ||
4469 | 1940 | for (vector< pair<Vec3b,int> >::iterator c = colors.begin(); | ||
4470 | 1941 | c != colors.end(); | ||
4471 | 1942 | ++c){ | ||
4472 | 1943 | |||
4473 | 1944 | Vec3b& color = (*c).first; | ||
4474 | 1945 | int& count = (*c).second; | ||
4475 | 1946 | |||
4476 | 1947 | int d = L1dist((*it), (color)); | ||
4477 | 1948 | //cout << d << endl; | ||
4478 | 1949 | if (d < 150){ | ||
4479 | 1950 | matched = true; | ||
4480 | 1951 | count++; | ||
4481 | 1952 | break; | ||
4482 | 1953 | } | ||
4483 | 1954 | } | ||
4484 | 1955 | |||
4485 | 1956 | if (!matched){ | ||
4486 | 1957 | |||
4487 | 1958 | // if (colors.size() == 4) | ||
4488 | 1959 | // return true; | ||
4489 | 1960 | // else | ||
4490 | 1961 | colors.push_back(pair<Vec3b,int>(*it,1)); | ||
4491 | 1962 | |||
4492 | 1963 | } | ||
4493 | 1964 | |||
4494 | 1965 | } | ||
4495 | 1966 | |||
4496 | 1967 | dout() << endl << endl; | ||
4497 | 1968 | for (vector< pair<Vec3b,int> >::iterator c = colors.begin(); | ||
4498 | 1969 | c != colors.end(); | ||
4499 | 1970 | ++c){ | ||
4500 | 1971 | |||
4501 | 1972 | Vec3b& color = (*c).first; | ||
4502 | 1973 | int& count = (*c).second; | ||
4503 | 1974 | //cout << count << endl; | ||
4504 | 1975 | } | ||
4505 | 1976 | |||
4506 | 1977 | return (colors.size() > 5); | ||
4507 | 1978 | } | ||
4508 | 1979 | |||
4509 | 1980 | |||
4510 | 1981 | void | ||
4511 | 1982 | cvgui::extractSmallRects(const Mat& src, | ||
4512 | 1983 | vector<Rect>& rects){ | ||
4513 | 1984 | |||
4514 | 1985 | Mat copy = src.clone(); | ||
4515 | 1986 | |||
4516 | 1987 | vector<vector<Point> > contours; | ||
4517 | 1988 | findContours(copy, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); | ||
4518 | 1989 | |||
4519 | 1990 | for (vector<vector<Point> >::iterator contour = contours.begin(); | ||
4520 | 1991 | contour != contours.end(); ++contour){ | ||
4521 | 1992 | |||
4522 | 1993 | Rect bound = boundingRect(Mat(*contour)); | ||
4523 | 1994 | rects.push_back(bound); | ||
4524 | 1995 | } | ||
4525 | 1996 | |||
4526 | 1997 | } | ||
4527 | 1998 | |||
4528 | 1999 | void | ||
4529 | 2000 | cvgui::calculateColor(vector<Blob>& blobs, | ||
4530 | 2001 | const Mat& color_image, | ||
4531 | 2002 | const Mat& foreground_mask){ | ||
4532 | 2003 | |||
4533 | 2004 | |||
4534 | 2005 | for (vector<Blob>::iterator it = blobs.begin(); | ||
4535 | 2006 | it != blobs.end(); ++it){ | ||
4536 | 2007 | |||
4537 | 2008 | Blob& blob = *it; | ||
4538 | 2009 | |||
4539 | 2010 | |||
4540 | 2011 | Mat part(color_image, blob); | ||
4541 | 2012 | Mat mask(foreground_mask, blob); | ||
4542 | 2013 | Scalar mean, stddev; | ||
4543 | 2014 | meanStdDev(part, mean, stddev, mask); | ||
4544 | 2015 | |||
4545 | 2016 | blob.mr = mean[0]; | ||
4546 | 2017 | blob.mg = mean[1]; | ||
4547 | 2018 | blob.mb = mean[2]; | ||
4548 | 2019 | |||
4549 | 2020 | } | ||
4550 | 2021 | |||
4551 | 2022 | } | ||
4552 | 2023 | |||
4553 | 2024 | |||
4554 | 2025 | void | ||
4555 | 2026 | cvgui::extractBlobs(const Mat& src, vector<Blob>& blobs){ | ||
4556 | 2027 | |||
4557 | 2028 | Mat copy = src.clone(); | ||
4558 | 2029 | blobs.clear(); | ||
4559 | 2030 | |||
4560 | 2031 | vector<vector<Point> > contours; | ||
4561 | 2032 | findContours(copy, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); | ||
4562 | 2033 | |||
4563 | 2034 | |||
4564 | 2035 | for (vector<vector<Point> >::iterator contour = contours.begin(); | ||
4565 | 2036 | contour != contours.end(); ++contour){ | ||
4566 | 2037 | |||
4567 | 2038 | |||
4568 | 2039 | double area = contourArea(Mat(*contour)); | ||
4569 | 2040 | |||
4570 | 2041 | Rect bound = boundingRect(Mat(*contour)); | ||
4571 | 2042 | |||
4572 | 2043 | |||
4573 | 2044 | |||
4574 | 2045 | |||
4575 | 2046 | Blob blob(bound); | ||
4576 | 2047 | blob.area = area; | ||
4577 | 2048 | blobs.push_back(blob); | ||
4578 | 2049 | |||
4579 | 2050 | } | ||
4580 | 2051 | |||
4581 | 2052 | |||
4582 | 2053 | |||
4583 | 2054 | |||
4584 | 2055 | |||
4585 | 2056 | } | ||
4586 | 2057 | |||
4587 | 2058 | |||
4588 | 2059 | void | ||
4589 | 2060 | cvgui::extractRects(const Mat& src, | ||
4590 | 2061 | vector<Rect>& rects){ | ||
4591 | 2062 | |||
4592 | 2063 | Mat copy = src.clone(); | ||
4593 | 2064 | rects.clear(); | ||
4594 | 2065 | |||
4595 | 2066 | |||
4596 | 2067 | vector<vector<Point> > contours; | ||
4597 | 2068 | findContours(copy, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); | ||
4598 | 2069 | |||
4599 | 2070 | |||
4600 | 2071 | for (vector<vector<Point> >::iterator contour = contours.begin(); | ||
4601 | 2072 | contour != contours.end(); ++contour){ | ||
4602 | 2073 | |||
4603 | 2074 | |||
4604 | 2075 | double area = contourArea(Mat(*contour)); | ||
4605 | 2076 | |||
4606 | 2077 | Rect bound = boundingRect(Mat(*contour)); | ||
4607 | 2078 | |||
4608 | 2079 | |||
4609 | 2080 | // too small | ||
4610 | 2081 | if (bound.width < 6 || bound.height < 6) | ||
4611 | 2082 | continue; | ||
4612 | 2083 | |||
4613 | 2084 | // too empty | ||
4614 | 2085 | if (bound.height > 100 && bound.width * bound.height * 0.50 > area) | ||
4615 | 2086 | continue; | ||
4616 | 2087 | |||
4617 | 2088 | rects.push_back(bound); | ||
4618 | 2089 | |||
4619 | 2090 | } | ||
4620 | 2091 | |||
4621 | 2092 | } | ||
4622 | 2093 | |||
4623 | 2094 | void | ||
4624 | 2095 | cvgui::findLongLines_Vertical(const Mat& src, Mat& dest, int min_length, int extension){ | ||
4625 | 2096 | dest = src.clone(); | ||
4626 | 2097 | |||
4627 | 2098 | Mat maskT, destT; | ||
4628 | 2099 | transpose(dest,destT); | ||
4629 | 2100 | cvgui::findLongLines_Horizontal(destT,maskT,min_length, extension); | ||
4630 | 2101 | |||
4631 | 2102 | Mat maskTT; | ||
4632 | 2103 | transpose(maskT,maskTT); | ||
4633 | 2104 | dest = maskTT; | ||
4634 | 2105 | } | ||
4635 | 2106 | |||
4636 | 2107 | |||
4637 | 2108 | void | ||
4638 | 2109 | cvgui::findLongLines(const Mat& src, Mat& dest, int min_length, int extension){ | ||
4639 | 2110 | |||
4640 | 2111 | Mat copy = src.clone(); | ||
4641 | 2112 | Mat v,h; | ||
4642 | 2113 | |||
4643 | 2114 | cvgui::findLongLines_Horizontal(copy, h, min_length, extension); | ||
4644 | 2115 | |||
4645 | 2116 | |||
4646 | 2117 | cvgui::findLongLines_Vertical(copy, v, min_length, extension); | ||
4647 | 2118 | |||
4648 | 2119 | // Mat maskT, destT; | ||
4649 | 2120 | // transpose(dest,destT); | ||
4650 | 2121 | // cvgui::findLongLines_Horizontal(destT,maskT,min_length, extension); | ||
4651 | 2122 | // | ||
4652 | 2123 | // Mat maskTT; | ||
4653 | 2124 | // transpose(maskT,maskTT); | ||
4654 | 2125 | |||
4655 | 2126 | |||
4656 | 2127 | bitwise_or(v,h,dest); | ||
4657 | 2128 | |||
4658 | 2129 | } | ||
4659 | 2130 | |||
4660 | 2131 | |||
4661 | 2132 | //void | ||
4662 | 2133 | //cvgui::filterLineSegments(const Mat& src, Mat& dest, | ||
4663 | 2134 | // int min_length, int max_length){ | ||
4664 | 2135 | // | ||
4665 | 2136 | // typedef uchar T; | ||
4666 | 2137 | // | ||
4667 | 2138 | // int extension = 5; | ||
4668 | 2139 | // | ||
4669 | 2140 | // dest = Mat::zeros(src.rows,src.cols,CV_8UC1); | ||
4670 | 2141 | // | ||
4671 | 2142 | // Size size = src.size(); | ||
4672 | 2143 | // for( int i = 0; i < size.height; i +=1 ){ | ||
4673 | 2144 | // | ||
4674 | 2145 | // const T* ptr1 = src.ptr<T>(i); | ||
4675 | 2146 | // T* ptr2 = dest.ptr<T>(i); | ||
4676 | 2147 | // | ||
4677 | 2148 | // bool has_previous_baseline = false; | ||
4678 | 2149 | // int previous_baseline_endpoint = 0; | ||
4679 | 2150 | // int current_baseline_startpoint = 0; | ||
4680 | 2151 | // | ||
4681 | 2152 | // | ||
4682 | 2153 | // for( int j = 1; j < size.width; j += 1 ){ | ||
4683 | 2154 | // | ||
4684 | 2155 | // | ||
4685 | 2156 | // if (ptr1[j] > 0 && ptr1[j-1] == 0){ | ||
4686 | 2157 | // current_baseline_startpoint = j; | ||
4687 | 2158 | // } | ||
4688 | 2159 | // | ||
4689 | 2160 | // if (ptr1[j-1] > 0 && (ptr1[j] == 0 || j == size.width - 1)){ | ||
4690 | 2161 | // | ||
4691 | 2162 | // | ||
4692 | 2163 | // // check for the condition of a baseline hypothesis | ||
4693 | 2164 | // // the length of the baseline must be > 15 | ||
4694 | 2165 | // if ((j - current_baseline_startpoint) > min_length){// || j == size.width - 1){ | ||
4695 | 2166 | // | ||
4696 | 2167 | // // int closeness_threshold = 1; | ||
4697 | 2168 | // // if (has_previous_baseline && | ||
4698 | 2169 | // // (current_baseline_startpoint - previous_baseline_endpoint) | ||
4699 | 2170 | // // <= closeness_threshold){ | ||
4700 | 2171 | // // | ||
4701 | 2172 | // // | ||
4702 | 2173 | // // // merge the current baseline with the previously baseline | ||
4703 | 2174 | // // for (int k=previous_baseline_endpoint; | ||
4704 | 2175 | // // k < current_baseline_startpoint; k += 1){ | ||
4705 | 2176 | // // ptr2[k] = ptr1[j]; | ||
4706 | 2177 | // // } | ||
4707 | 2178 | // // } | ||
4708 | 2179 | // | ||
4709 | 2180 | // // has_previous_baseline = true; | ||
4710 | 2181 | // //previous_baseline_endpoint = j; | ||
4711 | 2182 | // | ||
4712 | 2183 | // | ||
4713 | 2184 | // for (int k=current_baseline_startpoint; k < j; ++k){ | ||
4714 | 2185 | // ptr2[k] = 255; | ||
4715 | 2186 | // } | ||
4716 | 2187 | // | ||
4717 | 2188 | // for (int k=j; k < min(j+extension,size.width-1); ++k){ | ||
4718 | 2189 | // ptr2[k] = 255; | ||
4719 | 2190 | // } | ||
4720 | 2191 | // | ||
4721 | 2192 | // | ||
4722 | 2193 | // } | ||
4723 | 2194 | // | ||
4724 | 2195 | // // forming a new baseline hypothesis | ||
4725 | 2196 | // //current_baseline_startpoint = j+1; | ||
4726 | 2197 | // } | ||
4727 | 2198 | // } | ||
4728 | 2199 | // } | ||
4729 | 2200 | // | ||
4730 | 2201 | //} | ||
4731 | 2202 | |||
4732 | 2203 | |||
4733 | 2204 | void | ||
4734 | 2205 | cvgui::voteCenter_Vertical(const Mat& binary, Mat& dest, | ||
4735 | 2206 | int min_length, int tolerance, int distance){ | ||
4736 | 2207 | |||
4737 | 2208 | dest = binary.clone(); | ||
4738 | 2209 | |||
4739 | 2210 | Mat maskT, destT; | ||
4740 | 2211 | transpose(dest,destT); | ||
4741 | 2212 | cvgui::voteCenter_Horizontal(destT,maskT,min_length,tolerance,distance); | ||
4742 | 2213 | |||
4743 | 2214 | Mat maskTT; | ||
4744 | 2215 | transpose(maskT,maskTT); | ||
4745 | 2216 | dest = maskTT; | ||
4746 | 2217 | } | ||
4747 | 2218 | |||
4748 | 2219 | void | ||
4749 | 2220 | cvgui::voteCenter_Horizontal(const Mat& binary, Mat& dest, | ||
4750 | 2221 | int min_length, int tolerance, int distance){ | ||
4751 | 2222 | |||
4752 | 2223 | typedef uchar T; | ||
4753 | 2224 | |||
4754 | 2225 | dest = Mat::zeros(binary.rows,binary.cols,CV_8UC1); | ||
4755 | 2226 | |||
4756 | 2227 | Size size = binary.size(); | ||
4757 | 2228 | for( int i = 0; i < size.height; i +=1 ){ | ||
4758 | 2229 | |||
4759 | 2230 | const T* ptr1 = binary.ptr<T>(i); | ||
4760 | 2231 | T* ptr2 = 0; | ||
4761 | 2232 | //dest.ptr<T>(i); | ||
4762 | 2233 | // | ||
4763 | 2234 | // | ||
4764 | 2235 | // T* ptru = 0; | ||
4765 | 2236 | // T* ptrb = 0; | ||
4766 | 2237 | // | ||
4767 | 2238 | int grid = 5; | ||
4768 | 2239 | |||
4769 | 2240 | |||
4770 | 2241 | int gi = grid*(i+distance)/grid; | ||
4771 | 2242 | |||
4772 | 2243 | if (gi >= 0 && gi < size.height){ | ||
4773 | 2244 | ptr2 = dest.ptr<T>(i+distance); | ||
4774 | 2245 | } | ||
4775 | 2246 | |||
4776 | 2247 | // if (grid*(i+distance)/grid<size.height){ | ||
4777 | 2248 | // ptrb = dest.ptr<T>(i+distance); | ||
4778 | 2249 | // } | ||
4779 | 2250 | |||
4780 | 2251 | bool has_previous_baseline = false; | ||
4781 | 2252 | int previous_baseline_endpoint = 0; | ||
4782 | 2253 | int current_baseline_startpoint = 0; | ||
4783 | 2254 | |||
4784 | 2255 | |||
4785 | 2256 | for( int j = 1; j < size.width; j += 1 ){ | ||
4786 | 2257 | |||
4787 | 2258 | |||
4788 | 2259 | if (ptr1[j] > 0 && ptr1[j-1] == 0){ | ||
4789 | 2260 | current_baseline_startpoint = j; | ||
4790 | 2261 | } | ||
4791 | 2262 | |||
4792 | 2263 | if (ptr1[j-1] > 0 && (ptr1[j] == 0 || j == size.width - 1)){ | ||
4793 | 2264 | |||
4794 | 2265 | |||
4795 | 2266 | // check for the condition of a baseline hypothesis | ||
4796 | 2267 | // the length of the baseline must be > 15 | ||
4797 | 2268 | if ((j - current_baseline_startpoint) > min_length){// || j == size.width - 1){ | ||
4798 | 2269 | |||
4799 | 2270 | |||
4800 | 2271 | |||
4801 | 2272 | for (int k=current_baseline_startpoint+min_length/2; k < j-min_length/2; ++k){ | ||
4802 | 2273 | |||
4803 | 2274 | if (ptr2) | ||
4804 | 2275 | ptr2[k] = 255; | ||
4805 | 2276 | } | ||
4806 | 2277 | |||
4807 | 2278 | for (int k=j-min_length/2; k < min(j-min_length/2+tolerance,size.width-1); ++k){ | ||
4808 | 2279 | |||
4809 | 2280 | if (ptr2) | ||
4810 | 2281 | ptr2[k] = 255; | ||
4811 | 2282 | |||
4812 | 2283 | } | ||
4813 | 2284 | |||
4814 | 2285 | |||
4815 | 2286 | } | ||
4816 | 2287 | |||
4817 | 2288 | // forming a new baseline hypothesis | ||
4818 | 2289 | //current_baseline_startpoint = j+1; | ||
4819 | 2290 | } | ||
4820 | 2291 | } | ||
4821 | 2292 | } | ||
4822 | 2293 | |||
4823 | 2294 | } | ||
4824 | 2295 | |||
4825 | 2296 | void | ||
4826 | 2297 | cvgui::findLongLines_Horizontal(const Mat& binary, Mat& dest, | ||
4827 | 2298 | int min_length, int extension){ | ||
4828 | 2299 | |||
4829 | 2300 | typedef uchar T; | ||
4830 | 2301 | |||
4831 | 2302 | dest = Mat::zeros(binary.rows,binary.cols,CV_8UC1); | ||
4832 | 2303 | |||
4833 | 2304 | Size size = binary.size(); | ||
4834 | 2305 | for( int i = 0; i < size.height; i +=1 ){ | ||
4835 | 2306 | |||
4836 | 2307 | const T* ptr1 = binary.ptr<T>(i); | ||
4837 | 2308 | T* ptr2 = dest.ptr<T>(i); | ||
4838 | 2309 | |||
4839 | 2310 | bool has_previous_baseline = false; | ||
4840 | 2311 | int previous_baseline_endpoint = 0; | ||
4841 | 2312 | int current_baseline_startpoint = 0; | ||
4842 | 2313 | |||
4843 | 2314 | |||
4844 | 2315 | |||
4845 | 2316 | |||
4846 | 2317 | for( int j = 1; j < size.width; j += 1 ){ | ||
4847 | 2318 | |||
4848 | 2319 | |||
4849 | 2320 | if (ptr1[j] > 0 && ptr1[j-1] == 0){ | ||
4850 | 2321 | current_baseline_startpoint = j; | ||
4851 | 2322 | } | ||
4852 | 2323 | |||
4853 | 2324 | if (ptr1[j-1] > 0 && (ptr1[j] == 0 || j == size.width - 1)){ | ||
4854 | 2325 | |||
4855 | 2326 | |||
4856 | 2327 | // check for the condition of a baseline hypothesis | ||
4857 | 2328 | // the length of the baseline must be > 15 | ||
4858 | 2329 | if ((j - current_baseline_startpoint) > min_length){// || j == size.width - 1){ | ||
4859 | 2330 | |||
4860 | 2331 | // int closeness_threshold = 1; | ||
4861 | 2332 | // if (has_previous_baseline && | ||
4862 | 2333 | // (current_baseline_startpoint - previous_baseline_endpoint) | ||
4863 | 2334 | // <= closeness_threshold){ | ||
4864 | 2335 | // | ||
4865 | 2336 | // | ||
4866 | 2337 | // // merge the current baseline with the previously baseline | ||
4867 | 2338 | // for (int k=previous_baseline_endpoint; | ||
4868 | 2339 | // k < current_baseline_startpoint; k += 1){ | ||
4869 | 2340 | // ptr2[k] = ptr1[j]; | ||
4870 | 2341 | // } | ||
4871 | 2342 | // } | ||
4872 | 2343 | |||
4873 | 2344 | // has_previous_baseline = true; | ||
4874 | 2345 | //previous_baseline_endpoint = j; | ||
4875 | 2346 | |||
4876 | 2347 | |||
4877 | 2348 | for (int k=current_baseline_startpoint; k < j; ++k){ | ||
4878 | 2349 | ptr2[k] = 255; | ||
4879 | 2350 | } | ||
4880 | 2351 | |||
4881 | 2352 | for (int k=j; k < min(j+extension,size.width-1); ++k){ | ||
4882 | 2353 | ptr2[k] = 255; | ||
4883 | 2354 | } | ||
4884 | 2355 | |||
4885 | 2356 | |||
4886 | 2357 | } | ||
4887 | 2358 | |||
4888 | 2359 | // forming a new baseline hypothesis | ||
4889 | 2360 | //current_baseline_startpoint = j+1; | ||
4890 | 2361 | } | ||
4891 | 2362 | } | ||
4892 | 2363 | } | ||
4893 | 2364 | } | ||
4894 | 2365 | |||
4895 | 2366 | |||
4896 | 2367 | Mat | ||
4897 | 2368 | cvgui::obtainGrayBackgroundMask(const Mat& input){ | ||
4898 | 2369 | |||
4899 | 2370 | Mat copy = input.clone(); | ||
4900 | 2371 | |||
4901 | 2372 | Mat_<Vec3b>::iterator it = copy.begin<Vec3b>(), | ||
4902 | 2373 | itEnd = copy.end<Vec3b>(); | ||
4903 | 2374 | for(; it != itEnd; ++it){ | ||
4904 | 2375 | |||
4905 | 2376 | uchar& b = (*it)[0]; | ||
4906 | 2377 | uchar& g = (*it)[1]; | ||
4907 | 2378 | uchar& r = (*it)[2]; | ||
4908 | 2379 | |||
4909 | 2380 | if (r == 0 && b == 0 && g == 0){ | ||
4910 | 2381 | r = 1; b = 1; g = 1; | ||
4911 | 2382 | } | ||
4912 | 2383 | |||
4913 | 2384 | if (b > 50 && | ||
4914 | 2385 | abs(b-g) < 10 && abs(g-b) < 10 && abs(b-r) < 10){ | ||
4915 | 2386 | r = 0; | ||
4916 | 2387 | g = 0; | ||
4917 | 2388 | b = 0; | ||
4918 | 2389 | } | ||
4919 | 2390 | |||
4920 | 2391 | |||
4921 | 2392 | |||
4922 | 2393 | } | ||
4923 | 2394 | |||
4924 | 2395 | |||
4925 | 2396 | Mat ms[3]; | ||
4926 | 2397 | split(copy, ms); | ||
4927 | 2398 | |||
4928 | 2399 | Mat mask; | ||
4929 | 2400 | threshold(ms[0],mask,0,255,THRESH_BINARY); | ||
4930 | 2401 | |||
4931 | 2402 | dilate(mask,mask,Mat()); | ||
4932 | 2403 | |||
4933 | 2404 | return mask; | ||
4934 | 2405 | } | ||
4935 | 2406 | |||
4936 | 2407 | |||
4937 | 2408 | Mat | ||
4938 | 2409 | cvgui::removeGrayBackground(const Mat& input){ | ||
4939 | 2410 | |||
4940 | 2411 | // Mat copy = input.clone(); | ||
4941 | 2412 | // Mat mask; | ||
4942 | 2413 | // // (Size(copy.rows,copy.cols), CV_8UC1); | ||
4943 | 2414 | // | ||
4944 | 2415 | // Mat_<Vec3b>::iterator it = copy.begin<Vec3b>(), | ||
4945 | 2416 | // itEnd = copy.end<Vec3b>(); | ||
4946 | 2417 | // for(; it != itEnd; ++it){ | ||
4947 | 2418 | // | ||
4948 | 2419 | // uchar& b = (*it)[0]; | ||
4949 | 2420 | // uchar& g = (*it)[1]; | ||
4950 | 2421 | // uchar& r = (*it)[2]; | ||
4951 | 2422 | // | ||
4952 | 2423 | // if (r == 0 && b == 0 && g == 0){ | ||
4953 | 2424 | // r = 1; b = 1; g = 1; | ||
4954 | 2425 | // } | ||
4955 | 2426 | // | ||
4956 | 2427 | // if (b > 50 && | ||
4957 | 2428 | // abs(b-g) < 10 && abs(g-b) < 10 && abs(b-r) < 10){ | ||
4958 | 2429 | // r = 0; | ||
4959 | 2430 | // g = 0; | ||
4960 | 2431 | // b = 0; | ||
4961 | 2432 | // } | ||
4962 | 2433 | // | ||
4963 | 2434 | // | ||
4964 | 2435 | // | ||
4965 | 2436 | // } | ||
4966 | 2437 | // | ||
4967 | 2438 | // | ||
4968 | 2439 | // Mat ms[3]; | ||
4969 | 2440 | // split(copy, ms); | ||
4970 | 2441 | // | ||
4971 | 2442 | // //threshold(ms[0],mask,0,255,THRESH_BINARY_INV); | ||
4972 | 2443 | // threshold(ms[0],mask,0,255,THRESH_BINARY); | ||
4973 | 2444 | // | ||
4974 | 2445 | // dilate(mask,mask,Mat()); | ||
4975 | 2446 | // | ||
4976 | 2447 | // | ||
4977 | 2448 | // vector<vector<Point> > contours; | ||
4978 | 2449 | // findContours(ms[0], contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); | ||
4979 | 2450 | // | ||
4980 | 2451 | // Scalar red(0,0,255); | ||
4981 | 2452 | // //drawContours(copy, contours, -1, red); | ||
4982 | 2453 | // | ||
4983 | 2454 | // | ||
4984 | 2455 | // vector<Rect> boundingRects; | ||
4985 | 2456 | // | ||
4986 | 2457 | // for (vector<vector<Point> >::iterator contour = contours.begin(); | ||
4987 | 2458 | // contour != contours.end(); ++contour){ | ||
4988 | 2459 | // | ||
4989 | 2460 | // | ||
4990 | 2461 | // double area = contourArea(Mat(*contour)); | ||
4991 | 2462 | // | ||
4992 | 2463 | // Rect bound = boundingRect(Mat(*contour)); | ||
4993 | 2464 | // | ||
4994 | 2465 | // | ||
4995 | 2466 | // if (bound.width * bound.height * 0.5 > area) | ||
4996 | 2467 | // continue; | ||
4997 | 2468 | // | ||
4998 | 2469 | // boundingRects.push_back(bound); | ||
4999 | 2470 | // | ||
5000 | 2471 | // rectangle(copy, |
The diff has been truncated for viewing.
Thanks. Uploaded.