Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #893 from Kumataro:freetype2
Browse files Browse the repository at this point in the history
* Support freetype2

* Before call pkg_search_module() check it is available.

* If using libraries are unavailable, this module is shown in unavailable list.

* using ocv_define_modules() insted of target_link_libraries().

* Fix inner indentation in C++ namespaces

* Remove mImg from freetype2 and Create UserData class to refer in path drawing callbacks.

* to split interface and implementation details.
( and to avoid 3rd headers in public headers)

* PKG_CONFIG_FOUND is used instead of COMMAND okg_search_modules

* Update Document using Doxygen

* Add ocv_module_include_directories()

* Do no put pixels over image boundaries.

* Fix SIGSEGV (only valgrind) and missing text in top border line

* Fix trailing whitespace.

* Use Header File Macros

* Fix CMP0023 warning in cmake

* std::string to cv::String

* Fix trailing whitespace

* Change splitnumber from unsigned int to int to support python

* ocv_include_directories() should be define before ocv_define_module()

* Fix boundary problem in putTextBitmapBlend()

* Fix to draw an outline glyph which are on the boundary of image.

* Remove precomp.cpp

* Fix CMakeLists.txt to right order.

* Remove prototype definition of removed function.

* Add CV_Assert() where FreeType and Harfbuzz are called

* Add CV_Assert() to check InputOutputArray and line_type
  • Loading branch information
Kumataro authored and alalek committed Dec 16, 2016
1 parent cf82f5f commit cac3c9a
Show file tree
Hide file tree
Showing 6 changed files with 772 additions and 18 deletions.
38 changes: 20 additions & 18 deletions modules/README.md
Expand Up @@ -34,38 +34,40 @@ $ cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -D BUILD_opencv_<r

13. **fuzzy**: Fuzzy Logic in Vision -- Fuzzy logic image transform and inverse; Fuzzy image processing.

14. **hdf**: Hierarchical Data Storage -- This module contains I/O routines for Hierarchical Data Format: https://en.m.wikipedia.org/wiki/Hierarchical_Data_Format meant to store large amounts of data.
14. **freetype**: Drawing text using freetype and harfbuzz.

15. **line_descriptor**: Line Segment Extract and Match -- Methods of extracting, describing and latching line segments using binary descriptors.
15. **hdf**: Hierarchical Data Storage -- This module contains I/O routines for Hierarchical Data Format: https://en.m.wikipedia.org/wiki/Hierarchical_Data_Format meant to store large amounts of data.

16. **matlab**: Matlab Interface -- OpenCV Matlab Mex wrapper code generator for certain opencv core modules.
16. **line_descriptor**: Line Segment Extract and Match -- Methods of extracting, describing and latching line segments using binary descriptors.

17. **optflow**: Optical Flow -- Algorithms for running and evaluating deepflow, simpleflow, sparsetodenseflow and motion templates (silhouette flow).
17. **matlab**: Matlab Interface -- OpenCV Matlab Mex wrapper code generator for certain opencv core modules.

18. **plot**: Plotting -- The plot module allows you to easily plot data in 1D or 2D.
18. **optflow**: Optical Flow -- Algorithms for running and evaluating deepflow, simpleflow, sparsetodenseflow and motion templates (silhouette flow).

19. **reg**: Image Registration -- Pixels based image registration for precise alignment. Follows the paper "Image Alignment and Stitching: A Tutorial", by Richard Szeliski.
19. **plot**: Plotting -- The plot module allows you to easily plot data in 1D or 2D.

20. **rgbd**: RGB-Depth Processing module -- Linemod 3D object recognition; Fast surface normals and 3D plane finding. 3D visual odometry
20. **reg**: Image Registration -- Pixels based image registration for precise alignment. Follows the paper "Image Alignment and Stitching: A Tutorial", by Richard Szeliski.

21. **saliency**: Saliency API -- Where humans would look in a scene. Has routines for static, motion and "objectness" saliency.
21. **rgbd**: RGB-Depth Processing module -- Linemod 3D object recognition; Fast surface normals and 3D plane finding. 3D visual odometry

22. **sfm**: Structure from Motion -- This module contains algorithms to perform 3d reconstruction from 2d images. The core of the module is a light version of Libmv.
22. **saliency**: Saliency API -- Where humans would look in a scene. Has routines for static, motion and "objectness" saliency.

23. **stereo**: Stereo Correspondence -- Stereo matching done with different descriptors: Census / CS-Census / MCT / BRIEF / MV.
23. **sfm**: Structure from Motion -- This module contains algorithms to perform 3d reconstruction from 2d images. The core of the module is a light version of Libmv.

24. **structured_light**: Structured Light Use -- How to generate and project gray code patterns and use them to find dense depth in a scene.
24. **stereo**: Stereo Correspondence -- Stereo matching done with different descriptors: Census / CS-Census / MCT / BRIEF / MV.

25. **surface_matching**: Point Pair Features -- Implements 3d object detection and localization using multimodal point pair features.
25. **structured_light**: Structured Light Use -- How to generate and project gray code patterns and use them to find dense depth in a scene.

26. **text**: Visual Text Matching -- In a visual scene, detect text, segment words and recognise the text.
26. **surface_matching**: Point Pair Features -- Implements 3d object detection and localization using multimodal point pair features.

27. **tracking**: Vision Based Object Tracking -- Use and/or evaluate one of 5 different visual object tracking techniques.
27. **text**: Visual Text Matching -- In a visual scene, detect text, segment words and recognise the text.

28. **xfeatures2d**: Features2D extra -- Extra 2D Features Framework containing experimental and non-free 2D feature detector/descriptor algorithms. SURF, SIFT, BRIEF, Censure, Freak, LUCID, Daisy, Self-similar.
28. **tracking**: Vision Based Object Tracking -- Use and/or evaluate one of 5 different visual object tracking techniques.

29. **ximgproc**: Extended Image Processing -- Structured Forests / Domain Transform Filter / Guided Filter / Adaptive Manifold Filter / Joint Bilateral Filter / Superpixels.
29. **xfeatures2d**: Features2D extra -- Extra 2D Features Framework containing experimental and non-free 2D feature detector/descriptor algorithms. SURF, SIFT, BRIEF, Censure, Freak, LUCID, Daisy, Self-similar.

30. **xobjdetect**: Boosted 2D Object Detection -- Uses a Waldboost cascade and local binary patterns computed as integral features for 2D object detection.
30. **ximgproc**: Extended Image Processing -- Structured Forests / Domain Transform Filter / Guided Filter / Adaptive Manifold Filter / Joint Bilateral Filter / Superpixels.

31. **xphoto**: Extra Computational Photography -- Additional photo processing algorithms: Color balance / Denoising / Inpainting.
31. **xobjdetect**: Boosted 2D Object Detection -- Uses a Waldboost cascade and local binary patterns computed as integral features for 2D object detection.

32. **xphoto**: Extra Computational Photography -- Additional photo processing algorithms: Color balance / Denoising / Inpainting.
26 changes: 26 additions & 0 deletions modules/freetype/CMakeLists.txt
@@ -0,0 +1,26 @@
set(the_description "FreeType module. It enables to draw strings with outlines and mono-bitmaps/gray-bitmaps.")

if(PKG_CONFIG_FOUND)
pkg_search_module(FREETYPE freetype2)
pkg_search_module(HARFBUZZ harfbuzz)
endif()

if(NOT FREETYPE_FOUND)
message(STATUS "freetype2: NO")
else()
message(STATUS "freetype2: YES")
endif()

if(NOT HARFBUZZ_FOUND)
message(STATUS "harfbuzz: NO")
else()
message(STATUS "harfbuzz: YES")
endif()


if( FREETYPE_FOUND AND HARFBUZZ_FOUND )
ocv_define_module(freetype opencv_core opencv_imgproc PRIVATE_REQUIRED ${freetype2_LIBRARIES} ${harfbuzz_LIBRARIES} WRAP python)
ocv_include_directories( ${FREETYPE_INCLUDE_DIRS} ${HARFBUZZ_INCLUDE_DIRS} )
else()
ocv_module_disable(freetype)
endif()
34 changes: 34 additions & 0 deletions modules/freetype/README.md
@@ -0,0 +1,34 @@
FreeType Module
===========

This FreeType module allows you to draw strings with outlines and bitmaps.

Installation
-----------
harfbuzz is requested to convert UTF8 to gid(GlyphID).
freetype library is requested to rasterize given gid.

harfbuzz https://www.freedesktop.org/wiki/Software/HarfBuzz/
freetype https://www.freetype.org/

Usage
-----------
cv::freetype::FreeType2 ft2;
ft2.loadFontData("your-font.ttf", 0);
ft2.setSplitNumber( 4 ); // Bezier-line is splited by 4 segment.
ft2.putText(src, .... )

Option
------------
- 2nd argument of loadFontData is used if font file has many font data.
- 3 drawing mode is available.
-- outline mode is used if lineWidth is larger than 0. (like original putText)
-- bitmap mode is used if lineWidth is less than 0.
--- 1bit bitmap mode is used if lineStyle is 4 or 8.
--- gray bitmap mode is used if lineStyle is 16.

Future work
------------
- test
-- CJK and ...
- RTL,LTR,TTB,BTT...
130 changes: 130 additions & 0 deletions modules/freetype/include/opencv2/freetype.hpp
@@ -0,0 +1,130 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009-2012, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
//################################################################################
//
// Created by Kumataro
//
//################################################################################

#ifndef _OPENCV_FREETYPE_H_
#define _OPENCV_FREETYPE_H_
#ifdef __cplusplus

#include <opencv2/core.hpp>

/**
@defgroup freetype Drawing UTF-8 strings with freetype/harfbuzz
This modules is to draw UTF-8 strings with freetype/harfbuzz.
1. Install freetype2 and harfbuzz in your system.
2. Create FreeType2 instance with createFreeType2() function.
3. Load font file with loadFontData() function.
4. Draw text with putText() function.
- If thickness parameter is negative, drawing glyph is filled.
- If thickness parameter is positive, drawing glyph is outlined with thickness.
- If line_type parameter is 16(or CV_AA), drawing glyph is smooth.
*/

namespace cv {
namespace freetype {
//! @addtogroup freetype
//! @{
class CV_EXPORTS_W FreeType2 : public Algorithm
{
public:
/** @brief Load font data.
The function loadFontData loads font data.
@param fontFileName FontFile Name
@param id face_index to select a font faces in a single file.
*/

CV_WRAP virtual void loadFontData(String fontFileName, int id) = 0;

/** @brief Set Split Number from Bezier-curve to line
The function setSplitNumber set the number of split points from bezier-curve to line.
If you want to draw large glyph, large is better.
If you want to draw small glyph, small is better.
@param num number of split points from bezier-curve to line
*/

CV_WRAP virtual void setSplitNumber( int num ) = 0;

/** @brief Draws a text string.
The function putText renders the specified text string in the image. Symbols that cannot be rendered using the specified font are replaced by "Tofu" or non-drawn.
@param img Image.
@param text Text string to be drawn.
@param org Bottom-left/Top-left corner of the text string in the image.
@param fontHeight Drawing font size by pixel unit.
@param color Text color.
@param thickness Thickness of the lines used to draw a text when negative, the glyph is filled. Otherwise, the glyph is drawn with this thickness.
@param line_type Line type. See the line for details.
@param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.
*/

CV_WRAP virtual void putText(
InputOutputArray img, const String& text, Point org,
int fontHeight, Scalar color,
int thickness, int line_type, bool bottomLeftOrigin
) = 0;

};
/** @brief Create FreeType2 Instance
The function createFreeType2 create instance to draw UTF-8 strings.
*/
CV_EXPORTS_W Ptr<FreeType2> createFreeType2();

//! @]
} } // namespace freetype

#endif
#endif

0 comments on commit cac3c9a

Please sign in to comment.