commit
c33629e053
62 changed files with 972 additions and 566 deletions
@ -0,0 +1,41 @@ |
||||
#include <opencv2/highgui.hpp> |
||||
#include <opencv2/plot.hpp> |
||||
#include <iostream> |
||||
|
||||
using namespace cv; |
||||
|
||||
int main() |
||||
{ |
||||
Mat data_x( 1, 51, CV_64F ); |
||||
Mat data_y( 1, 51, CV_64F ); |
||||
|
||||
for ( int i = 0; i < data_x.cols; i++ ) |
||||
{ |
||||
double x = ( i - data_x.cols / 2 ); |
||||
data_x.at<double>( 0, i ) = x; |
||||
data_y.at<double>( 0, i ) = x * x * x; |
||||
} |
||||
|
||||
std::cout << "data_x : " << data_x << std::endl; |
||||
std::cout << "data_y : " << data_y << std::endl; |
||||
|
||||
Mat plot_result; |
||||
|
||||
Ptr<plot::Plot2d> plot = plot::Plot2d::create( data_x, data_y ); |
||||
plot->render(plot_result); |
||||
|
||||
imshow( "The plot rendered with default visualization options", plot_result ); |
||||
|
||||
plot->setShowText( false ); |
||||
plot->setShowGrid( false ); |
||||
plot->setPlotBackgroundColor( Scalar( 255, 200, 200 ) ); |
||||
plot->setPlotLineColor( Scalar( 255, 0, 0 ) ); |
||||
plot->setPlotLineWidth( 2 ); |
||||
plot->setInvertOrientation( true ); |
||||
plot->render( plot_result ); |
||||
|
||||
imshow( "The plot rendered with some of custom visualization options", plot_result ); |
||||
waitKey(); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,116 @@ |
||||
Tesseract (master) installation by using git-bash (version>=2.14.1) and cmake (version >=3.9.1){#tutorial_install_tesseract} |
||||
=============================================================== |
||||
|
||||
-# We assume you installed opencv and opencv_contrib in c:/lib using [this tutorials](http://docs.opencv.org/master/d3/d52/tutorial_windows_install.html#tutorial_windows_gitbash_build] |
||||
|
||||
-# You must download [png lib](https://sourceforge.net/projects/libpng/files/libpng16/1.6.32/lpng1632.zip/download) and [zlib](https://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib1211.zip/download). |
||||
Uncompress lpngx.y.zz in folder lpng and zlib in folder zlib. lpng and zlib must be in same folder as opencv and opencv_contrib. |
||||
save this script with name installpngzlib.sh in c:/lib |
||||
@code{.bash} |
||||
#!/bin/bash |
||||
myRepo=$(pwd) |
||||
CMAKE_CONFIG_GENERATOR="Visual Studio 14 2015 Win64" |
||||
RepoSource=zlib |
||||
mkdir Build/$RepoSource |
||||
pushd Build/$RepoSource |
||||
cmake . -G"Visual Studio 14 2015 Win64" \ |
||||
-DCMAKE_INSTALL_PREFIX:PATH="$myRepo"/install/zlib -DINSTALL_BIN_DIR:PATH="$myRepo"/install/zlib/bin \ |
||||
-DINSTALL_INC_DIR:PATH="$myRepo"/install/zlib/include -DINSTALL_LIB_DIR:PATH="$myRepo"/install/zlib/lib "$myRepo"/"$RepoSource" |
||||
cmake --build . --config release |
||||
cmake --build . --target install --config release |
||||
cmake --build . --config debug |
||||
cmake --build . --target install --config debug |
||||
popd |
||||
RepoSource=lpng |
||||
mkdir Build/$RepoSource |
||||
pushd Build/$RepoSource |
||||
cp "$myRepo"/"$RepoSource"/scripts/pnglibconf.h.prebuilt "$myRepo"/"$RepoSource"/pnglibconf.h |
||||
cmake . -G"Visual Studio 14 2015 Win64" \ |
||||
-DZLIB_INCLUDE_DIR:PATH="$myRepo"/install/zlib/include -DZLIB_LIBRARY_DEBUG:FILE="$myRepo"/install/zlib/lib/zlibstaticd.lib \ |
||||
-Dld-version-script:BOOL=OFF -DPNG_TESTS:BOOL=OFF -DAWK:STRING= \ |
||||
-DZLIB_LIBRARY_RELEASE:FILE="$myRepo"/install/zlib/lib/zlibstatic.lib -DCMAKE_INSTALL_PREFIX="$myRepo"/Install/"$RepoSource" \ |
||||
"$myRepo"/"$RepoSource" |
||||
cmake --build . --config release |
||||
cmake --build . --target install --config release |
||||
cmake --build . --config debug |
||||
cmake --build . --target install --config debug |
||||
popd |
||||
@endcode |
||||
-# In git command line enter the following command : |
||||
@code{.bash} |
||||
./installpngzlib.sh |
||||
@endcode |
||||
|
||||
-# save this script with name installTesseract.sh in c:/lib |
||||
@code{.bash} |
||||
#!/bin/bash |
||||
function MAJGitRepo |
||||
{ |
||||
if [ ! -d "$myRepo/$1" ]; then |
||||
echo "clonning ${1}" |
||||
git clone $2 |
||||
mkdir Build/$1 |
||||
else |
||||
echo "update $1" |
||||
cd $1 |
||||
git pull --rebase |
||||
cd .. |
||||
fi |
||||
} |
||||
echo "Installing leptonica and tesseract" |
||||
myRepo=$(pwd) |
||||
CMAKE_CONFIG_GENERATOR="Visual Studio 14 2015 Win64" |
||||
|
||||
MAJGitRepo leptonica https://github.com/DanBloomberg/leptonica.git |
||||
RepoSource=leptonica |
||||
pushd Build/$RepoSource |
||||
cmake -G"$CMAKE_CONFIG_GENERATOR" -DCMAKE_INSTALL_PREFIX="$myRepo"/Install/leptonica "$myRepo/$RepoSource" |
||||
echo "************************* $Source_DIR -->debug" |
||||
cmake --build . --config release |
||||
cmake --build $RepoSource --target install --config release |
||||
popd |
||||
|
||||
RepoSource=tesseract |
||||
MAJGitRepo $RepoSource https://github.com/tesseract-ocr/tesseract.git |
||||
pushd Build/$RepoSource |
||||
cmake -G"$CMAKE_CONFIG_GENERATOR" -DBUILD_TRAINING_TOOLS:BOOL=OFF -DCMAKE_INSTALL_PREFIX="$myRepo"/Install/tesseract -DLeptonica_DIR:PATH="$myRepo"/Install/leptonica/cmake -DPKG_CONFIG_EXECUTABLE:BOOL=OFF "$myRepo"/"$RepoSource" |
||||
echo "************************* $Source_DIR -->release" |
||||
cmake --build . --config release |
||||
cmake --build . --target install --config release |
||||
|
||||
popd |
||||
RepoSource=opencv |
||||
pushd Build/$RepoSource |
||||
CMAKE_OPTIONS='-DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF -DBUILD_DOCS:BOOL=OFF -DWITH_CUDA:BOOL=OFF' |
||||
cmake -G"$CMAKE_CONFIG_GENERATOR" \ |
||||
-DTesseract_INCLUDE_DIR:PATH="${myRepo}"/Install/tesseract/include -DTesseract_LIBRARY="${myRepo}"/Install/tesseract/lib/tesseract400.lib -DLept_LIBRARY="${myRepo}"/Install/leptonica/lib/leptonica-1.74.4.lib \ |
||||
$CMAKE_OPTIONS -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \ |
||||
-DINSTALL_CREATE_DISTRIB=ON -DCMAKE_INSTALL_PREFIX="$myRepo"/install/"$RepoSource" "$myRepo/$RepoSource" |
||||
echo "************************* $Source_DIR -->devenv debug" |
||||
cmake --build . --config debug |
||||
echo "************************* $Source_DIR -->devenv release" |
||||
cmake --build . --config release |
||||
cmake --build . --target install --config release |
||||
cmake --build . --target install --config debug |
||||
popd |
||||
|
||||
@endcode |
||||
In this script I suppose you use VS 2015 in 64 bits |
||||
@code{.bash} |
||||
CMAKE_CONFIG_GENERATOR="Visual Studio 14 2015 Win64" |
||||
@endcode |
||||
and leptonica, tesseract will be installed in c:/lib/install |
||||
@code{.bash} |
||||
-DCMAKE_INSTALL_PREFIX="$myRepo"/install/"$RepoSource" "$myRepo/$RepoSource" |
||||
@endcode |
||||
with no Perf tests, no tests, no doc, no CUDA and no example |
||||
@code{.bash} |
||||
CMAKE_OPTIONS='-DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF -DBUILD_DOCS:BOOL=OFF -DWITH_CUDA:BOOL=OFF -DBUILD_EXAMPLES:BOOL=OFF' |
||||
@endcode |
||||
-# In git command line enter the following command : |
||||
@code{.bash} |
||||
./installTesseract.sh |
||||
@endcode |
||||
-# now we need the language files from tesseract. either clone https://github.com/tesseract-ocr/tessdata, or copy only those language files you need to a folder (example c:\\lib\\install\\tesseract\\tessdata). If you don't want to add a new folder you must copy language file in same folder than your executable |
||||
-# if you created a new folder, then you must add a new variable, TESSDATA_PREFIX with the value c:\\lib\\install\\tessdata to your system's environment |
||||
-# add c:\\Lib\\install\\leptonica\\bin and c:\\Lib\\install\\tesseract\\bin to your PATH environment. If you don't want to modify the PATH then copy tesseract400.dll and leptonica-1.74.4.dll to the same folder than your exe file. |
@ -0,0 +1,10 @@ |
||||
Text module {#tutorial_table_of_content_text} |
||||
===================== |
||||
|
||||
- @subpage tutorial_install_tesseract |
||||
|
||||
*Compatibility:* \> OpenCV 3.4 |
||||
|
||||
*Author:* Laurent Berger |
||||
|
||||
Instructions in order to properly setup tesseract on windows for the text module. |
@ -0,0 +1,31 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#ifndef __OPENCV_PEILIN_HPP__ |
||||
#define __OPENCV_PEILIN_HPP__ |
||||
|
||||
#include <opencv2/core.hpp> |
||||
|
||||
namespace cv |
||||
{ |
||||
//! @addtogroup ximgproc
|
||||
//! @{
|
||||
|
||||
/**
|
||||
* @brief Calculates an affine transformation that normalize given image using Pei&Lin Normalization. |
||||
* |
||||
* Assume given image \f$I=T(\bar{I})\f$ where \f$\bar{I}\f$ is a normalized image and \f$T\f$ is an affine transformation distorting this image by translation, rotation, scaling and skew. |
||||
* The function returns an affine transformation matrix corresponding to the transformation \f$T^{-1}\f$ described in [PeiLin95]. |
||||
* For more details about this implementation, please see |
||||
* [PeiLin95] Soo-Chang Pei and Chao-Nan Lin. Image normalization for pattern recognition. Image and Vision Computing, Vol. 13, N.10, pp. 711-723, 1995. |
||||
* |
||||
* @param I Given transformed image. |
||||
* @return Transformation matrix corresponding to inversed image transformation |
||||
*/ |
||||
CV_EXPORTS Matx23d PeiLinNormalization ( InputArray I ); |
||||
/** @overload */ |
||||
CV_EXPORTS_W void PeiLinNormalization ( InputArray I, OutputArray T ); |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,59 @@ |
||||
#include <opencv2/imgproc.hpp> |
||||
#include <opencv2/highgui.hpp> |
||||
#include <opencv2/ximgproc.hpp> |
||||
|
||||
#include <iostream> |
||||
|
||||
static void help() |
||||
{ |
||||
std::cout << "\nThis program demonstrates Pei&Lin Normalization\n" |
||||
"Usage:\n" |
||||
"./peilin [image1_name -- default is ../data/peilin_plane.png] [image2_name -- default is ../data/peilin_shape.png]\n" << std::endl; |
||||
} |
||||
|
||||
static inline cv::Mat operator& ( const cv::Mat& lhs, const cv::Matx23d& rhs ) |
||||
{ |
||||
cv::Mat ret; |
||||
cv::warpAffine ( lhs, ret, rhs, lhs.size(), cv::INTER_LINEAR ); |
||||
return ret; |
||||
} |
||||
|
||||
static inline cv::Mat operator& ( const cv::Matx23d& lhs, const cv::Mat& rhs ) |
||||
{ |
||||
cv::Mat ret; |
||||
cv::warpAffine ( rhs, ret, lhs, rhs.size(), cv::INTER_LINEAR | cv::WARP_INVERSE_MAP ); |
||||
return ret; |
||||
} |
||||
|
||||
int main(int argc, char** argv) |
||||
{ |
||||
cv::CommandLineParser parser(argc, argv, "{help h | | }{ @input1 | ../data/peilin_plane.png | }{ @input2 | ../data/peilin_plane.png | }"); |
||||
if (parser.has("help")) |
||||
{ |
||||
help(); |
||||
return 0; |
||||
} |
||||
std::string filename1 = parser.get<std::string>("@input1"); |
||||
std::string filename2 = parser.get<std::string>("@input2"); |
||||
|
||||
cv::Mat I = cv::imread(filename1, 0); |
||||
if (I.empty()) |
||||
{ |
||||
std::cout << "Couldn't open image " << filename1 << std::endl; |
||||
return 0; |
||||
} |
||||
cv::Mat J = cv::imread(filename2, 0); |
||||
if (J.empty()) |
||||
{ |
||||
std::cout << "Couldn't open image " << filename2 << std::endl; |
||||
return 0; |
||||
} |
||||
cv::Mat N = I & cv::PeiLinNormalization ( I ); |
||||
cv::Mat D = cv::PeiLinNormalization ( J ) & I; |
||||
cv::imshow ( "I", I ); |
||||
cv::imshow ( "N", N ); |
||||
cv::imshow ( "J", J ); |
||||
cv::imshow ( "D", D ); |
||||
cv::waitKey(); |
||||
return 0; |
||||
} |
After Width: | Height: | Size: 662 B |
After Width: | Height: | Size: 2.5 KiB |
@ -0,0 +1,57 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
|
||||
static inline Moments operator& ( const Moments & lhs, const Matx22d & rhs ) |
||||
{ |
||||
return Moments ( |
||||
lhs.m00, |
||||
rhs ( 0, 0 ) * lhs.m10 + rhs ( 0, 1 ) * lhs.m01, |
||||
rhs ( 1, 0 ) * lhs.m10 + rhs ( 1, 1 ) * lhs.m01, |
||||
rhs ( 0, 0 ) * rhs ( 0, 0 ) * lhs.m20 + rhs ( 0, 1 ) * rhs ( 0, 1 ) * lhs.m02 + 2 * rhs ( 0, 0 ) * rhs ( 0, 1 ) * lhs.m11, |
||||
rhs ( 0, 0 ) * rhs ( 1, 0 ) * lhs.m20 + rhs ( 0, 1 ) * rhs ( 1, 1 ) * lhs.m02 + ( rhs ( 0, 0 ) * rhs ( 1, 1 ) + rhs ( 0, 1 ) * rhs ( 1, 0 ) ) * lhs.m11, |
||||
rhs ( 1, 0 ) * rhs ( 1, 0 ) * lhs.m20 + rhs ( 1, 1 ) * rhs ( 1, 1 ) * lhs.m02 + 2 * rhs ( 1, 0 ) * rhs ( 1, 1 ) * lhs.m11, |
||||
rhs ( 0, 0 ) * rhs ( 0, 0 ) * rhs ( 0, 0 ) * lhs.m30 + 3 * rhs ( 0, 0 ) * rhs ( 0, 0 ) * rhs ( 0, 1 ) * lhs.m21 + 3 * rhs ( 0, 0 ) * rhs ( 0, 1 ) * rhs ( 0, 1 ) * lhs.m12 + rhs ( 0, 1 ) * rhs ( 0, 1 ) * rhs ( 0, 1 ) * lhs.m03, |
||||
rhs ( 0, 0 ) * rhs ( 0, 0 ) * rhs ( 1, 0 ) * lhs.m30 + ( rhs ( 0, 0 ) * rhs ( 0, 0 ) * rhs ( 1, 1 ) + 2 * rhs ( 0, 0 ) * rhs ( 0, 1 ) * rhs ( 1, 0 ) ) * lhs.m21 + ( 2 * rhs ( 0, 0 ) * rhs ( 0, 1 ) * rhs ( 1, 1 ) + rhs ( 0, 1 ) * rhs ( 0, 1 ) * rhs ( 1, 0 ) ) * lhs.m12 + rhs ( 0, 1 ) * rhs ( 0, 1 ) * rhs ( 1, 1 ) * lhs.m03, |
||||
rhs ( 0, 0 ) * rhs ( 1, 0 ) * rhs ( 1, 0 ) * lhs.m30 + ( rhs ( 1, 0 ) * rhs ( 1, 0 ) * rhs ( 0, 1 ) + 2 * rhs ( 0, 0 ) * rhs ( 1, 0 ) * rhs ( 1, 1 ) ) * lhs.m21 + ( 2 * rhs ( 0, 1 ) * rhs ( 1, 0 ) * rhs ( 1, 1 ) + rhs ( 1, 1 ) * rhs ( 1, 1 ) * rhs ( 0, 0 ) ) * lhs.m12 + rhs ( 0, 1 ) * rhs ( 1, 1 ) * rhs ( 1, 1 ) * lhs.m03, |
||||
rhs ( 1, 0 ) * rhs ( 1, 0 ) * rhs ( 1, 0 ) * lhs.m30 + 3 * rhs ( 1, 0 ) * rhs ( 1, 0 ) * rhs ( 1, 1 ) * lhs.m21 + 3 * rhs ( 1, 0 ) * rhs ( 1, 1 ) * rhs ( 1, 1 ) * lhs.m12 + rhs ( 1, 1 ) * rhs ( 1, 1 ) * rhs ( 1, 1 ) * lhs.m03 |
||||
); |
||||
} |
||||
|
||||
static inline Matx23d operator| ( const Matx22d & lhs, const Matx21d & rhs ) |
||||
{ |
||||
return Matx23d ( lhs ( 0, 0 ), lhs ( 0, 1 ), rhs ( 0 ), lhs ( 1, 0 ), lhs ( 1, 1 ), rhs ( 1 ) ); |
||||
} |
||||
|
||||
Matx23d PeiLinNormalization ( InputArray I ) |
||||
{ |
||||
const Moments M = moments ( I ); |
||||
const double l1 = ( M.mu20 / M.m00 + M.mu02 / M.m00 + sqrt ( ( M.mu20 / M.m00 - M.mu02 / M.m00 ) * ( M.mu20 / M.m00 - M.mu02 / M.m00 ) + 4 * M.mu11 / M.m00 * M.mu11 / M.m00 ) ) / 2; |
||||
const double l2 = ( M.mu20 / M.m00 + M.mu02 / M.m00 - sqrt ( ( M.mu20 / M.m00 - M.mu02 / M.m00 ) * ( M.mu20 / M.m00 - M.mu02 / M.m00 ) + 4 * M.mu11 / M.m00 * M.mu11 / M.m00 ) ) / 2; |
||||
const double ex = ( M.mu11 / M.m00 ) / sqrt ( ( l1 - M.mu20 / M.m00 ) * ( l1 - M.mu20 / M.m00 ) + M.mu11 / M.m00 * M.mu11 / M.m00 ); |
||||
const double ey = ( l1 - M.mu20 / M.m00 ) / sqrt ( ( l1 - M.mu20 / M.m00 ) * ( l1 - M.mu20 / M.m00 ) + M.mu11 / M.m00 * M.mu11 / M.m00 ); |
||||
const Matx22d E = Matx22d ( ex, ey, -ey, ex ); |
||||
const double p = min ( I.size().height, I.size().width ) / 8; |
||||
const Matx22d W = Matx22d ( p / sqrt ( l1 ), 0, 0, p / sqrt ( l2 ) ); |
||||
const Matx21d c = Matx21d ( M.m10 / M.m00, M.m01 / M.m00 ); |
||||
const Matx21d i = Matx21d ( I.size().width / 2, I.size().height / 2 ); |
||||
const Moments N = M & W * E; |
||||
const double t1 = N.mu12 + N.mu30; |
||||
const double t2 = N.mu03 + N.mu21; |
||||
const double phi = atan2 ( -t1, t2 ); |
||||
const double psi = ( -t1 * sin ( phi ) + t2 * cos ( phi ) >= 0 ) ? phi : ( phi + CV_PI ); |
||||
const Matx22d A = Matx22d ( cos ( psi ), sin ( psi ), -sin ( psi ), cos ( psi ) ); |
||||
return ( A * W * E ) | ( i - A * W * E * c ); |
||||
} |
||||
|
||||
void PeiLinNormalization ( InputArray I, OutputArray T ) |
||||
{ |
||||
T.assign ( Mat ( PeiLinNormalization ( I ) ) ); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue