├── .gitignore ├── CHANGELOG.md ├── CMakeLists.txt ├── DEPENDENCIES.md ├── LICENSE.GPL ├── README.md ├── applications ├── imago_console │ ├── CMakeLists.txt │ └── src │ │ ├── learning_context.h │ │ ├── machine_learning.cpp │ │ ├── machine_learning.h │ │ ├── main.cpp │ │ ├── recognition_helpers.cpp │ │ ├── recognition_helpers.h │ │ ├── similarity_tools.cpp │ │ └── similarity_tools.h └── imago_gui │ ├── CMakeLists.txt │ ├── build.xml │ ├── resources │ ├── document-open.png │ ├── document-save.png │ ├── edit-copy.png │ ├── edit-find-replace.png │ ├── edit-undo.png │ ├── gga-logo.png │ ├── go-first.png │ ├── go-last.png │ ├── go-next.png │ ├── go-previous.png │ ├── imago-icon.ico │ ├── imago-icon.png │ ├── list-add.png │ ├── list-remove.png │ ├── splash.bmp │ ├── splash.png │ └── start-here.png │ └── src │ └── com │ └── ggasoftware │ ├── DocumentHandling │ ├── Document.java │ ├── DocumentPanel.java │ ├── ImageDocument.java │ ├── PdfDocument.java │ └── TiffDocument.java │ ├── Ego.java │ ├── EgoForm.java │ ├── EgoFrame.java │ ├── FormBuilder.java │ ├── ImagePanel.java │ ├── MenuBuilder.java │ ├── MessageBox.java │ ├── MoleculePanel.java │ ├── MoleculeSelection.java │ ├── OpenSketcherDialog.java │ ├── Utils.java │ └── WaitingPanel.java ├── bindings ├── c │ ├── CMakeLists.txt │ ├── src │ │ ├── imago_c.cpp │ │ ├── imago_c.h │ │ ├── imago_version.h.in │ │ ├── recognition_context.cpp │ │ ├── recognition_context.h │ │ ├── session_manager.cpp │ │ └── session_manager.h │ └── test │ │ ├── imago_c_test.c │ │ └── indigo_compare_molecules.c └── java │ ├── build.xml │ └── src │ └── com │ └── ggasoftware │ └── imago │ ├── Imago.java │ ├── ImagoException.java │ └── ImagoLib.java ├── cmake ├── Boost.cmake ├── BuildOptions.cmake ├── BuildOptionsLinux.cmake ├── BuildOptionsMac.cmake ├── BuildOptionsWin.cmake ├── GetSystemVersion.cmake ├── Indigo.cmake └── OpenCV.cmake ├── examples ├── 0000041_rnd.mol ├── 0000041_rnd.png ├── 0000191_rnd.mol ├── 0000191_rnd.png ├── 0000230_rnd.mol ├── 0000230_rnd.png ├── 0000415_rnd.mol ├── 0000415_rnd.png ├── 0000603_rnd.mol ├── 0000603_rnd.png ├── 0000931_rnd.mol ├── 0000931_rnd.png ├── 0001018_rnd.mol ├── 0001018_rnd.png ├── 0001608_rnd.mol ├── 0001608_rnd.png ├── 0002057_rnd.mol ├── 0002057_rnd.png ├── 0002708_rnd.mol └── 0002708_rnd.png ├── imago-version.cmake ├── imago ├── CMakeLists.txt └── src │ ├── algebra.cpp │ ├── algebra.h │ ├── approximator.cpp │ ├── approximator.h │ ├── basic_2d_storage.h │ ├── character_recognizer.cpp │ ├── character_recognizer.h │ ├── chemical_structure_recognizer.cpp │ ├── chemical_structure_recognizer.h │ ├── chemical_validity.cpp │ ├── chemical_validity.h │ ├── comdef.h │ ├── complex_contour.cpp │ ├── complex_contour.h │ ├── complex_number.cpp │ ├── complex_number.h │ ├── dirent.h │ ├── double_bond_maker.cpp │ ├── double_bond_maker.h │ ├── exception.h │ ├── failsafe_png.cpp │ ├── failsafe_png.h │ ├── file_helpers.cpp │ ├── file_helpers.h │ ├── filters_list.cpp │ ├── filters_list.h │ ├── font.inc │ ├── fonts_list.cpp │ ├── fonts_list.h │ ├── graph_extractor.cpp │ ├── graph_extractor.h │ ├── graphics_detector.cpp │ ├── graphics_detector.h │ ├── image.cpp │ ├── image.h │ ├── image_draw_utils.cpp │ ├── image_draw_utils.h │ ├── image_utils.cpp │ ├── image_utils.h │ ├── label_combiner.cpp │ ├── label_combiner.h │ ├── label_logic.cpp │ ├── label_logic.h │ ├── line_priority_queue.h │ ├── log_ext.cpp │ ├── log_ext.h │ ├── molecule.cpp │ ├── molecule.h │ ├── molfile_saver.cpp │ ├── molfile_saver.h │ ├── multiple_bond_checker.cpp │ ├── multiple_bond_checker.h │ ├── output.cpp │ ├── output.h │ ├── periodic_table.cpp │ ├── periodic_table.h │ ├── pixel_boundings.cpp │ ├── pixel_boundings.h │ ├── platform_tools.cpp │ ├── platform_tools.h │ ├── prefilter_basic.cpp │ ├── prefilter_basic.h │ ├── prefilter_entry.cpp │ ├── prefilter_entry.h │ ├── prefilter_retinex.cpp │ ├── prefilter_retinex.h │ ├── probability_separator.cpp │ ├── probability_separator.h │ ├── recognition_distance.cpp │ ├── recognition_distance.h │ ├── recognition_tree.cpp │ ├── recognition_tree.h │ ├── rectangle.cpp │ ├── rectangle.h │ ├── reference_object.h │ ├── rng_builder.h │ ├── scanner.cpp │ ├── scanner.h │ ├── segment.cpp │ ├── segment.h │ ├── segment_tools.cpp │ ├── segment_tools.h │ ├── segmentator.cpp │ ├── segmentator.h │ ├── segments_graph.cpp │ ├── segments_graph.h │ ├── separator.cpp │ ├── separator.h │ ├── settings.cpp │ ├── settings.h │ ├── settings_defaults.inc │ ├── skeleton.cpp │ ├── skeleton.h │ ├── stat_utils.h │ ├── stl_fwd.h │ ├── superatom.cpp │ ├── superatom.h │ ├── superatom_expansion.cpp │ ├── superatom_expansion.h │ ├── thin_filter2.cpp │ ├── thin_filter2.h │ ├── triple_bond_maker.cpp │ ├── triple_bond_maker.h │ ├── vec2d.h │ ├── virtual_fs.cpp │ ├── virtual_fs.h │ ├── weak_segmentator.cpp │ ├── weak_segmentator.h │ ├── wedge_bond_extractor.cpp │ └── wedge_bond_extractor.h └── tools └── compare-versions ├── html ├── colorbox.css ├── images │ ├── border.png │ ├── controls.png │ ├── ie6 │ │ ├── borderBottomCenter.png │ │ ├── borderBottomLeft.png │ │ ├── borderBottomRight.png │ │ ├── borderMiddleLeft.png │ │ ├── borderMiddleRight.png │ │ ├── borderTopCenter.png │ │ ├── borderTopLeft.png │ │ └── borderTopRight.png │ ├── loading.gif │ ├── loading_background.png │ └── overlay.png ├── jquery-ui.custom.min.js ├── jquery.colorbox.js ├── jquery.min.js ├── redmond │ ├── images │ │ ├── ui-bg_flat_0_aaaaaa_40x100.png │ │ ├── ui-bg_flat_55_fbec88_40x100.png │ │ ├── ui-bg_glass_75_d0e5f5_1x400.png │ │ ├── ui-bg_glass_85_dfeffc_1x400.png │ │ ├── ui-bg_glass_95_fef1ec_1x400.png │ │ ├── ui-bg_gloss-wave_55_5c9ccc_500x100.png │ │ ├── ui-bg_inset-hard_100_f5f8f9_1x100.png │ │ ├── ui-bg_inset-hard_100_fcfdfd_1x100.png │ │ ├── ui-icons_217bc0_256x240.png │ │ ├── ui-icons_2e83ff_256x240.png │ │ ├── ui-icons_469bdd_256x240.png │ │ ├── ui-icons_6da8d5_256x240.png │ │ ├── ui-icons_cd0a0a_256x240.png │ │ ├── ui-icons_d8e7f3_256x240.png │ │ └── ui-icons_f9bd01_256x240.png │ └── jquery-ui-1.8.24.custom.css ├── spinner.gif └── style.css ├── images └── readme.txt ├── indigo └── readme.txt ├── run.py ├── template.html └── versions └── readme.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /third_party 3 | /dist -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Imago OCR 2.0 2 | ---------------------------- 3 | 4 | *22 February 2013* 5 | 6 | * Recognition quality: 7 | * Added adaptive preliminary filters designed for recognition of low-quality scans or even photos; 8 | * Recognition rate is significantly improved due to usage of highly-adaptive methods instead of strict criterias; 9 | * Restriction constants and recognition parameters are moved into configurable clusters, so the better recognition rate can be achieved on various non-typical image sets using machine learning approach; 10 | * Machine learning tool is embedded in [console application](/opensource/imago/imago_console), added ability to quickly check recognition rate on specified collection; 11 | * Chemical features: 12 | * Chemical feature set is extended: bridged bonds, query features, R-groups are handled properly; 13 | * Superatom labels validation logic introduced which greatly increases recognition probability of complex superatom labels; 14 | * Abbreviation expansion support added; 15 | * Improved interoperability: 16 | * Added support of various popular image formats: `JPG`, `BMP`, `DIB`, `TIFF`, `PBM`, `RAS` and others; 17 | * Implemented the new logging system which produces nice human-readable reports; 18 | * Replaced characters recognition system, the new one supports user-defined fonts; 19 | * Updated API and [Java](/opensource/imago/java) / [C](/opensource/imago/c) wrappers; 20 | * Updated build system, reduced dependencies list; 21 | * Fixed a lot of bugs, overall stability is significantly improved, decreased memory consumption. 22 | 23 | Imago OCR 1.0 24 | ----------------------- 25 | 26 | *28 March 2011* 27 | 28 | * Recognizable Molecule Features 29 | * Single, double, triple bonds; 30 | * Atom labels, subscripts, isotopes, charges; 31 | * Superatoms; 32 | * Rings; 33 | * Stereochemistry (up- and down-bonds); 34 | * Supported PNG image format; 35 | * Implemented characters recognition system based on Fourier Descriptors; 36 | * Java and C wrappers introduced; 37 | * Ego, a Java GUI application introduced 38 | * Improved techniques are used for molecular graph extraction. 39 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.6) 2 | 3 | project(Imago) 4 | 5 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/) 6 | 7 | set(IMAGO_LIBS_LOCATION $ENV{IMAGO_LIBS_LOCATION}) 8 | if (NOT IMAGO_LIBS_LOCATION) 9 | set(LIBS_LOCATION "http://ggasoftware.com/downloads/repo/" CACHE STRING "URL to directory with imago third party libs") 10 | else() 11 | set(LIBS_LOCATION ${IMAGO_LIBS_LOCATION} CACHE STRING "URL to directory with imago third party libs") 12 | endif() 13 | message(STATUS ${LIBS_LOCATION}) 14 | 15 | include(GetSystemVersion) 16 | include(BuildOptions) 17 | include(imago-version.cmake) 18 | 19 | message(STATUS "Subsystem: ${SUBSYSTEM_NAME}") 20 | 21 | INCLUDE(CTest) 22 | 23 | add_subdirectory(imago) 24 | add_subdirectory(applications/imago_console) 25 | add_subdirectory(bindings/c) 26 | 27 | set(CPACK_ARCHIVE_COMPONENT_INSTALL 1) 28 | 29 | SET(CPACK_COMPONENTS_ALL shared console static) 30 | 31 | SET(CPACK_GENERATOR "ZIP") 32 | SET(CPACK_PACKAGE_FILE_NAME "imago-${IMAGO_VERSION}-${PACKAGE_SUFFIX}") 33 | 34 | SET(CMAKE_INSTALL_PREFIX ${Imago_SOURCE_DIR}/dist) 35 | 36 | INCLUDE(CPack) 37 | -------------------------------------------------------------------------------- /DEPENDENCIES.md: -------------------------------------------------------------------------------- 1 | ## Third-party modules used in the Imago core library ## 2 | ### Boost ### 3 | [http://www.boost.org]() 4 | 5 | License: [Boost Software License](http://www.boost.org/users/license.html) 6 | 7 | ### OpenCV ### 8 | [http://opencv.org]() 9 | 10 | License: BSD license 11 | 12 | ### picoPNG ### 13 | This module is used in the core Imago library for PNG image loading and was modified to support fail-safe image loading when some minor parts are corrupted. 14 | 15 | License: 16 | > picoPNG version 20101224 17 | > Copyright (c) 2005-2010 Lode Vandevenne 18 | > 19 | > This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. 20 | > 21 | > Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 22 | > 23 | > 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 24 | > 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 25 | > 3. This notice may not be removed or altered from any source distribution. 26 | 27 | ## Third-party modules for Java applications ## 28 | ### JNA ### 29 | For Java bindings JNA library is used: [http://jna.java.net/]() 30 | 31 | License: GNU LGPL Version 2.1 32 | 33 | ### Java Advanced Imaging (JAI) API ### 34 | JAI is used in the Imago OCR Visual Tool. 35 | 36 | [http://java.net/projects/jai]() 37 | 38 | Part of Java SE SDK. 39 | 40 | ### PDFRenderer ### 41 | [http://java.net/projects/pdf-renderer]() 42 | 43 | License: GNU LGPL Version 2.1 44 | 45 | ### Launch4j ### 46 | [http://launch4j.sourceforge.net]() 47 | 48 | Launch4j is used for wrapping Imago OCR Visual Tool into executable files on Windows and Mac OS X 49 | 50 | License: 51 | > This program is free software licensed under the BSD license, the head subproject (the code which is attached to the wrapped jars) is licensed under the MIT license. Launch4j may be used for wrapping closed source, commercial applications. 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/README.md -------------------------------------------------------------------------------- /applications/imago_console/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(ImagoConsole) 2 | 3 | file(GLOB SRC src/*.cpp) 4 | file(GLOB HEADERS "src/*.h") 5 | 6 | list(APPEND SRC ${HEADERS}) 7 | 8 | include_directories(${ImagoLib_SOURCE_DIR}/src) 9 | 10 | add_executable(imago_console ${SRC}) 11 | 12 | if(UNIX AND NOT APPLE) 13 | find_package(Freetype REQUIRED) 14 | target_link_libraries(imago_console freetype fontconfig) 15 | endif() 16 | 17 | target_link_libraries(imago_console imago) 18 | 19 | INSTALL(TARGETS imago_console DESTINATION . COMPONENT console) 20 | 21 | # Add test to evaluate images from the examples directory 22 | add_test(imago_console_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/imago_console "-test" "${Imago_SOURCE_DIR}/examples") 23 | set_tests_properties (imago_console_test PROPERTIES PASS_REGULAR_EXPRESSION "Result: 10 vaild, 10 ok, 100 average score") 24 | -------------------------------------------------------------------------------- /applications/imago_console/src/learning_context.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | 17 | #ifndef _learning_context_h 18 | #define _learning_context_h 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | struct LearningContext 25 | { 26 | bool valid; 27 | 28 | double similarity; 29 | //std::string vars; 30 | 31 | double best_similarity_achieved; 32 | //std::string best_vars; 33 | 34 | std::string reference_file; 35 | std::string output_file; 36 | 37 | double stability; 38 | double score_stability; 39 | 40 | double time; 41 | double average_time; 42 | 43 | int attempts; 44 | 45 | LearningContext() 46 | { 47 | valid = false; 48 | similarity = best_similarity_achieved = 0.0; 49 | score_stability = stability = 1.0; 50 | time = average_time = 0.0; 51 | attempts = 0; 52 | } 53 | }; 54 | 55 | typedef std::map LearningBase; 56 | 57 | struct LearningResultRecord 58 | { 59 | std::string config; 60 | double average_time; 61 | double average_score; 62 | int ok_count; 63 | int valid_count; 64 | int work_iteration; 65 | 66 | bool operator<(const LearningResultRecord& second) const 67 | { 68 | return ok_count < second.ok_count || 69 | (ok_count == second.ok_count && 70 | average_score < second.average_score); 71 | } 72 | 73 | LearningResultRecord() 74 | { 75 | average_time = average_score = 0.0; 76 | work_iteration = ok_count = valid_count = 0; 77 | } 78 | }; 79 | 80 | typedef std::vector LearningHistory; 81 | 82 | #endif // _learning_context_h 83 | -------------------------------------------------------------------------------- /applications/imago_console/src/machine_learning.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | 17 | #ifndef _machine_learning_h 18 | #define _machine_learning_h 19 | 20 | #include 21 | #include "learning_context.h" 22 | #include "file_helpers.h" 23 | #include "settings.h" 24 | 25 | namespace machine_learning 26 | { 27 | double getWorstAllowedDelta(int imagesCount = 0); 28 | std::string modifyConfig(const std::string& config, const LearningBase& learning, int iteration); 29 | void runSingleItem(LearningContext& ctx, LearningResultRecord& res, const std::string& image_name, int timelimit_value, bool init = false); 30 | bool updateResult(LearningResultRecord& result_record, LearningHistory& history); 31 | bool storeConfig(const LearningResultRecord& res, const std::string& prefix = ""); 32 | bool readLearningProgress(LearningBase& base, LearningHistory& history, bool quiet = false, const std::string& filename = "learning_progress.dat"); 33 | bool storeLearningProgress(const LearningBase& base, const LearningHistory& history, const std::string& filename = "learning_progress.dat"); 34 | int performMachineLearning(imago::Settings& vars, const strings& imageSet, const std::string& configName, bool test_mode = false); 35 | } 36 | 37 | #endif -------------------------------------------------------------------------------- /applications/imago_console/src/recognition_helpers.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | 17 | #ifndef _recognition_helpers_h 18 | #define _recognition_helpers_h 19 | 20 | #include 21 | #include "virtual_fs.h" 22 | #include "settings.h" 23 | #include "image.h" 24 | 25 | namespace recognition_helpers 26 | { 27 | void dumpVFS(imago::VirtualFS& vfs, const std::string& filename); 28 | void applyConfig(bool verbose, imago::Settings& vars, const std::string& config); 29 | 30 | struct RecognitionResult 31 | { 32 | std::string molecule; 33 | int warnings; 34 | }; 35 | 36 | RecognitionResult recognizeImage(bool verbose, imago::Settings& vars, const imago::Image& src, 37 | const std::string& config); 38 | 39 | int performFilterTest(imago::Settings& vars, const std::string& imageName); 40 | 41 | int performFileAction(bool verbose, imago::Settings& vars, const std::string& imageName, 42 | const std::string& configName, const std::string& outputName = "molecule.mol"); 43 | 44 | } 45 | 46 | #endif -------------------------------------------------------------------------------- /applications/imago_console/src/similarity_tools.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #include "similarity_tools.h" 16 | 17 | #include "exception.h" 18 | #include "platform_tools.h" 19 | 20 | #include "indigo.h" 21 | 22 | namespace similarity_tools 23 | { 24 | 25 | std::string similarity_tool_exe = ""; 26 | std::string similarity_tool_param = ""; 27 | 28 | void setExternalSimilarityTool(const std::string& tool, const std::string& param) 29 | { 30 | similarity_tool_exe = tool; 31 | similarity_tool_param = param; 32 | } 33 | 34 | std::string quote(const std::string input) 35 | { 36 | std::string result = input; 37 | if (!result.empty() && result[0] != '\"') 38 | result = '\"' + result + '\"'; 39 | return result; 40 | } 41 | 42 | double getSimilarity(const LearningContext& ctx) 43 | { 44 | double result = 0.0; 45 | if (!similarity_tool_exe.empty()) 46 | { 47 | std::string params = quote(ctx.output_file) + " " + quote(ctx.reference_file); 48 | if (!similarity_tool_param.empty()) 49 | { 50 | params = quote(similarity_tool_param) + " " + params; 51 | } 52 | int retVal = platform::CALL(similarity_tool_exe, params); 53 | if (retVal >= 0 && retVal <= 100) 54 | return retVal; 55 | else 56 | throw imago::FileNotFoundException("Failed to call similarity tool " 57 | + similarity_tool_exe + " (" + imago::ImagoException::str(retVal) + ")"); 58 | } 59 | else 60 | { 61 | int outm = indigoLoadMoleculeFromFile(ctx.output_file.c_str()); 62 | if (outm == -1) 63 | { 64 | indigoFreeAllObjects(); 65 | throw imago::IOException("Failed to load " + ctx.output_file + ":" + indigoGetLastError()); 66 | } 67 | int refm = indigoLoadMoleculeFromFile(ctx.reference_file.c_str()); 68 | if (refm == -1) 69 | { 70 | indigoFreeAllObjects(); 71 | throw imago::IOException("Failed to load " + ctx.reference_file + ":" + indigoGetLastError()); 72 | } 73 | 74 | indigoNormalize(refm, ""); 75 | indigoNormalize(outm, ""); 76 | 77 | float sim1 = indigoSimilarity(refm, outm, "normalized-edit"); 78 | indigoAromatize(refm); 79 | indigoAromatize(outm); 80 | 81 | float sim2 = indigoSimilarity(refm, outm, "normalized-edit"); 82 | 83 | result = 100.0 * std::max(sim1, sim2); 84 | 85 | // Clear all the objects used by Indigo 86 | indigoFreeAllObjects(); 87 | } 88 | 89 | return result; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /applications/imago_console/src/similarity_tools.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | 17 | #ifndef _similarity_tools_h 18 | #define _similarity_tools_h 19 | 20 | #include 21 | #include "learning_context.h" 22 | 23 | namespace similarity_tools 24 | { 25 | void setExternalSimilarityTool(const std::string& executable, const std::string& param = ""); 26 | double getSimilarity(const LearningContext& ctx); 27 | } 28 | 29 | #endif // _similarity_tools_h 30 | -------------------------------------------------------------------------------- /applications/imago_gui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.6) 2 | 3 | project(ImagoGUI) 4 | 5 | include(../../imago-version.cmake) 6 | 7 | install(FILES "build/imago-gui.exe" DESTINATION "bin" COMPONENT bin) 8 | 9 | install(FILES "../../dist/imago_console.exe" DESTINATION "bin" COMPONENT console) 10 | 11 | 12 | FILE(GLOB EXAMPLES "${CMAKE_CURRENT_SOURCE_DIR}/../../examples/*.*") 13 | foreach(f ${EXAMPLES}) 14 | install(FILES "${f}" DESTINATION "examples" COMPONENT examples) 15 | endforeach() 16 | 17 | set(CPACK_PACKAGE_VENDOR "GGA Software Services LLC") 18 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Imago GUI") 19 | set(CPACK_PACKAGE_VERSION ${IMAGO_VERSION}) 20 | set(CPACK_PACKAGE_VERSION_MAJOR "2") 21 | set(CPACK_PACKAGE_VERSION_MINOR "0") 22 | set(CPACK_PACKAGE_VERSION_PATCH "0") 23 | set(CPACK_PACKAGE_INSTALL_DIRECTORY "") 24 | set(CPACK_PACKAGE_EXECUTABLES "imago-gui;ImagoGUI") 25 | set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1) 26 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../../LICENSE.GPL") 27 | set(CPACK_PACKAGE_FILE_NAME "imago-gui-${IMAGO_VERSION}-installer-win") 28 | set(CPACK_NSIS_PACKAGE_NAME "ImagoGUI") 29 | set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/resources/imago-icon.ico") 30 | set(CPACK_PACKAGE_NAME "ImagoGUI") 31 | set(CPACK_PACKAGE_INSTALL_DIRECTORY "ImagoGUI") 32 | 33 | set(CPACK_COMPONENTS_ALL bin examples console) 34 | 35 | set(CPACK_COMPONENT_CONSOLE_DISPLAY_NAME "Imago Console Application") 36 | set(CPACK_COMPONENT_CONSOLE_DESCRIPTION "Imago chemical compounds OCR console application") 37 | 38 | set(CPACK_COMPONENT_BIN_DISPLAY_NAME "ImagoGUI Application") 39 | set(CPACK_COMPONENT_BIN_DESCRIPTION "ImagoGUI chemical compounds OCR application") 40 | 41 | set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Examples") 42 | set(CPACK_COMPONENT_EXAMPLES_DESCRIPTION "Example pictures and compounds") 43 | 44 | #set(CPACK_COMPONENT_BIN_REQUIRED 1) 45 | 46 | include(CPack) 47 | 48 | -------------------------------------------------------------------------------- /applications/imago_gui/resources/document-open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/document-open.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/document-save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/document-save.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/edit-copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/edit-copy.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/edit-find-replace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/edit-find-replace.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/edit-undo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/edit-undo.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/gga-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/gga-logo.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/go-first.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/go-first.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/go-last.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/go-last.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/go-next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/go-next.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/go-previous.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/go-previous.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/imago-icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/imago-icon.ico -------------------------------------------------------------------------------- /applications/imago_gui/resources/imago-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/imago-icon.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/list-add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/list-add.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/list-remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/list-remove.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/splash.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/splash.bmp -------------------------------------------------------------------------------- /applications/imago_gui/resources/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/splash.png -------------------------------------------------------------------------------- /applications/imago_gui/resources/start-here.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/applications/imago_gui/resources/start-here.png -------------------------------------------------------------------------------- /applications/imago_gui/src/com/ggasoftware/DocumentHandling/Document.java: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | package com.ggasoftware.DocumentHandling; 16 | 17 | import java.awt.Dimension; 18 | import java.awt.Graphics; 19 | import java.awt.Rectangle; 20 | import java.awt.image.BufferedImage; 21 | import java.awt.image.ImageObserver; 22 | 23 | public interface Document { 24 | 25 | public interface DocumentPageAsImage { 26 | public void paint(Graphics g); 27 | public BufferedImage getSelectedRectangle(Rectangle rect, 28 | ImageObserver observer); 29 | 30 | public void setScale(double scale); 31 | public Dimension getSize(); 32 | public Dimension getUnscaledSize(); 33 | } 34 | 35 | public int getPageCount(); 36 | public DocumentPageAsImage getPage(int page, ImageObserver observer); 37 | } 38 | -------------------------------------------------------------------------------- /applications/imago_gui/src/com/ggasoftware/EgoForm.java: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | package com.ggasoftware; 16 | 17 | import com.ggasoftware.DocumentHandling.DocumentPanel; 18 | import javax.swing.JFrame; 19 | 20 | public class EgoForm extends JFrame { 21 | public EgoForm(String name) { 22 | super(name); 23 | } 24 | 25 | protected javax.swing.JToolBar jMainToolBar; 26 | protected javax.swing.JButton jOpenButton; 27 | protected javax.swing.JButton jPreviousDocumentButton; 28 | protected javax.swing.JButton jRecognizeButton; 29 | protected javax.swing.JButton jSaveButton; 30 | protected javax.swing.JButton jSketcherButton; 31 | protected javax.swing.JButton jCopyButton; 32 | 33 | protected javax.swing.JTabbedPane jMainTabbedPane; 34 | protected DocumentPanel jDocumentPanel; 35 | protected MoleculePanel jMoleculePanel; 36 | protected javax.swing.JScrollPane jLogScollPane; 37 | protected javax.swing.JTextPane logArea; 38 | 39 | protected javax.swing.JMenuBar jMainMenuBar; 40 | protected javax.swing.JMenuItem jActualSizeMenuItem; 41 | protected javax.swing.JMenuItem jCopyMenuItem; 42 | 43 | protected javax.swing.JMenu jFileMenu; 44 | protected javax.swing.JMenuItem jFirstPageMenuItem; 45 | protected javax.swing.JMenuItem jFitHeightMenuItem; 46 | protected javax.swing.JMenuItem jFitWidthMenuItem; 47 | protected javax.swing.JMenuItem jLastPageMenuItem; 48 | 49 | protected javax.swing.JMenu jMoleculeMenu; 50 | protected javax.swing.JMenu jNavigateMenu; 51 | protected javax.swing.JMenuItem jNextPageMenuItem; 52 | protected javax.swing.JMenuItem jOpenMenuItem; 53 | 54 | protected javax.swing.JMenuItem jPreviousDocumentMenuItem; 55 | protected javax.swing.JMenuItem jPreviousPageMenuItem; 56 | protected javax.swing.JMenuItem jQuitMenuItem; 57 | protected javax.swing.JMenuItem jRecognizeMenuItem; 58 | protected javax.swing.JMenuItem jSaveMenuItem; 59 | protected javax.swing.JMenuItem jSketcherMenuItem; 60 | 61 | protected javax.swing.JMenu jViewMenu; 62 | 63 | protected javax.swing.JMenu jZoomMenu; 64 | protected javax.swing.JMenuItem jZoomOutMenuItem; 65 | protected javax.swing.JMenuItem jZoomInMenuItem; 66 | 67 | protected javax.swing.JMenu jHelpMenu; 68 | protected javax.swing.JMenuItem jAboutMenuItem; 69 | } 70 | -------------------------------------------------------------------------------- /applications/imago_gui/src/com/ggasoftware/ImagePanel.java: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | package com.ggasoftware; 16 | 17 | import java.awt.Color; 18 | import java.awt.Graphics; 19 | import java.awt.Image; 20 | import javax.swing.JPanel; 21 | 22 | public class ImagePanel extends javax.swing.JPanel { 23 | 24 | private Image orig_img = null; 25 | private Image scaled_img = null; 26 | 27 | void ImagePanel() { 28 | } 29 | 30 | private void scaleImage() { 31 | if (orig_img == null) 32 | return; 33 | 34 | scaled_img = null; 35 | 36 | int i_height = orig_img.getHeight(this); 37 | int i_width = orig_img.getWidth(this); 38 | 39 | if (i_height > i_width) { 40 | if (i_height > getHeight()) { 41 | scaled_img = orig_img.getScaledInstance(-1, getHeight(), Image.SCALE_FAST); 42 | } 43 | } 44 | else { 45 | if (i_width > getWidth()) { 46 | scaled_img = orig_img.getScaledInstance(getWidth(), -1, Image.SCALE_FAST); 47 | } 48 | } 49 | if (scaled_img == null) 50 | scaled_img = orig_img; 51 | } 52 | 53 | void setImage(Image new_img) { 54 | orig_img = new_img; 55 | scaleImage(); 56 | } 57 | 58 | @Override 59 | public void paint(Graphics g) { 60 | super.paint(g); 61 | 62 | if (scaled_img != null) { 63 | g.drawImage(scaled_img, (getWidth() - scaled_img.getWidth(this)) / 2, (getHeight() - scaled_img.getHeight(this)) / 2, this); 64 | } 65 | else { 66 | g.setColor(Color.WHITE); 67 | g.fillRect(0, 0, getWidth(), getHeight()); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /applications/imago_gui/src/com/ggasoftware/Utils.java: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | package com.ggasoftware; 16 | 17 | import java.io.File; 18 | 19 | public class Utils { 20 | public static String getFileExtension(File file) { 21 | String name = file.getName(); 22 | if (!name.contains(".")) { 23 | return null; 24 | } 25 | return name.substring(name.lastIndexOf('.') + 1).toLowerCase(); 26 | } 27 | 28 | public static boolean checkFile(File file) { 29 | if (isPDF(file)) { 30 | return true; 31 | } 32 | if (isTIF(file)) { 33 | return true; 34 | } 35 | if (isAcceptableImage(file)) { 36 | return true; 37 | } 38 | return false; 39 | } 40 | 41 | public static boolean isPDF(File file) { 42 | if ("pdf".equals(getFileExtension(file))) { 43 | return true; 44 | } 45 | return false; 46 | } 47 | 48 | public static boolean isTIF(File file) { 49 | String ext = getFileExtension(file); 50 | if ("tif".equals(ext) || "tiff".equals(ext)) { 51 | return true; 52 | } 53 | return false; 54 | } 55 | 56 | public static boolean isAcceptableImage(File file) { 57 | String ext = getFileExtension(file); 58 | if ("png".equals(ext) || "jpg".equals(ext) || "gif".equals(ext)) { 59 | return true; 60 | } 61 | return false; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /applications/imago_gui/src/com/ggasoftware/WaitingPanel.java: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | package com.ggasoftware; 16 | 17 | import javax.swing.JLabel; 18 | import javax.swing.JPanel; 19 | 20 | public class WaitingPanel extends JPanel { 21 | public WaitingPanel() { 22 | super(true); 23 | setSize(150, 50); 24 | add(new JLabel("Recognizing...")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /bindings/c/src/imago_version.h.in: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #ifndef _imago_version_h 16 | #define _imago_version_h 17 | 18 | #define IMAGO_VERSION "${IMAGO_VERSION_EXT}" 19 | 20 | #endif -------------------------------------------------------------------------------- /bindings/c/src/recognition_context.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "recognition_context.h" 20 | 21 | namespace imago 22 | { 23 | typedef std::map ContextMap; 24 | static ContextMap _contexts; 25 | static boost::mutex _contexts_mutex; 26 | 27 | RecognitionContext *getContextForSession( qword sessionId ) 28 | { 29 | boost::lock_guard lock(_contexts_mutex); 30 | ContextMap::iterator it; 31 | if ((it = _contexts.find(sessionId)) == _contexts.end()) 32 | return NULL; 33 | 34 | return it->second; 35 | } 36 | 37 | void setContextForSession( qword sessionId, RecognitionContext *context ) 38 | { 39 | boost::lock_guard lock(_contexts_mutex); 40 | ContextMap::iterator it; 41 | if ((it = _contexts.find(sessionId)) == _contexts.end()) 42 | _contexts.insert(std::make_pair(sessionId, context)); 43 | else 44 | it->second = context; 45 | } 46 | 47 | void deleteRecognitionContext(qword sessionId, RecognitionContext *context) 48 | { 49 | boost::lock_guard lock(_contexts_mutex); 50 | delete context; 51 | _contexts.erase(_contexts.find(sessionId)); 52 | } 53 | 54 | struct _ContextCleanup 55 | { 56 | ~_ContextCleanup() 57 | { 58 | BOOST_FOREACH(ContextMap::value_type item, _contexts) 59 | { 60 | delete item.second; 61 | } 62 | } 63 | }; 64 | 65 | static _ContextCleanup _deleter; 66 | } -------------------------------------------------------------------------------- /bindings/c/src/recognition_context.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _recognition_context_h 17 | #define _recognition_context_h 18 | 19 | #include 20 | 21 | #include "comdef.h" 22 | #include "chemical_structure_recognizer.h" 23 | #include "image.h" 24 | #include "molecule.h" 25 | #include "settings.h" 26 | #include "virtual_fs.h" 27 | #include "session_manager.h" 28 | 29 | namespace imago 30 | { 31 | struct RecognitionContext 32 | { 33 | ChemicalStructureRecognizer csr; 34 | Image img_tmp; 35 | Image img_src; 36 | Molecule mol; 37 | std::string molfile; 38 | std::string out_buf; 39 | std::string error_buf; 40 | std::string configs_list; 41 | Settings vars; 42 | VirtualFS vfs; 43 | void *session_specific_data; 44 | 45 | RecognitionContext () 46 | { 47 | session_specific_data = 0; 48 | error_buf = "No error"; 49 | } 50 | }; 51 | 52 | RecognitionContext *getContextForSession(qword sessionId); 53 | inline RecognitionContext *getCurrentContext() 54 | { 55 | return getContextForSession(SessionManager::getInstance().getSID()); 56 | } 57 | 58 | void setContextForSession(qword sessionId, RecognitionContext *context); 59 | void deleteRecognitionContext(qword sessionId, RecognitionContext *context); 60 | }; 61 | 62 | 63 | #endif /* _imago_session_h */ -------------------------------------------------------------------------------- /bindings/c/src/session_manager.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #include 16 | #include 17 | 18 | #include "session_manager.h" 19 | 20 | using namespace imago; 21 | 22 | boost::mutex SessionManager::_mutex; 23 | boost::thread_specific_ptr SessionManager::_curSID; 24 | SessionManager SessionManager::_instance; 25 | 26 | 27 | SessionManager::SessionManager() 28 | { 29 | _freeSID = 0; 30 | } 31 | 32 | qword SessionManager::getSID() 33 | { 34 | qword *pid = _curSID.get(); 35 | qword id; 36 | 37 | if (pid == 0) 38 | { 39 | id = allocSID(); 40 | setSID(id); 41 | } 42 | else 43 | id = *pid; 44 | 45 | return id; 46 | } 47 | 48 | qword SessionManager::allocSID() 49 | { 50 | lock_guard lock(_mutex); 51 | qword id; 52 | 53 | if (_availableSIDs.size() > 0) 54 | { 55 | id = _availableSIDs.front(); 56 | _availableSIDs.pop_front(); 57 | } 58 | else 59 | { 60 | while (_activeSessions.find(_freeSID) != _activeSessions.end()) 61 | ++_freeSID; 62 | 63 | id = _freeSID; 64 | ++_freeSID; 65 | } 66 | 67 | _activeSessions.insert(id); 68 | return id; 69 | } 70 | 71 | void SessionManager::setSID( qword id ) 72 | { 73 | lock_guard lock(_mutex); 74 | 75 | if (_activeSessions.find(id) == _activeSessions.end()) 76 | { 77 | //keep working or throw an exception? 78 | //throw WrongSessionIdException(); 79 | _activeSessions.insert(id); 80 | } 81 | 82 | qword *pId = _curSID.get(); 83 | if (pId == 0) 84 | { 85 | _curSID.reset(new qword(id)); 86 | pId = _curSID.get(); 87 | } 88 | else 89 | *pId = id; 90 | } 91 | 92 | void SessionManager::releaseSID( qword id ) 93 | { 94 | lock_guard lock(_mutex); 95 | 96 | IdSet::iterator curSessionIt = _activeSessions.find(id); 97 | if (curSessionIt == _activeSessions.end()) 98 | { 99 | std::cerr << "Trying to release unallocated session " << id << "\n"; 100 | return; 101 | } 102 | 103 | _activeSessions.erase(curSessionIt); 104 | _availableSIDs.push_back(id); 105 | } 106 | 107 | SessionManager &SessionManager::getInstance() 108 | { 109 | return _instance; 110 | } 111 | 112 | SessionManager::~SessionManager() 113 | { 114 | _activeSessions.clear(); 115 | _availableSIDs.clear(); 116 | _curSID.reset(0); 117 | } 118 | 119 | -------------------------------------------------------------------------------- /bindings/c/src/session_manager.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _session_manager_h 17 | #define _session_manager_h 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "comdef.h" 25 | 26 | namespace imago 27 | { 28 | class SessionManager 29 | { 30 | public: 31 | static SessionManager &getInstance(); 32 | 33 | qword getSID(); 34 | void setSID( qword id ); 35 | 36 | qword allocSID(); 37 | void releaseSID( qword id ); 38 | private: 39 | qword _freeSID; 40 | 41 | typedef std::deque IdContainer; 42 | IdContainer _availableSIDs; 43 | typedef std::set IdSet; 44 | IdSet _activeSessions; 45 | 46 | static boost::thread_specific_ptr _curSID; 47 | static SessionManager _instance; 48 | static boost::mutex _mutex; 49 | typedef boost::lock_guard lock_guard; 50 | 51 | SessionManager(); 52 | SessionManager( const SessionManager& ); 53 | ~SessionManager(); 54 | }; 55 | } 56 | 57 | #endif /* _session_manager_h */ 58 | 59 | -------------------------------------------------------------------------------- /bindings/c/test/imago_c_test.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #include 16 | 17 | #include "imago_c.h" 18 | 19 | int main (int argc, char *argv[]) 20 | { 21 | int warnings; 22 | int ret; 23 | qword session; 24 | 25 | if (argc < 3) 26 | { 27 | fprintf(stderr, "Usage: \n"); 28 | return -1; 29 | } 30 | 31 | session = imagoAllocSessionId(); 32 | imagoSetSessionId(session); 33 | 34 | printf("Loading image..."); 35 | ret = imagoLoadImageFromFile(argv[1]); 36 | if (ret != 1) 37 | { 38 | fprintf(stderr, "Cannot load image\n"); 39 | return -1; 40 | } 41 | printf("OK\n"); 42 | 43 | printf("Recognizing image..."); 44 | ret = imagoRecognize(&warnings); 45 | if (ret != 1) 46 | { 47 | fprintf(stderr, "Cannot recognize image\n"); 48 | return -1; 49 | } 50 | printf("OK\n"); 51 | printf("Number of warnings: %d\n", warnings); 52 | 53 | printf("Saving recongized molecule..."); 54 | ret = imagoSaveMolToFile(argv[2]); 55 | if (ret != 1) 56 | { 57 | fprintf(stderr, "Cannot save molecule\n"); 58 | return -1; 59 | } 60 | printf("OK\n"); 61 | 62 | imagoReleaseSessionId(session); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /bindings/c/test/indigo_compare_molecules.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #include 16 | 17 | #include "indigo.h" 18 | 19 | int compareMolecules (const char *m1_filename, const char *m2_filename) 20 | { 21 | int m1 = indigoLoadMoleculeFromFile(m1_filename); 22 | int m2 = indigoLoadMoleculeFromFile(m1_filename); 23 | if (indigoExactMatch(m1, m2, "") == 0) 24 | return 0; 25 | return 1; 26 | } 27 | 28 | int main (int argc, char *argv[]) 29 | { 30 | if (argc < 2) 31 | { 32 | fprintf(stderr, "Usage: \n"); 33 | return -1; 34 | } 35 | 36 | if (compareMolecules(argv[2], argv[3]) == 0) 37 | { 38 | fprintf(stderr, "Recognized molecule doesn't match: %s and %s\n", argv[2], argv[3]); 39 | return -1; 40 | } 41 | printf("Matched.\n"); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /bindings/java/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /bindings/java/src/com/ggasoftware/imago/ImagoException.java: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | package com.ggasoftware.imago; 16 | 17 | public class ImagoException extends RuntimeException { 18 | 19 | public ImagoException() { 20 | super(); 21 | } 22 | 23 | public ImagoException(String message) { 24 | super(message); 25 | } 26 | } -------------------------------------------------------------------------------- /bindings/java/src/com/ggasoftware/imago/ImagoLib.java: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | package com.ggasoftware.imago; 16 | 17 | import com.sun.jna.*; 18 | import com.sun.jna.ptr.*; 19 | 20 | public interface ImagoLib extends Library { 21 | String imagoGetVersion(); 22 | String imagoGetLastError(); 23 | 24 | long imagoAllocSessionId(); 25 | void imagoSetSessionId(long id); 26 | void imagoReleaseSessionId(long id); 27 | 28 | int imagoSetConfig(String config); 29 | String imagoGetConfigsList(); 30 | 31 | int imagoSetFilter(String filter); 32 | 33 | int imagoLoadImageFromBuffer(byte[] buf, int buf_size); 34 | int imagoLoadImageFromFile(String filename); 35 | 36 | int imagoSaveImageToFile(String filename); 37 | 38 | int imagoLoadGreyscaleRawImage(byte[] buf, int width, int height); 39 | 40 | int imagoSetLogging(int mode); 41 | 42 | int imagoRecognize(IntByReference warnings); 43 | 44 | int imagoSaveMolToBuffer(PointerByReference buf, IntByReference buf_size); 45 | int imagoSaveMolToFile(String filename); 46 | 47 | int imagoFilterImage(); 48 | 49 | int imagoGetInkPercentage(DoubleByReference percentage); 50 | 51 | int imagoGetPrefilteredImageSize(IntByReference width, IntByReference height); 52 | int imagoGetPrefilteredImage(PointerByReference data, IntByReference width, IntByReference height); 53 | 54 | int imagoSetSessionSpecificData(Pointer data); 55 | int imagoGetSessionSpecificData(PointerByReference data); 56 | 57 | int imagoGetLogCount(IntByReference count); 58 | int imagoGetLogRecord(int it, PointerByReference name, IntByReference length, PointerByReference data); 59 | } -------------------------------------------------------------------------------- /cmake/Boost.cmake: -------------------------------------------------------------------------------- 1 | option(USE_SYSTEM_BOOST "Use system Boost libs or download prebuilt from the server" OFF) 2 | 3 | #Common settings 4 | #set(Boost_DEBUG ON) 5 | set(Boost_ADDITIONAL_VERSIONS "1.49" "1.49.0") 6 | set(Boost_USE_STATIC_LIBS ON) 7 | set(Boost_USE_MULTITHREADED ON) 8 | set(Boost_USE_STATIC_RUNTIME OFF) 9 | set(Boost_FIND_REQUIRED ON) 10 | 11 | if(NOT USE_SYSTEM_BOOST) 12 | set(BOOST_INCLUDEDIR "${THIRD_PARTY_DIR}/boost") 13 | set(BOOST_LIBRARYDIR "${THIRD_PARTY_DIR}/boost/${SYSTEM_NAME}/${SUBSYSTEM_NAME}") 14 | set(Boost_NO_SYSTEM_PATHS TRUE) 15 | 16 | set(BOOST_HEADERS_FILENAME "boost_headers.zip") 17 | set(BOOST_LIBS_FILENAME "boost_libs_${SYSTEM_NAME}_${SUBSYSTEM_NAME}.zip") 18 | 19 | if(NOT EXISTS ${BOOST_INCLUDEDIR}) 20 | if(NOT EXISTS ${THIRD_PARTY_DIR}/${BOOST_HEADERS_FILENAME}) 21 | message("Downloading Boost headers from ${LIBS_LOCATION}") 22 | file(DOWNLOAD ${LIBS_LOCATION}/${BOOST_HEADERS_FILENAME} 23 | ${THIRD_PARTY_DIR}/${BOOST_HEADERS_FILENAME} 24 | STATUS boost_headers_status SHOW_PROGRESS) 25 | list(GET boost_headers_status 0 boost_header_status) 26 | if(NOT boost_headers_status EQUAL 0) 27 | message(FATAL_ERROR "Couldn't download boost headers!") 28 | endif() 29 | endif() 30 | execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BOOST_INCLUDEDIR}) 31 | execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf ${THIRD_PARTY_DIR}/${BOOST_HEADERS_FILENAME} 32 | WORKING_DIRECTORY ${BOOST_INCLUDEDIR}) 33 | endif() 34 | if(NOT EXISTS ${BOOST_LIBRARYDIR}) 35 | if(NOT EXISTS ${THIRD_PARTY_DIR}/${BOOST_LIBS_FILENAME}) 36 | message("Downloading boost libs from ${LIBS_LOCATION}") 37 | file(DOWNLOAD ${LIBS_LOCATION}/${BOOST_LIBS_FILENAME} 38 | ${THIRD_PARTY_DIR}/${BOOST_LIBS_FILENAME} 39 | STATUS boost_libs_status SHOW_PROGRESS) 40 | 41 | endif() 42 | execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BOOST_LIBRARYDIR}) 43 | execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf ${THIRD_PARTY_DIR}/${BOOST_LIBS_FILENAME} 44 | WORKING_DIRECTORY ${BOOST_LIBRARYDIR}) 45 | endif() 46 | endif() 47 | 48 | find_package(Boost 1.49.0 COMPONENTS thread program_options system filesystem) 49 | 50 | include_directories(${Boost_INCLUDE_DIR}) -------------------------------------------------------------------------------- /cmake/BuildOptions.cmake: -------------------------------------------------------------------------------- 1 | if(SYSTEM_NAME STREQUAL "Win") 2 | include(BuildOptionsWin) 3 | elseif(SYSTEM_NAME STREQUAL "Linux") 4 | include(BuildOptionsLinux) 5 | elseif(SYSTEM_NAME STREQUAL "Mac") 6 | include(BuildOptionsMac) 7 | endif() 8 | 9 | if(NOT LIBS_LOCATION) 10 | message(FATAL_ERROR "Please set LIBS_LOCATION variable") 11 | endif() 12 | set(THIRD_PARTY_DIR ${CMAKE_SOURCE_DIR}/third_party) 13 | 14 | include(Boost) 15 | include(OpenCV) 16 | include(Indigo) 17 | 18 | set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE) 19 | include(InstallRequiredSystemLibraries) 20 | -------------------------------------------------------------------------------- /cmake/BuildOptionsLinux.cmake: -------------------------------------------------------------------------------- 1 | find_package(Threads REQUIRED) 2 | 3 | if(SUBSYSTEM_NAME STREQUAL "x86") 4 | set(IMAGO_C_FLAGS "-m32") 5 | elseif(SUBSYSTEM_NAME STREQUAL "x64") 6 | set(IMAGO_C_FLAGS "-fPIC -m64") 7 | else() 8 | message(FATAL_ERROR "Unknown subsystem name!") 9 | endif() 10 | 11 | add_definitions("${IMAGO_C_FLAGS}") 12 | set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS_INIT} ${IMAGO_C_FLAGS}) 13 | set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS_INIT} ${IMAGO_C_FLAGS}) 14 | set(LINK_FLAGS "${LINK_FLAGS} ${IMAGO_C_FLAGS}") 15 | -------------------------------------------------------------------------------- /cmake/BuildOptionsMac.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42") 2 | 3 | if(SUBSYSTEM_NAME STREQUAL "iOS") 4 | SET (SDKVER "5.0") 5 | SET (DEVROOT "/Developer/Platforms/iPhoneOS.platform/Developer") 6 | SET (SDKROOT "${DEVROOT}/SDKs/iPhoneOS${SDKVER}.sdk") 7 | SET (CMAKE_OSX_SYSROOT "${SDKROOT}") 8 | SET (CMAKE_OSX_ARCHITECTURES "armv7;i386") #"$(ARCHS_STANDARD_32_BIT)") #"$(ARCHS_UNIVERSAL_IPHONE_OS)") 9 | SET (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator") 10 | #Other 'CMAKE_OSX_ARCHITECTURES' iPhone/IOS option examples 11 | #SET (CMAKE_OSX_ARCHITECTURES "armv7") 12 | #SET (CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD_32_BIT) 13 | else() 14 | if (${SUBSYSTEM_NAME}) 15 | EXEC_PROGRAM(xcodebuild ARGS -version OUTPUT_VARIABLE XCODE_VERSION) 16 | STRING(REGEX MATCH "[0-9][.][0-9]" XCODE_VERSION ${XCODE_VERSION}) 17 | if (${XCODE_VERSION} GREATER 4.2) 18 | set(CMAKE_OSX_SYSROOT /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${SUBSYSTEM_NAME}.sdk) 19 | else() 20 | set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${SUBSYSTEM_NAME}.sdk) 21 | endif() 22 | set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_OSX_SYSROOT}/usr) 23 | endif() 24 | SET(CMAKE_OSX_DEPLOYMENT_TARGET ${SUBSYSTEM_NAME} CACHE STRING "Deployment target for OSX" FORCE) 25 | MESSAGE(STATUS "CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT}") 26 | MESSAGE(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") 27 | find_package(Threads REQUIRED) 28 | set(CMAKE_OSX_ARCHITECTURES "i386;x86_64") 29 | set(COMPILE_FLAGS "${COMPILE_FLAGS} -fPIC") 30 | endif() -------------------------------------------------------------------------------- /cmake/BuildOptionsWin.cmake: -------------------------------------------------------------------------------- 1 | add_definitions("/D _CRT_SECURE_NO_DEPRECATE /D BOOST_ALL_NO_LIB") -------------------------------------------------------------------------------- /cmake/GetSystemVersion.cmake: -------------------------------------------------------------------------------- 1 | set(SUBSYSTEM_NAME "" CACHE STRING "Subsystem name") 2 | if(MSVC) 3 | set(SYSTEM_NAME "Win") 4 | if(NOT SUBSYSTEM_NAME) 5 | if(CMAKE_SIZEOF_VOID_P MATCHES 8) 6 | set(SUBSYSTEM_NAME "x64") 7 | else() 8 | set(SUBSYSTEM_NAME "x86") 9 | endif() 10 | endif() 11 | set(SYSTEM_DL_EXTENSION ".dll") 12 | elseif(APPLE) 13 | set(SYSTEM_NAME "Mac") 14 | if(NOT SUBSYSTEM_NAME) 15 | exec_program(uname ARGS -v OUTPUT_VARIABLE DARWIN_VERSION) 16 | string(REGEX MATCH "[0-9]+" DARWIN_VERSION ${DARWIN_VERSION}) 17 | if(DARWIN_VERSION MATCHES 8) 18 | set(SUBSYSTEM_NAME "10.4") 19 | elseif(DARWIN_VERSION MATCHES 9) 20 | set(SUBSYSTEM_NAME "10.5") 21 | elseif(DARWIN_VERSION MATCHES 10) 22 | set(SUBSYSTEM_NAME "10.6") 23 | elseif(DARWIN_VERSION MATCHES 11) 24 | set(SUBSYSTEM_NAME "10.6") 25 | elseif(DARWIN_VERSION MATCHES 12) 26 | set(SUBSYSTEM_NAME "10.6") 27 | elseif() 28 | message(FATAL_ERROR "Unsupported DARWIN_VERSION: ${DARWIN_VERSION}") 29 | endif() 30 | endif() 31 | set(SYSTEM_DL_EXTENSION ".dylib") 32 | elseif(UNIX) 33 | set(SYSTEM_NAME "Linux") 34 | if(NOT SUBSYSTEM_NAME) 35 | if(CMAKE_SIZEOF_VOID_P MATCHES 8) 36 | set(SUBSYSTEM_NAME "x64") 37 | else() 38 | set(SUBSYSTEM_NAME "x86") 39 | endif() 40 | endif() 41 | set(SYSTEM_DL_EXTENSION ".so") 42 | else() 43 | message(FATAL_ERROR "Unsupported system") 44 | endif() 45 | 46 | IF (SYSTEM_NAME MATCHES "Mac") 47 | SET(PACKAGE_SUFFIX "mac${SUBSYSTEM_NAME}") 48 | ELSE() 49 | IF (SYSTEM_NAME MATCHES "Win") 50 | SET(PACKAGE_SUFFIX_PREFIX "win") 51 | ELSEIF (SYSTEM_NAME MATCHES "Linux") 52 | SET(PACKAGE_SUFFIX_PREFIX "linux") 53 | ELSE() 54 | MESSAGE(FATAL_ERROR "Unsupported system") 55 | ENDIF() 56 | IF (SUBSYSTEM_NAME MATCHES "x86") 57 | SET(PACKAGE_SUFFIX_SUFFIX "32") 58 | ELSEIF (SUBSYSTEM_NAME MATCHES "x64") 59 | SET(PACKAGE_SUFFIX_SUFFIX "64") 60 | ELSE() 61 | MESSAGE(FATAL_ERROR "Unsupported system") 62 | ENDIF() 63 | SET(PACKAGE_SUFFIX "${PACKAGE_SUFFIX_PREFIX}${PACKAGE_SUFFIX_SUFFIX}") 64 | ENDIF() 65 | 66 | SET(SUBSYSTEM_PATH "${SYSTEM_NAME}/${SUBSYSTEM_NAME}") 67 | -------------------------------------------------------------------------------- /cmake/Indigo.cmake: -------------------------------------------------------------------------------- 1 | option(USE_SYSTEM_INDIGO "Use system Indigo libs or download prebuilt from the server" OFF) 2 | 3 | 4 | if(NOT USE_SYSTEM_INDIGO) 5 | set(INDIGO_DIR "${THIRD_PARTY_DIR}/indigo") 6 | set(INDIGO_INCLUDE_DIR "${INDIGO_DIR}/indigo") 7 | set(INDIGO_LIBS_RELEASE_DIR "${INDIGO_DIR}/libs_release/${SYSTEM_NAME}/${SUBSYSTEM_NAME}") 8 | set(INDIGO_LIBS_DEBUG_DIR "${INDIGO_DIR}/libs_debug/${SYSTEM_NAME}/${SUBSYSTEM_NAME}") 9 | 10 | set(INDIGO_LIBS_FILENAME "indigo-libs-${SYSTEM_NAME}-${SUBSYSTEM_NAME}.zip") 11 | 12 | set(INDIGO_LIBS_LOCATION "${LIBS_LOCATION}/indigo/c_static/") 13 | 14 | if(NOT EXISTS ${INDIGO_LIBS_RELEASE_DIR}) 15 | if(NOT EXISTS ${THIRD_PARTY_DIR}/${INDIGO_LIBS_FILENAME}) 16 | message("Downloading Indigo libs from ${INDIGO_LIBS_LOCATION}/${INDIGO_LIBS_FILENAME}") 17 | file(DOWNLOAD ${INDIGO_LIBS_LOCATION}/${INDIGO_LIBS_FILENAME} 18 | ${THIRD_PARTY_DIR}/${INDIGO_LIBS_FILENAME} 19 | STATUS indigo_libs_status SHOW_PROGRESS) 20 | endif() 21 | execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${INDIGO_DIR}) 22 | execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf ${THIRD_PARTY_DIR}/${INDIGO_LIBS_FILENAME} 23 | WORKING_DIRECTORY ${INDIGO_DIR}) 24 | endif() 25 | 26 | include_directories(${INDIGO_INCLUDE_DIR}) 27 | file(GLOB INDIGO_LIBS_RELEASE "${INDIGO_LIBS_RELEASE_DIR}/*${CMAKE_STATIC_LIBRARY_SUFFIX}") 28 | file(GLOB INDIGO_LIBS_DEBUG "${INDIGO_LIBS_DEBUG_DIR}/*${CMAKE_STATIC_LIBRARY_SUFFIX}") 29 | 30 | foreach(lib ${INDIGO_LIBS_DEBUG}) 31 | set(Indigo_LIBRARIES ${Indigo_LIBRARIES} debug ${lib}) 32 | endforeach() 33 | foreach(lib ${INDIGO_LIBS_RELEASE}) 34 | set(Indigo_LIBRARIES ${Indigo_LIBRARIES} optimized ${lib}) 35 | endforeach() 36 | 37 | # To avoid problem with library order we specify them twice or even more 38 | set(Indigo_LIBRARIES ${Indigo_LIBRARIES} ${Indigo_LIBRARIES} ${Indigo_LIBRARIES}) 39 | else() 40 | message(FATAL_ERROR "Not implemented yet!") 41 | endif() 42 | -------------------------------------------------------------------------------- /cmake/OpenCV.cmake: -------------------------------------------------------------------------------- 1 | option(USE_SYSTEM_OPENCV "Use system OpenCV libs or download prebuilt from the server" OFF) 2 | 3 | if(NOT USE_SYSTEM_OPENCV) 4 | set(OpenCV_DIR "${THIRD_PARTY_DIR}/opencv/${SYSTEM_NAME}/${SUBSYSTEM_NAME}") 5 | set(OpenCV_FILENAME "opencv_${SYSTEM_NAME}_${SUBSYSTEM_NAME}.zip") 6 | if(NOT EXISTS ${OpenCV_DIR}) 7 | if(NOT EXISTS ${THIRD_PARTY_DIR}/${OpenCV_FILENAME}) 8 | message("Downloading OpenCV headers from ${LIBS_LOCATION}") 9 | file(DOWNLOAD ${LIBS_LOCATION}/${OpenCV_FILENAME} 10 | ${THIRD_PARTY_DIR}/${OpenCV_FILENAME} 11 | STATUS opencv_status SHOW_PROGRESS) 12 | endif() 13 | execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${OpenCV_DIR}) 14 | execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf ${THIRD_PARTY_DIR}/${OpenCV_FILENAME} 15 | WORKING_DIRECTORY ${OpenCV_DIR}) 16 | endif() 17 | 18 | if(NOT SYSTEM_NAME STREQUAL "Win") 19 | set(OpenCV_DIR "${OpenCV_DIR}/share/OpenCV") 20 | endif() 21 | 22 | include("${OpenCV_DIR}/OpenCVConfig.cmake") 23 | include_directories(${OpenCV_INCLUDE_DIRS}) 24 | else() 25 | #find_package 26 | message(FATAL_ERROR "Not implemented yet!") 27 | endif() 28 | -------------------------------------------------------------------------------- /examples/0000041_rnd.mol: -------------------------------------------------------------------------------- 1 | 41 2 | -INDIGO-12261221092D 3 | 4 | 14 13 0 0 0 0 0 0 0 0999 V2000 5 | 9.4651 0.0950 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0 6 | 3.4030 -0.4050 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0 7 | 4.2690 0.0950 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 8 | 6.8671 -1.4050 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 9 | 6.0010 1.0950 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 10 | 2.5369 -0.9050 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 11 | 2.9030 0.4610 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 12 | 3.9030 -1.2710 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 13 | 7.7331 0.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 14 | 8.5991 -0.4050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 15 | 6.8671 -0.4050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 16 | 6.0010 0.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 17 | 5.1350 -0.4050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 18 | 10.3312 -0.4050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 19 | 1 10 1 0 0 0 0 20 | 1 14 1 0 0 0 0 21 | 2 3 1 0 0 0 0 22 | 2 6 1 0 0 0 0 23 | 2 7 1 0 0 0 0 24 | 2 8 2 0 0 0 0 25 | 3 13 1 0 0 0 0 26 | 4 11 2 0 0 0 0 27 | 5 12 1 0 0 0 0 28 | 9 10 1 0 0 0 0 29 | 9 11 1 0 0 0 0 30 | 11 12 1 0 0 0 0 31 | 12 13 2 0 0 0 0 32 | M END 33 | -------------------------------------------------------------------------------- /examples/0000041_rnd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/examples/0000041_rnd.png -------------------------------------------------------------------------------- /examples/0000191_rnd.mol: -------------------------------------------------------------------------------- 1 | 191 2 | -INDIGO-12261221092D 3 | 4 | 19 21 0 0 0 0 0 0 0 0999 V2000 5 | 5.9405 0.8252 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 6 | 3.4026 1.3296 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 7 | 4.6844 3.0874 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 8 | 7.6651 2.0032 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 9 | 4.6783 -0.4327 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 10 | 4.6783 -2.0422 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 11 | 2.8660 -0.2375 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 12 | 2.0000 -1.7374 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 13 | 2.8660 -3.2374 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 14 | 4.4026 1.3278 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 15 | 4.9889 0.5178 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 16 | 4.9917 2.1358 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 17 | 5.9422 1.8252 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 18 | 6.7523 2.4116 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 19 | 3.7320 -0.7375 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 20 | 5.2619 -1.2374 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 21 | 3.7320 -1.7374 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 22 | 2.8660 -2.2374 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 23 | 2.0000 -0.7375 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 24 | 1 11 1 0 0 0 0 25 | 1 13 1 0 0 0 0 26 | 2 10 1 0 0 0 0 27 | 3 12 1 0 0 0 0 28 | 4 14 1 0 0 0 0 29 | 5 11 1 0 0 0 0 30 | 5 15 1 0 0 0 0 31 | 5 16 1 0 0 0 0 32 | 6 16 2 0 0 0 0 33 | 6 17 1 0 0 0 0 34 | 7 15 1 0 0 0 0 35 | 7 19 2 0 0 0 0 36 | 8 18 2 0 0 0 0 37 | 8 19 1 0 0 0 0 38 | 9 18 1 0 0 0 0 39 | 10 11 1 0 0 0 0 40 | 10 12 1 0 0 0 0 41 | 12 13 1 0 0 0 0 42 | 13 14 1 0 0 0 0 43 | 15 17 2 0 0 0 0 44 | 17 18 1 0 0 0 0 45 | M END 46 | -------------------------------------------------------------------------------- /examples/0000191_rnd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/examples/0000191_rnd.png -------------------------------------------------------------------------------- /examples/0000230_rnd.mol: -------------------------------------------------------------------------------- 1 | 230 2 | -INDIGO-12261221092D 3 | 4 | 14 13 0 0 0 0 0 0 0 0999 V2000 5 | 3.4030 -0.2500 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0 6 | 6.0010 1.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 7 | 6.8671 -1.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 8 | 4.2690 0.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 9 | 7.7331 1.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 10 | 9.4651 0.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 11 | 2.5369 -0.7500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 12 | 2.9030 0.6160 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 13 | 3.9030 -1.1160 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 14 | 6.8671 -0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 15 | 6.0010 0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 16 | 7.7331 0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 17 | 5.1350 -0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 18 | 8.5991 -0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 19 | 1 4 1 0 0 0 0 20 | 1 7 1 0 0 0 0 21 | 1 8 1 0 0 0 0 22 | 1 9 2 0 0 0 0 23 | 2 11 1 0 0 0 0 24 | 3 10 1 0 0 0 0 25 | 4 13 1 0 0 0 0 26 | 5 12 1 0 0 0 0 27 | 6 14 2 0 0 0 0 28 | 10 11 1 0 0 0 0 29 | 10 12 1 0 0 0 0 30 | 11 13 1 0 0 0 0 31 | 12 14 1 0 0 0 0 32 | M END 33 | -------------------------------------------------------------------------------- /examples/0000230_rnd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/examples/0000230_rnd.png -------------------------------------------------------------------------------- /examples/0000415_rnd.mol: -------------------------------------------------------------------------------- 1 | 415 2 | -INDIGO-12261221092D 3 | 4 | 14 15 0 0 0 0 0 0 0 0999 V2000 5 | 2.4608 -0.0784 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 6 | 3.9118 2.7694 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 7 | 3.1028 1.1816 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 8 | 4.2778 -2.2694 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 9 | 3.4118 0.2306 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 10 | 4.4118 0.2306 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 11 | 4.7208 1.1816 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 12 | 3.9118 1.7694 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 13 | 3.4118 -0.7694 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 14 | 2.1517 1.4906 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 15 | 2.5458 -1.2694 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 16 | 4.2778 -1.2694 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 17 | 2.5458 -2.2694 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 18 | 3.4118 -2.7694 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 19 | 1 5 1 0 0 0 0 20 | 2 8 2 0 0 0 0 21 | 3 5 1 0 0 0 0 22 | 3 8 1 0 0 0 0 23 | 3 10 1 0 0 0 0 24 | 4 12 1 0 0 0 0 25 | 4 14 2 0 0 0 0 26 | 5 6 1 0 0 0 0 27 | 5 9 1 0 0 0 0 28 | 6 7 1 0 0 0 0 29 | 7 8 1 0 0 0 0 30 | 9 11 1 0 0 0 0 31 | 9 12 2 0 0 0 0 32 | 11 13 2 0 0 0 0 33 | 13 14 1 0 0 0 0 34 | M END 35 | -------------------------------------------------------------------------------- /examples/0000415_rnd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/examples/0000415_rnd.png -------------------------------------------------------------------------------- /examples/0000603_rnd.mol: -------------------------------------------------------------------------------- 1 | 603 2 | -INDIGO-12261221092D 3 | 4 | 16 15 0 0 0 0 0 0 0 0999 V2000 5 | 3.4030 -0.2500 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0 6 | 6.8671 -1.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 7 | 6.0010 1.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 8 | 4.2690 0.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 9 | 7.7331 1.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 10 | 8.5991 -1.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 11 | 10.3312 -0.2500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 12 | 2.5369 -0.7500 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 13 | 2.9030 0.6160 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 14 | 3.9030 -1.1160 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 15 | 6.8671 -0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 16 | 6.0010 0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 17 | 7.7331 0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 18 | 5.1350 -0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 19 | 8.5991 -0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 20 | 9.4651 0.2500 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 21 | 1 4 1 0 0 0 0 22 | 1 8 1 0 0 0 0 23 | 1 9 1 0 0 0 0 24 | 1 10 2 0 0 0 0 25 | 2 11 1 0 0 0 0 26 | 3 12 1 0 0 0 0 27 | 4 14 1 0 0 0 0 28 | 5 13 1 0 0 0 0 29 | 6 15 2 0 0 0 0 30 | 7 16 1 0 0 0 0 31 | 11 12 1 0 0 0 0 32 | 11 13 1 0 0 0 0 33 | 12 14 1 0 0 0 0 34 | 13 15 1 0 0 0 0 35 | 15 16 1 0 0 0 0 36 | M END 37 | -------------------------------------------------------------------------------- /examples/0000603_rnd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/examples/0000603_rnd.png -------------------------------------------------------------------------------- /examples/0000931_rnd.mol: -------------------------------------------------------------------------------- 1 | 931 2 | -INDIGO-12261221092D 3 | 4 | 10 11 0 0 0 0 0 0 0 0999 V2000 5 | 3.7320 -0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 6 | 3.7320 0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 7 | 2.8660 -1.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 8 | 2.8660 1.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 9 | 4.6260 -1.0347 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 10 | 4.6260 1.0347 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 11 | 2.0000 -0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 12 | 2.0000 0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 13 | 5.5321 0.5208 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 14 | 5.5321 -0.5208 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 15 | 1 2 1 0 0 0 0 16 | 1 3 2 0 0 0 0 17 | 1 5 1 0 0 0 0 18 | 2 4 2 0 0 0 0 19 | 2 6 1 0 0 0 0 20 | 3 7 1 0 0 0 0 21 | 4 8 1 0 0 0 0 22 | 5 10 2 0 0 0 0 23 | 6 9 2 0 0 0 0 24 | 7 8 2 0 0 0 0 25 | 9 10 1 0 0 0 0 26 | M END 27 | -------------------------------------------------------------------------------- /examples/0000931_rnd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/examples/0000931_rnd.png -------------------------------------------------------------------------------- /examples/0001018_rnd.mol: -------------------------------------------------------------------------------- 1 | 1018 2 | -INDIGO-12261221092D 3 | 4 | 9 9 0 0 0 0 0 0 0 0999 V2000 5 | 2.5369 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 6 | 3.4030 -1.5000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 7 | 5.1350 -0.5000 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 8 | 4.2690 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 9 | 4.2690 1.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 10 | 5.1350 1.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 11 | 6.0010 1.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 12 | 6.0010 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 13 | 3.4030 -0.5000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 14 | 1 9 1 0 0 0 0 15 | 2 9 2 0 0 0 0 16 | 3 4 1 0 0 0 0 17 | 3 8 2 0 0 0 0 18 | 4 5 2 0 0 0 0 19 | 4 9 1 0 0 0 0 20 | 5 6 1 0 0 0 0 21 | 6 7 2 0 0 0 0 22 | 7 8 1 0 0 0 0 23 | M END 24 | -------------------------------------------------------------------------------- /examples/0001018_rnd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/examples/0001018_rnd.png -------------------------------------------------------------------------------- /examples/0001608_rnd.mol: -------------------------------------------------------------------------------- 1 | 1608 2 | -INDIGO-12261221092D 3 | 4 | 10 10 0 0 0 0 0 0 0 0999 V2000 5 | 2.0000 -1.5600 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0 6 | 3.7320 -2.5600 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0 7 | 4.5981 1.9400 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 8 | 3.7320 0.4400 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 9 | 3.7320 1.4400 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 10 | 2.8660 -0.0600 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 11 | 4.5981 -0.0600 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 12 | 2.8660 -1.0600 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 13 | 4.5981 -1.0600 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 14 | 3.7320 -1.5600 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 15 | 1 8 1 0 0 0 0 16 | 2 10 1 0 0 0 0 17 | 3 5 1 0 0 0 0 18 | 4 5 1 0 0 0 0 19 | 4 6 2 0 0 0 0 20 | 4 7 1 0 0 0 0 21 | 6 8 1 0 0 0 0 22 | 7 9 2 0 0 0 0 23 | 8 10 2 0 0 0 0 24 | 9 10 1 0 0 0 0 25 | M END 26 | -------------------------------------------------------------------------------- /examples/0001608_rnd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/examples/0001608_rnd.png -------------------------------------------------------------------------------- /examples/0002057_rnd.mol: -------------------------------------------------------------------------------- 1 | 2057 2 | -INDIGO-12261221092D 3 | 4 | 22 23 0 0 0 0 0 0 0 0999 V2000 5 | 2.5369 -2.9050 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 6 | 8.5991 1.5950 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 7 | 4.2690 -3.9050 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 8 | 3.4030 0.5950 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 9 | 8.5991 3.5950 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 10 | 6.8671 -0.4050 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 11 | 4.2690 -0.9050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 12 | 6.0010 2.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 13 | 4.2690 0.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 14 | 5.1350 1.5950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 15 | 5.1350 0.5950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 16 | 3.4030 -1.4050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 17 | 6.8671 1.5950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 18 | 5.1350 -1.4050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 19 | 6.0010 3.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 20 | 3.4030 -2.4050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 21 | 7.7331 2.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 22 | 4.2690 -2.9050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 23 | 5.1350 -2.4050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 24 | 7.7331 3.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 25 | 6.8671 3.5950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 26 | 6.0010 0.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 27 | 1 16 1 0 0 0 0 28 | 2 17 1 0 0 0 0 29 | 3 18 1 0 0 0 0 30 | 4 9 2 0 0 0 0 31 | 5 20 1 0 0 0 0 32 | 6 22 3 0 0 0 0 33 | 7 9 1 0 0 0 0 34 | 7 12 2 0 0 0 0 35 | 7 14 1 0 0 0 0 36 | 8 10 1 0 0 0 0 37 | 8 13 2 0 0 0 0 38 | 8 15 1 0 0 0 0 39 | 9 11 1 0 0 0 0 40 | 10 11 2 0 0 0 0 41 | 11 22 1 0 0 0 0 42 | 12 16 1 0 0 0 0 43 | 13 17 1 0 0 0 0 44 | 14 19 2 0 0 0 0 45 | 15 21 2 0 0 0 0 46 | 16 18 2 0 0 0 0 47 | 17 20 2 0 0 0 0 48 | 18 19 1 0 0 0 0 49 | 20 21 1 0 0 0 0 50 | M END 51 | -------------------------------------------------------------------------------- /examples/0002057_rnd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/examples/0002057_rnd.png -------------------------------------------------------------------------------- /examples/0002708_rnd.mol: -------------------------------------------------------------------------------- 1 | 2708 2 | -INDIGO-12261221092D 3 | 4 | 19 19 0 0 0 0 0 0 0 0999 V2000 5 | 2.8660 4.6550 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0 6 | 6.3301 4.6550 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0 7 | 2.8660 -4.3450 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 8 | 2.0000 -2.8450 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 9 | 4.5981 2.6550 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 10 | 4.5981 1.6550 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 11 | 4.5981 -1.3450 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 12 | 4.5981 -0.3450 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 13 | 3.7320 -1.8450 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 14 | 5.4641 3.1550 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 15 | 3.7320 3.1550 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 16 | 3.7320 1.1550 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 17 | 5.4641 1.1550 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 18 | 3.7320 0.1550 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 19 | 5.4641 0.1550 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 20 | 3.7320 -2.8450 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 21 | 5.4641 4.1550 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 22 | 3.7320 4.1550 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 23 | 2.8660 -3.3450 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 24 | 1 18 1 0 0 0 0 25 | 2 17 1 0 0 0 0 26 | 3 19 1 0 0 0 0 27 | 4 19 2 0 0 0 0 28 | 5 6 1 0 0 0 0 29 | 5 10 1 0 0 0 0 30 | 5 11 1 0 0 0 0 31 | 6 12 2 0 0 0 0 32 | 6 13 1 0 0 0 0 33 | 7 8 1 0 0 0 0 34 | 7 9 1 0 0 0 0 35 | 8 14 2 0 0 0 0 36 | 8 15 1 0 0 0 0 37 | 9 16 1 0 0 0 0 38 | 10 17 1 0 0 0 0 39 | 11 18 1 0 0 0 0 40 | 12 14 1 0 0 0 0 41 | 13 15 2 0 0 0 0 42 | 16 19 1 0 0 0 0 43 | M END 44 | -------------------------------------------------------------------------------- /examples/0002708_rnd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggasoftware/imago/caad7d33dc9d39a84c869c71b82032b76d693d2a/examples/0002708_rnd.png -------------------------------------------------------------------------------- /imago-version.cmake: -------------------------------------------------------------------------------- 1 | SET(IMAGO_VERSION "2.0.0") 2 | 3 | IF($ENV{BUILD_NUMBER}) 4 | SET(IMAGO_BUILD_VERSION $ENV{BUILD_NUMBER}) 5 | ELSE() 6 | SET(IMAGO_BUILD_VERSION 0) 7 | ENDIF() 8 | 9 | SET(IMAGO_VERSION_EXT "${IMAGO_VERSION}.${IMAGO_BUILD_VERSION} ${PACKAGE_SUFFIX}") 10 | -------------------------------------------------------------------------------- /imago/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(ImagoLib) 2 | 3 | file(GLOB SRC src/*.cpp) 4 | 5 | FILE(GLOB HEADERS "src/*.h") 6 | list(APPEND SRC ${HEADERS}) 7 | 8 | add_library(imago STATIC ${SRC}) 9 | 10 | target_link_libraries(imago ${CMAKE_THREAD_LIBS_INIT}) 11 | target_link_libraries(imago ${Indigo_LIBRARIES}) 12 | target_link_libraries(imago ${OpenCV_LIBS}) 13 | target_link_libraries(imago ${Boost_LIBRARIES}) 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /imago/src/algebra.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _math_h 17 | #define _math_h 18 | 19 | #include "vec2d.h" 20 | #include 21 | #include "settings.h" 22 | 23 | namespace imago 24 | { 25 | class Rectangle; 26 | 27 | struct Line 28 | { 29 | double A, B, C; 30 | }; 31 | 32 | class Algebra 33 | { 34 | public: 35 | /** 36 | * @brief Distance from point to segment 37 | * 38 | * @param v point 39 | * @param b begin point of segment 40 | * @param e end point of segment 41 | * 42 | * @return 43 | */ 44 | static double distance2segment( const Vec2d &v, const Vec2d &b, const Vec2d &e ); 45 | 46 | static double distance2rect( const Vec2d &p, int x, int y, int width, int height ); 47 | 48 | static double distance2rect( const Vec2d &p, const Rectangle &r ); 49 | 50 | static Line points2line( const Vec2d &b, const Vec2d &e ); 51 | 52 | static Vec2d linesIntersection(const Settings& vars, const Vec2d &p11, const Vec2d &p12, const Vec2d &p21, const Vec2d &p22 ); 53 | 54 | static Vec2d linesIntersection(const Settings& vars, const Line &l1, const Line &l2 ); 55 | 56 | static double slope( const Vec2d &b, const Vec2d &e ); 57 | 58 | static double pointProjectionCoef( const Vec2d &orig, const Vec2d &to_begin , const Vec2d &to_end ); 59 | 60 | static std::pair segmentProjection( const Vec2d &orig_begin , const Vec2d &orig_end, const Vec2d &to_begin , const Vec2d &to_end ); 61 | 62 | static bool segmentsParallel( const Vec2d &b1, const Vec2d &e1, const Vec2d &b2, const Vec2d &e2, double eps, double *dist = 0 ); 63 | 64 | static bool rangesSeparable (double range1_bound1, double range1_bound2, double range2_bound1, double range2_bound2); 65 | 66 | static bool SegmentsOnSameLine(const Settings& vars, Vec2d &b1, Vec2d &e1, Vec2d &b2, Vec2d &e2); 67 | }; 68 | } 69 | #endif /* _math_h */ 70 | -------------------------------------------------------------------------------- /imago/src/approximator.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _approximator_h 17 | #define _approximator_h 18 | 19 | #include "vec2d.h" 20 | #include "stl_fwd.h" 21 | #include "settings.h" 22 | 23 | namespace imago 24 | { 25 | class BaseApproximator 26 | { 27 | public: 28 | virtual void apply(const Settings& vars, double eps, const Points2d &input, Points2d &output ) const = 0; 29 | }; 30 | 31 | class CvApproximator: public BaseApproximator 32 | { 33 | public: 34 | void apply(const Settings& vars, double eps, const Points2d &input, Points2d &output ) const; 35 | }; 36 | 37 | class DPApproximator: public BaseApproximator 38 | { 39 | void _apply_int( double eps, const Points2d &input, Points2d &output ) const; 40 | public: 41 | void apply(const Settings& vars, double eps, const Points2d &input, Points2d &output ) const; 42 | }; 43 | } 44 | #endif /* _approximator_h */ 45 | -------------------------------------------------------------------------------- /imago/src/basic_2d_storage.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _basic_2d_storage_h 17 | #define _basic_2d_storage_h 18 | 19 | namespace imago 20 | { 21 | // two-dimensional storage for specified type data 22 | template class Basic2dStorage 23 | { 24 | public: 25 | // initialize dimensions and data pointer, fill with zero, fast 26 | Basic2dStorage(int width, int height) 27 | { 28 | _w = width; 29 | _h = height; 30 | data = new t[_w*_h](); 31 | } 32 | 33 | // initialize dimensions and data pointer, fill with 'value' 34 | Basic2dStorage(int width, int height, t value) 35 | { 36 | _w = width; 37 | _h = height; 38 | data = new t[_w * _h]; 39 | for (int u = 0; u < _w*_h; u++) 40 | data[u] = value; 41 | } 42 | 43 | // delete data pointer 44 | virtual ~Basic2dStorage() 45 | { 46 | if (data) 47 | delete []data; 48 | } 49 | 50 | // index operator 51 | const t& at(int x, int y) const 52 | { 53 | return data[x + y * _w]; 54 | } 55 | 56 | // index operator 57 | t& at(int x, int y) 58 | { 59 | return data[x + y * _w]; 60 | } 61 | 62 | // dimensions getters 63 | int width() const { return _w; } 64 | int height() const { return _h; } 65 | 66 | // return true if point (x,y) fits in storage 67 | bool inRange(int x, int y) const 68 | { 69 | return x >= 0 && y >= 0 && x < _w && y < _h; 70 | } 71 | 72 | private: 73 | int _w, _h; 74 | t* data; 75 | }; 76 | } 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /imago/src/character_recognizer.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _character_recognizer_h 17 | #define _character_recognizer_h 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "segment.h" 24 | #include "stl_fwd.h" 25 | #include "recognition_distance.h" 26 | #include "segment_tools.h" 27 | #include "settings.h" 28 | 29 | namespace imago 30 | { 31 | class Segment; 32 | 33 | class CharacterRecognizer 34 | { 35 | public: 36 | bool isPossibleCharacter(const Settings& vars, const Segment& seg, 37 | bool loose_cmp = false, char* result = NULL); 38 | 39 | RecognitionDistance recognize(const Settings& vars, const Segment &seg, 40 | const std::string &candidates = all) const; 41 | 42 | virtual ~CharacterRecognizer() { }; 43 | 44 | static const std::string upper; 45 | static const std::string lower; 46 | static const std::string digits; 47 | static const std::string charges; 48 | static const std::string brackets; 49 | static const std::string all; 50 | static const std::string graphics; 51 | static const std::string like_bonds; 52 | 53 | private: 54 | static qword getSegmentHash(const Segment &seg); 55 | }; 56 | 57 | namespace CharacterRecognizerImp 58 | { 59 | const int REQUIRED_SIZE = 30; 60 | const int PENALTY_SHIFT = 1; 61 | const int PENALTY_STEP = 1; 62 | 63 | // used for technical reasons, do not modify 64 | const int PENALTY_WHITE_FACTOR = 32; 65 | const int CHARACTERS_OFFSET = 32; 66 | const int INTERNAL_ARRAY_DIM = REQUIRED_SIZE + 2*PENALTY_SHIFT; 67 | const int INTERNAL_ARRAY_SIZE = INTERNAL_ARRAY_DIM * INTERNAL_ARRAY_DIM; 68 | 69 | struct MatchRecord 70 | { 71 | unsigned char penalty_ink[INTERNAL_ARRAY_SIZE]; 72 | unsigned char penalty_white[INTERNAL_ARRAY_SIZE]; 73 | std::string text; 74 | double wh_ratio; 75 | }; 76 | 77 | typedef std::vector Templates; 78 | 79 | void calculatePenalties(const cv::Mat1b& img, unsigned char* penalty_ink, unsigned char* penalty_white); 80 | double compareImages(const cv::Mat1b& img, const unsigned char* penalty_ink, const unsigned char* penalty_white); 81 | cv::Mat1b prepareImage(const Settings& vars, const cv::Mat1b& src, double &ratio); 82 | bool initializeTemplates(const Settings& vars, const std::string& path, Templates& templates); 83 | RecognitionDistance recognizeMat(const Settings& vars, const cv::Mat1b& image, const Templates& templates); 84 | }; 85 | } 86 | 87 | #endif /* _character_recognizer_h */ 88 | -------------------------------------------------------------------------------- /imago/src/chemical_structure_recognizer.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _chemical_structure_recognizer_h 17 | #define _chemical_structure_recognizer_h 18 | 19 | #include "image.h" 20 | #include "character_recognizer.h" 21 | #include "stl_fwd.h" 22 | #include "settings.h" 23 | 24 | namespace imago 25 | { 26 | class Molecule; 27 | class Segment; 28 | class CharacterRecognizer; 29 | 30 | class ChemicalStructureRecognizer 31 | { 32 | public: 33 | ChemicalStructureRecognizer(); 34 | 35 | void setImage( Image &img ); 36 | void recognize( Settings& vars, Molecule &mol); 37 | void image2mol( Settings& vars, Image &img, Molecule &mol ); 38 | void extractCharacters (Settings& vars, Image& img); 39 | const CharacterRecognizer &getCharacterRecognizer() { return _cr; }; 40 | 41 | ~ChemicalStructureRecognizer(); 42 | 43 | private: 44 | CharacterRecognizer _cr; 45 | Image _origImage; 46 | 47 | bool removeMoleculeCaptions(const Settings& vars, Image& img, SegmentDeque& layer_symbols, SegmentDeque& layer_graphics); 48 | void segmentate(const Settings& vars, Image& img, SegmentDeque& segments, bool connect_mode = false); 49 | void storeSegments(const Settings& vars, SegmentDeque& layer_symbols, SegmentDeque& layer_graphics); 50 | bool isReconnectSegmentsRequired(const Settings& vars, const Image& img, const SegmentDeque& segments); 51 | 52 | ChemicalStructureRecognizer( const ChemicalStructureRecognizer &csr ); 53 | }; 54 | } 55 | 56 | 57 | #endif /* _chemical_structure_recognizer_h */ 58 | -------------------------------------------------------------------------------- /imago/src/chemical_validity.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _chemical_validity_h 17 | #define _chemical_validity_h 18 | 19 | #include 20 | #include 21 | #include 22 | #include "superatom.h" 23 | 24 | namespace imago 25 | { 26 | class ChemicalValidity 27 | { 28 | public: 29 | // fills internal elements table 30 | ChemicalValidity(); 31 | 32 | // returns probability of superatom existence 33 | double getLabelProbability(const Superatom& sa) const; 34 | 35 | // updates the non-existent atom to the most close existent alternative 36 | void updateAlternative(Superatom& sa) const; 37 | 38 | private: 39 | typedef std::vector Strings; 40 | typedef std::map Probabilities; 41 | 42 | struct ElementTableEntry 43 | { 44 | Strings names; 45 | Probabilities probability; 46 | 47 | // helper function to initialize both names and probability 48 | void push_back(const std::string& name, double prob = 1.0); 49 | }; 50 | 51 | ElementTableEntry elements; 52 | typedef std::map HacksMap; 53 | HacksMap hacks; 54 | 55 | protected: 56 | // returns optimal string split by specified dictionary 57 | static Strings optimalSplit(const std::string& input, const Strings& dictionary); 58 | 59 | // calculates split probability against the 'elements' information 60 | double calcSplitProbability(const Strings& split) const; 61 | 62 | // returns if atom (short form, one atom) is probable 63 | bool isProbable(const std::string& atom) const; 64 | 65 | // returns list of alternative characters 66 | std::string getAlternatives(char base_char, const RecognitionDistance& d) const; 67 | 68 | typedef std::vector AtomRefs; 69 | // subtask of the updateAlternative function 70 | bool optimizeAtomGroup(AtomRefs& data) const; 71 | }; 72 | } 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /imago/src/comdef.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | /** 16 | * @file comdef.h 17 | * 18 | * @brief Common definitions 19 | */ 20 | 21 | #pragma once 22 | #ifndef _comdef_h 23 | #define _comdef_h 24 | 25 | #include 26 | #include 27 | 28 | #include "boost/graph/properties.hpp" 29 | namespace boost 30 | { 31 | enum vertex_seg_ptr_t { vertex_seg_ptr }; 32 | enum vertex_pos_t { vertex_pos }; 33 | enum edge_type_t { edge_type }; 34 | BOOST_INSTALL_PROPERTY(vertex, seg_ptr); 35 | BOOST_INSTALL_PROPERTY(vertex, pos); 36 | BOOST_INSTALL_PROPERTY(edge, type); 37 | } 38 | 39 | #ifdef _WIN32 40 | 41 | #define DLLEXPORT __declspec(dllexport) 42 | #define qword unsigned _int64 43 | 44 | #else 45 | 46 | #define DLLEXPORT 47 | #define qword unsigned long long 48 | 49 | #endif /* _WIN32 */ 50 | 51 | namespace imago 52 | { 53 | typedef unsigned char byte; 54 | typedef unsigned short word; 55 | typedef unsigned int dword; 56 | 57 | const double EPS = 1e-10; 58 | const double DIST_INF = 1e10; 59 | const unsigned int MAX_TEXT_LINE = 1024; 60 | 61 | const double PI = 3.14159265358979323846; 62 | const float TWO_PI_f = 6.2831853071794f; 63 | const double HALF_PI = 1.57079632679489661923; 64 | 65 | template int round(const T& a) 66 | { 67 | if (a >= 0) return (int)(a + 0.5); 68 | else return (int)(a - 0.5); 69 | } 70 | 71 | template T absolute(const T& a) 72 | { 73 | return a > 0 ? a : -a; 74 | } 75 | 76 | template int sign(const T& x) 77 | { 78 | return (x > 0) ? 1 : ((x < 0) ? -1 : 0); 79 | } 80 | 81 | template T square(const T& a) 82 | { 83 | return a * a; 84 | } 85 | 86 | static inline std::string upper(const std::string& in) 87 | { 88 | std::string data = in; 89 | std::transform(data.begin(), data.end(), data.begin(), ::toupper); 90 | return data; 91 | } 92 | 93 | static inline std::string lower(const std::string& in) 94 | { 95 | std::string data = in; 96 | std::transform(data.begin(), data.end(), data.begin(), ::tolower); 97 | return data; 98 | } 99 | } 100 | 101 | #endif /* _comdef_h */ 102 | -------------------------------------------------------------------------------- /imago/src/complex_contour.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | /** 16 | * @file complex_number.h 17 | * 18 | * @brief Complex numbers 19 | */ 20 | 21 | #pragma once 22 | #ifndef _complex_contour_h 23 | #define _complex_contour_h 24 | 25 | #include "complex_number.h" 26 | #include "stl_fwd.h" 27 | #include "settings.h" 28 | #include 29 | #include 30 | #include "graphics_detector.h" 31 | 32 | namespace imago{ 33 | 34 | class ComplexContour 35 | { 36 | public: 37 | ComplexContour(void); 38 | ComplexContour(const std::vector& conts) : _contours(conts) 39 | { 40 | } 41 | 42 | ComplexContour(const std::string& data) 43 | { 44 | std::stringstream s(data); 45 | double real, im; 46 | _contours.clear(); 47 | 48 | while(!s.eof()) 49 | { 50 | s >> real; 51 | s >> im; 52 | ComplexNumber c(real, im); 53 | _contours.push_back(c); 54 | } 55 | } 56 | 57 | ~ComplexContour(void); 58 | 59 | ComplexNumber& getContour(int shift); 60 | const ComplexNumber& getContour(int shift) const; 61 | 62 | double DiffR2(const ComplexContour& lc) const; 63 | 64 | double Norm() const; 65 | 66 | ComplexNumber Dot(const ComplexContour& c, int shift=0) const; 67 | 68 | std::vector InterCorrelation(const ComplexContour& c); 69 | 70 | std::vector AutoCorrelation(bool normalize); 71 | 72 | ComplexNumber FindMaxNorm() const; 73 | 74 | void Scale(double scale); 75 | 76 | void Normalize(); 77 | 78 | void NormalizeByPerimeter(); 79 | 80 | double getNorm() const; 81 | 82 | double Distance(const ComplexContour& c); 83 | 84 | void Equalize(int n); 85 | 86 | static ComplexContour RetrieveContour(const Settings& vars, Image& seg, bool fine_detail = false); 87 | 88 | ComplexNumber NormDot(const ComplexContour& c) const 89 | { 90 | int count = _contours.size(); 91 | double norm1 = 0, 92 | norm2 = 0; 93 | ComplexNumber S; 94 | 95 | for(int i=0; i < count; i++) 96 | { 97 | S += ComplexNumber::Dot(_contours[i], c.getContour(i)); 98 | norm1 += _contours[i].getRadius2(); 99 | norm2 += c.getContour(i).getRadius2(); 100 | } 101 | 102 | double k = 1.0 / std::sqrt(norm1 * norm2); 103 | S *= k; 104 | return S; 105 | } 106 | 107 | int Size() const 108 | { 109 | return _contours.size(); 110 | } 111 | private: 112 | 113 | void EqualizeUp(int n); 114 | void EqualizeDown(int n); 115 | std::vector _contours; 116 | }; 117 | } 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /imago/src/complex_number.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #include "complex_number.h" 16 | #include 17 | 18 | using namespace imago; 19 | 20 | 21 | 22 | ComplexNumber::ComplexNumber(double Real, double Imaginary) 23 | { 24 | _a = Real; 25 | _b = Imaginary; 26 | } 27 | 28 | ComplexNumber& ComplexNumber::operator*() 29 | { 30 | return *this; 31 | } 32 | 33 | const ComplexNumber& ComplexNumber::operator*() const 34 | { 35 | return *this; 36 | } 37 | 38 | ComplexNumber& ComplexNumber::operator+ (const ComplexNumber& n2) 39 | { 40 | _a += n2.getReal(); 41 | _b += n2.getImaginary(); 42 | return *this; 43 | } 44 | 45 | ComplexNumber& ComplexNumber::operator/(double n) 46 | { 47 | _a /= n; 48 | _b/= n; 49 | return *this; 50 | } 51 | 52 | ComplexNumber& ComplexNumber::operator/=(double n) 53 | { 54 | _a /= n; 55 | _b /= n; 56 | return *this; 57 | } 58 | 59 | ComplexNumber& ComplexNumber::operator*(double n) 60 | { 61 | _a *= n; 62 | _b *= n; 63 | return *this; 64 | } 65 | 66 | ComplexNumber& ComplexNumber::operator*=(double n) 67 | { 68 | _a *= n; 69 | _b *= n; 70 | return *this; 71 | } 72 | 73 | ComplexNumber ComplexNumber::Dot(const ComplexNumber& n1, const ComplexNumber& n2) 74 | { 75 | double a1 = n1.getReal(); 76 | double a2 = n2.getReal(); 77 | double b1 = n1.getImaginary(); 78 | double b2 = n2.getImaginary(); 79 | 80 | return ComplexNumber(a1*a2 + b1*b2, b1*a2-a1*b2) ; 81 | } 82 | 83 | ComplexNumber ComplexNumber::operator *(const ComplexNumber& n2) 84 | { 85 | double radius = getRadius() * n2.getRadius(); 86 | double angle = getAngle() + n2.getAngle(); 87 | 88 | return ComplexNumber(radius * cos(angle), radius * sin(angle)); 89 | } -------------------------------------------------------------------------------- /imago/src/complex_number.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | /** 16 | * @file complex_number.h 17 | * 18 | * @brief Complex numbers 19 | */ 20 | 21 | #pragma once 22 | #ifndef _complex_number_h 23 | #define _complex_number_h 24 | 25 | #include 26 | 27 | 28 | namespace imago{ 29 | 30 | class ComplexNumber 31 | { 32 | public: 33 | ComplexNumber():_a(0.0), _b(0.0) 34 | {} 35 | 36 | ComplexNumber(double Real, double Imaginary); 37 | 38 | inline double getReal() const 39 | { return _a; } 40 | 41 | inline void setReal(double a) 42 | { _a = a;} 43 | 44 | inline double getImaginary() const 45 | { return _b; } 46 | 47 | inline void setImaginary(double b) 48 | { _b = b;} 49 | 50 | static ComplexNumber Dot(const ComplexNumber& n1, const ComplexNumber& n2); 51 | 52 | ComplexNumber& operator*(); 53 | 54 | const ComplexNumber& operator*() const; 55 | 56 | ComplexNumber& operator +(const ComplexNumber& n2); 57 | 58 | ComplexNumber& operator +=(const ComplexNumber& cn) 59 | { 60 | _a += cn.getReal(); 61 | _b += cn.getImaginary(); 62 | return *this; 63 | } 64 | 65 | ComplexNumber operator -(const ComplexNumber& n) 66 | { 67 | return ComplexNumber(_a - n.getReal(), _b - n.getImaginary()); 68 | } 69 | 70 | ComplexNumber& operator /(double n); 71 | 72 | ComplexNumber& operator*(double n); 73 | 74 | ComplexNumber& operator /=(double n); 75 | 76 | ComplexNumber& operator *=(double n); 77 | 78 | inline double getAngle() const 79 | { 80 | return atan2(_b, _a); 81 | } 82 | 83 | inline double getRadius() const 84 | { 85 | return sqrt(getRadius2()); 86 | } 87 | 88 | inline double getRadius2() const 89 | { 90 | return _a * _a + _b * _b; 91 | } 92 | 93 | ComplexNumber operator *(const ComplexNumber& n2); 94 | 95 | private: 96 | double _a, _b; 97 | }; 98 | } 99 | #endif 100 | -------------------------------------------------------------------------------- /imago/src/double_bond_maker.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _double_bond_maker_h 17 | #define _double_bond_maker_h 18 | 19 | #include "boost/graph/graph_traits.hpp" 20 | #include "boost/tuple/tuple.hpp" 21 | #include "skeleton.h" 22 | #include "settings.h" 23 | 24 | namespace imago 25 | { 26 | class DoubleBondMaker 27 | { 28 | private: 29 | typedef Skeleton::Vertex Vertex; 30 | typedef Skeleton::Edge Edge; 31 | typedef Skeleton::SkeletonGraph Graph; 32 | public: 33 | DoubleBondMaker( const Settings& settings, Skeleton &s ); 34 | 35 | typedef boost::tuple Result; 36 | 37 | Result operator()( std::pair edges ); 38 | 39 | virtual ~DoubleBondMaker(); 40 | private: 41 | Edge empty; 42 | Edge first, second; 43 | Bond bf, bs; 44 | Vertex fb, fe, sb, se; 45 | Vec2d fb_pos, fe_pos, sb_pos, se_pos; 46 | 47 | Result _validateVertices(); 48 | 49 | DoubleBondMaker( const DoubleBondMaker & ); 50 | 51 | Result _simple(); 52 | 53 | Result _hard(); 54 | 55 | void _disconnect( Vertex a, Vertex b, const Vertex *third ); 56 | Skeleton &_s; 57 | Graph &_g; 58 | double _avgBondLength; 59 | 60 | const Settings& vars; 61 | }; 62 | 63 | template class DoubleBondComparator 64 | { 65 | public: 66 | DoubleBondComparator( Graph &g ) : _g(g) 67 | { 68 | types = boost::get(boost::edge_type, _g); 69 | } 70 | typedef typename boost::graph_traits::edge_descriptor Edge; 71 | int operator() ( const std::pair &a, 72 | const std::pair &b ) 73 | { 74 | double average_len_a = 0.5 * (types[a.first].length + types[a.second].length); 75 | double average_len_b = 0.5 * (types[b.first].length + types[b.second].length); 76 | return average_len_a > average_len_b; 77 | } 78 | private: 79 | typename boost::property_map::type 80 | types; 81 | Graph &_g; 82 | }; 83 | } 84 | 85 | #endif /* _double_bond_maker_h */ 86 | 87 | -------------------------------------------------------------------------------- /imago/src/exception.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | /** 16 | * @file exception.h 17 | * 18 | * @brief Declares Exception class 19 | */ 20 | 21 | #pragma once 22 | #ifndef _exception_h 23 | #define _exception_h 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "comdef.h" 32 | 33 | namespace imago 34 | { 35 | class ImagoException : public std::runtime_error 36 | { 37 | public: 38 | ImagoException(const std::string& error) : std::runtime_error(error) { } 39 | ImagoException(int errorCode) : std::runtime_error(str(errorCode)) { } 40 | 41 | static std::string str(int x) 42 | { 43 | char buffer[32]; 44 | sprintf(buffer, "%i", x); 45 | return buffer; 46 | } 47 | }; 48 | 49 | class OutOfBoundsException : public ImagoException 50 | { 51 | public: 52 | OutOfBoundsException(const std::string& error, int index1, int index2) 53 | : ImagoException(error + " index(" + str(index1) + ", " + str(index2) + ")") { } 54 | }; 55 | 56 | class NoContourException : public ImagoException 57 | { 58 | public: 59 | NoContourException(const std::string& error) : ImagoException(error) { } 60 | }; 61 | 62 | class LabelException : public ImagoException 63 | { 64 | public: 65 | LabelException(const std::string& error) : ImagoException(error) { } 66 | }; 67 | 68 | class FileNotFoundException : public ImagoException 69 | { 70 | public: 71 | FileNotFoundException(const std::string& error) : ImagoException(error) { } 72 | }; 73 | 74 | class LogicException : public ImagoException 75 | { 76 | public: 77 | LogicException(const std::string& error) : ImagoException(error) { } 78 | LogicException(const int errorCode) : ImagoException("code: " + str(errorCode)) { } 79 | }; 80 | 81 | class IOException : public ImagoException 82 | { 83 | public: 84 | IOException(const std::string& error) : ImagoException(error) { } 85 | }; 86 | 87 | class DivizionByZeroException : public ImagoException 88 | { 89 | public: 90 | DivizionByZeroException(const std::string& error) : ImagoException(error) { } 91 | }; 92 | 93 | class OCRException : public ImagoException 94 | { 95 | public: 96 | OCRException(const std::string& error) : ImagoException(error) { } 97 | }; 98 | } 99 | 100 | #endif /* _exception_h */ 101 | -------------------------------------------------------------------------------- /imago/src/failsafe_png.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _failsafe_png_h 17 | #define _failsafe_png_h 18 | 19 | #include "image.h" 20 | #include 21 | 22 | namespace imago 23 | { 24 | bool failsafePngLoadBuffer(const unsigned char* buffer, size_t buf_size, Image& img); 25 | bool failsafePngLoadFile(const std::string& fname, Image& img); 26 | } 27 | 28 | #endif // _failsafe_png_h 29 | -------------------------------------------------------------------------------- /imago/src/file_helpers.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | 17 | #ifndef _file_helpers_h_ 18 | #define _file_helpers_h_ 19 | 20 | #include 21 | #include 22 | 23 | typedef std::vector strings; 24 | 25 | namespace file_helpers 26 | { 27 | size_t getLastSlashPos(const std::string& filename); 28 | bool getReferenceFileName(const std::string& image, std::string& output); 29 | bool getOnlyFileName(const std::string& image, std::string& output); 30 | int getDirectoryContent(const std::string& dir, strings &files, bool recursive); 31 | bool isSupportedImageType(const std::string& filename); 32 | void filterOnlyImages(strings& files); 33 | } 34 | 35 | #endif // _file_helpers_h_ 36 | -------------------------------------------------------------------------------- /imago/src/filters_list.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #include "filters_list.h" 16 | #include "prefilter_basic.h" 17 | #include "prefilter_retinex.h" 18 | 19 | namespace imago 20 | { 21 | FilterEntryDefinition::FilterEntryDefinition(const std::string& _name, int _priority, FilterFunction _f, const std::string& _config, ConditionFunction _c) 22 | { 23 | name = _name; 24 | priority = _priority; 25 | routine = _f; 26 | condition = _c; 27 | update_config_string = _config; 28 | } 29 | 30 | FilterEntries::FilterEntries() 31 | { 32 | push_back(FilterEntryDefinition("prefilter_binarized", 1, prefilter_basic::prefilterBinarizedFullsize, 33 | "general.ImageAlreadyBinarized = 1;")); 34 | 35 | push_back(FilterEntryDefinition("prefilter_retinex", 2, prefilter_retinex::prefilterRetinexDownscaleOnly)); 36 | 37 | push_back(FilterEntryDefinition("prefilter_basic_s", 3, prefilter_basic::prefilterBasicForceDownscale)); 38 | 39 | push_back(FilterEntryDefinition("prefilter_basic", 4, prefilter_basic::prefilterBasicFullsize)); 40 | } 41 | 42 | FilterEntries getFiltersList() 43 | { 44 | static FilterEntries result; 45 | return result; 46 | } 47 | }; 48 | -------------------------------------------------------------------------------- /imago/src/filters_list.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _filters_list_h 17 | #define _filters_list_h 18 | 19 | #include 20 | #include 21 | #include "image.h" 22 | #include "settings.h" 23 | 24 | namespace imago 25 | { 26 | struct FilterEntryDefinition 27 | { 28 | typedef bool(*ConditionFunction)(const Image&); 29 | typedef bool(*FilterFunction)(Settings&, Image&); 30 | 31 | std::string name; 32 | std::string update_config_string; 33 | int priority; 34 | ConditionFunction condition; 35 | FilterFunction routine; 36 | 37 | FilterEntryDefinition(const std::string& _name, int _priority, FilterFunction _f, 38 | const std::string& _config = "", ConditionFunction _c = NULL); 39 | }; 40 | 41 | class FilterEntries : public std::vector 42 | { 43 | public: 44 | FilterEntries(); 45 | }; 46 | 47 | FilterEntries getFiltersList(); 48 | } 49 | 50 | #endif // _filters_list_h 51 | -------------------------------------------------------------------------------- /imago/src/fonts_list.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #include "fonts_list.h" 16 | 17 | namespace imago 18 | { 19 | FontEntryDefinition::FontEntryDefinition(const std::string& _name, const std::string& _data) 20 | { 21 | name = _name; 22 | data = _data; 23 | } 24 | 25 | FontEntries::FontEntries() 26 | { 27 | #define LENGTH(x) sizeof(x) / sizeof(int) 28 | 29 | // TODO: currently not used, decide: eliminate or transform 30 | /*{ 31 | const char* data[] = 32 | { 33 | #include "imago.font.inc" 34 | }; 35 | 36 | std::string temp; 37 | for (int i = 0; i < (sizeof(data) / sizeof(char*)) && data[i] != 0; i++) 38 | { 39 | temp += data[i]; 40 | } 41 | 42 | push_back(FontEntryDefinition("base", temp)); 43 | }*/ 44 | } 45 | 46 | FontEntries getFontsList() 47 | { 48 | static FontEntries result; 49 | return result; 50 | } 51 | }; -------------------------------------------------------------------------------- /imago/src/fonts_list.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _fonts_list_h 17 | #define _fonts_list_h 18 | 19 | #include 20 | #include 21 | 22 | namespace imago 23 | { 24 | struct FontEntryDefinition 25 | { 26 | std::string name; 27 | std::string data; 28 | 29 | FontEntryDefinition(const std::string& _name, const std::string& _data); 30 | }; 31 | 32 | class FontEntries : public std::vector 33 | { 34 | public: 35 | FontEntries(); 36 | }; 37 | 38 | FontEntries getFontsList(); 39 | } 40 | 41 | #endif // _fonts_list_h 42 | -------------------------------------------------------------------------------- /imago/src/graph_extractor.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #include 16 | 17 | #include "boost/foreach.hpp" 18 | 19 | #include "comdef.h" 20 | #include "log_ext.h" 21 | #include "graph_extractor.h" 22 | #include "graphics_detector.h" 23 | #include "image_utils.h" 24 | #include "image_draw_utils.h" 25 | #include "segment.h" 26 | #include "skeleton.h" 27 | 28 | using namespace imago; 29 | 30 | void GraphExtractor::extract(Settings& vars, const GraphicsDetector &gd, const SegmentDeque &segments, Skeleton &graph ) 31 | { 32 | logEnterFunction(); 33 | 34 | Image tmp; 35 | int w = 0, h = 0; 36 | 37 | // recreate image from segments 38 | BOOST_FOREACH( Segment *s, segments ) 39 | { 40 | if (s->getX() + s->getWidth() >= w) 41 | w = s->getX() + s->getWidth(); 42 | if (s->getY() + s->getHeight() >= h) 43 | h = s->getY() + s->getHeight(); 44 | } 45 | 46 | tmp.init(w + 10, h + 10); 47 | tmp.fillWhite(); 48 | 49 | BOOST_FOREACH( Segment *s, segments ) 50 | { 51 | ImageUtils::putSegment(tmp, *s, true); 52 | } 53 | 54 | getLogExt().appendImage("Working image", tmp); 55 | 56 | extract(vars, gd, tmp, graph); 57 | } 58 | 59 | void GraphExtractor::extract(Settings& vars, const GraphicsDetector &gd, const Image &img, Skeleton &graph ) 60 | { 61 | logEnterFunction(); 62 | 63 | double avg_size = 0; 64 | Points2d lsegments; 65 | 66 | gd.detect(vars, img, lsegments); 67 | 68 | if (!lsegments.empty()) 69 | { 70 | for (size_t i = 0; i < lsegments.size() / 2; i++) 71 | { 72 | Vec2d &p1 = lsegments[2 * i]; 73 | Vec2d &p2 = lsegments[2 * i + 1]; 74 | 75 | double dist = Vec2d::distance(p1, p2); 76 | 77 | if (dist > 2.0) 78 | avg_size += dist; 79 | } 80 | 81 | avg_size /= (lsegments.size() / 2.0); 82 | 83 | graph.setInitialAvgBondLength(vars, avg_size); 84 | 85 | for (size_t i = 0; i < lsegments.size() / 2; i++) 86 | { 87 | Vec2d &p1 = lsegments[2 * i]; 88 | Vec2d &p2 = lsegments[2 * i + 1]; 89 | 90 | double dist = Vec2d::distance(p1, p2); 91 | 92 | if (dist > vars.graph.MinimalDistTresh) 93 | graph.addBond(p1, p2); 94 | } 95 | 96 | getLogExt().appendSkeleton(vars, "Source skeleton", (Skeleton::SkeletonGraph)graph); 97 | 98 | graph.modifyGraph(vars); 99 | 100 | getLogExt().appendSkeleton(vars, "Modified skeleton", (Skeleton::SkeletonGraph)graph); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /imago/src/graph_extractor.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _graph_extractor_h 17 | #define _graph_extractor_h 18 | 19 | #include "stl_fwd.h" 20 | #include "settings.h" 21 | 22 | namespace imago 23 | { 24 | class Graph; 25 | class Skeleton; 26 | class Image; 27 | class GraphicsDetector; 28 | 29 | struct GraphExtractor 30 | { 31 | static void extract( Settings& vars, const GraphicsDetector &gd, 32 | const SegmentDeque &segments, Skeleton &graph ); 33 | 34 | static void extract( Settings& vars, const GraphicsDetector &gd, 35 | const Image &img, Skeleton &graph ); 36 | }; 37 | } 38 | 39 | 40 | #endif /* _graph_extractor_h */ 41 | -------------------------------------------------------------------------------- /imago/src/graphics_detector.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2009-2013 GGA Software Services LLC 3 | * 4 | * This file is part of Imago OCR project. 5 | * 6 | * This file may be distributed and/or modified under the terms of the 7 | * GNU General Public License version 3 as published by the Free Software 8 | * Foundation and appearing in the file LICENSE.GPL included in the 9 | * packaging of this file. 10 | * 11 | * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12 | * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13 | ***************************************************************************/ 14 | 15 | #pragma once 16 | #ifndef _graphics_detector_h 17 | #define _graphics_detector_h 18 | 19 | #include "vec2d.h" 20 | #include "stl_fwd.h" 21 | #include "label_combiner.h" 22 | #include "settings.h" 23 | 24 | namespace imago 25 | { 26 | struct LineSegment 27 | { 28 | Vec2d b; 29 | Vec2d e; 30 | }; 31 | 32 | class Segment; 33 | class Image; 34 | class Molecule; 35 | class BaseApproximator; 36 | 37 | class GraphicsDetector 38 | { 39 | public: 40 | GraphicsDetector(); 41 | GraphicsDetector( const BaseApproximator *approximator, double eps ); 42 | void extractRingsCenters(const Settings& vars, SegmentDeque &segments, Points2d &ring_centers ) const; 43 | void analyzeUnmappedLabels( std::deque