From 0124682ed99277e4809dfa842c36b91519eccd9c Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 26 Feb 2024 17:48:11 +0100 Subject: [PATCH] remove ppocr/mln/io --- projects/ppocr/mln/io/pbm/load.hh | 146 ---------------- projects/ppocr/mln/io/pnm/load.hh | 184 -------------------- projects/ppocr/mln/io/pnm/load_header.hh | 136 --------------- projects/ppocr/mln/io/pnm/macros.hh | 46 ----- projects/ppocr/mln/io/ppm/load.hh | 67 ------- src/capture/ocr/bitmap_as_ocr_image.hpp | 50 ++++++ src/capture/ocr/image2dview.hpp | 51 ------ src/capture/ocr/labelize.hh | 4 +- src/capture/ocr/main/extract_text.cc | 25 ++- src/capture/ocr/main/ppocr_extract_text.cpp | 25 ++- src/capture/utils/drawable_image_view.hpp | 18 +- targets.jam | 15 ++ 12 files changed, 99 insertions(+), 668 deletions(-) delete mode 100644 projects/ppocr/mln/io/pbm/load.hh delete mode 100644 projects/ppocr/mln/io/pnm/load.hh delete mode 100644 projects/ppocr/mln/io/pnm/load_header.hh delete mode 100644 projects/ppocr/mln/io/pnm/macros.hh delete mode 100644 projects/ppocr/mln/io/ppm/load.hh create mode 100644 src/capture/ocr/bitmap_as_ocr_image.hpp delete mode 100644 src/capture/ocr/image2dview.hpp diff --git a/projects/ppocr/mln/io/pbm/load.hh b/projects/ppocr/mln/io/pbm/load.hh deleted file mode 100644 index cb2a792a73..0000000000 --- a/projects/ppocr/mln/io/pbm/load.hh +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see . -// -// As a special exception, you may use this file as part of a free -// software project without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to produce -// an executable, this file does not by itself cause the resulting -// executable to be covered by the GNU General Public License. This -// exception does not however invalidate any other reasons why the -// executable file might be covered by the GNU General Public License. - -#ifndef MLN_IO_PBM_LOAD_HH -#define MLN_IO_PBM_LOAD_HH - -/// \file -/// -/// Define a function which loads an image of kind pbm with -/// given path. - - -#include -#include -#include - -#include -#include - - -namespace mln -{ - - namespace io - { - - namespace pbm - { - - /// Load a pbm image in a Milena image. - /// - /// \param[out] ima A reference to the image2d which will receive - /// data. - /// \param[in] filename The source. - /// - bool load(image2d& ima, const std::string& filename); - - -# ifndef MLN_INCLUDE_ONLY - - namespace internal - { - - /// load_ascii. - template - inline - void load_ascii(std::ifstream& file, image2d& ima) - { - typename image2d::fwd_piter p(ima.domain()); - for(p .start(); p .is_valid(); p .next()) - { - unsigned char value; - file >> value; - - mln_assertion(value == '0' || value == '1'); - ima(p) = (value == '0'); // In pbm, '0' means 'white' so 'object', thus 'true'! - } - } - - - /// load_raw_2d. - template - inline - void load_raw_2d(std::ifstream& file, image2d& ima) - { - typedef typename image2d::site::coord coord; - const coord min_row = 0; - const coord min_col = 0; - const coord max_row = ima.nrows(); - const coord max_col = ima.ncols(); - typename image2d::site p = point2d(0, min_col); - - char c = 0; - int i; - for (p.row() = min_row; p.row() < max_row; ++p.row()) - { - i = 0; - for (p.col() = min_col; p.col() < max_col; ++p.col()) - { - if (i % 8 == 0) - file.read(&c, 1); - ima(p) = !(c & 128); - c = static_cast(c * 2); - ++i; - } - } - } - - - } // end of namespace mln::io::internal - - - inline - bool load(image2d& ima, const std::string& filename) - { - std::ifstream file(filename.c_str()); - if (! file) - { - return false; - } - char type = 0; - int nrows, ncols; - if (!io::pnm::read_header('1', '4', file, type, nrows, ncols)) { - return false; - } - - ima.init_(nrows, ncols); - if (type == '4') - internal::load_raw_2d(file, ima); - else if (type == '1') - internal::load_ascii(file, ima); - return file.eof() == true || file.rdbuf()->sgetc() == std::ifstream::traits_type::eof(); - } - -# endif // ! MLN_INCLUDE_ONLY - - } // end of namespace mln::io::pbm - - } // end of namespace mln::io - -} // end of namespace mln - - -#endif // ! MLN_IO_PBM_LOAD_HH diff --git a/projects/ppocr/mln/io/pnm/load.hh b/projects/ppocr/mln/io/pnm/load.hh deleted file mode 100644 index cec8b5cbca..0000000000 --- a/projects/ppocr/mln/io/pnm/load.hh +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see . -// -// As a special exception, you may use this file as part of a free -// software project without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to produce -// an executable, this file does not by itself cause the resulting -// executable to be covered by the GNU General Public License. This -// exception does not however invalidate any other reasons why the -// executable file might be covered by the GNU General Public License. - -#ifndef MLN_IO_PNM_LOAD_HH -#define MLN_IO_PNM_LOAD_HH - -/// \file -/// -/// Define a function which loads an image of kind PNM 8/16bits with -/// given path. - -#include -#include -#include - -#include -#include - -#include -#include - -namespace mln -{ - - namespace io - { - - namespace pnm - { - - template - bool load_ascii_value(std::ifstream& file, I& ima); - - template - bool load_ascii_builtin(std::ifstream& file, I& ima); - - // used when (sizeof(int_u8) != 1) - template - inline - void load_raw_2d_uncontiguous(std::ifstream& file, image2d& ima) - { - const def::coord min_row = 0; - const def::coord min_col = 0; - const def::coord max_row = ima.nrows(); - const def::coord max_col = ima.ncols(); - - point2d p; - for (p.row() = min_row; p.row() < max_row; ++p.row()) - for (p.col() = min_col; p.col() < max_col; ++p.col()) - ::mln::trait::value_::read_value(file, ima(p)); - } - - // used in g++ > 2.95 - template - inline - void load_raw_2d_contiguous(std::ifstream& file, image2d& ima) - { - point2d p = point2d(0, ima.ncols() - 1); - typedef typename image2d::site::coord coord; - const coord min_row = 0; - const coord max_row = ima.nrows(); - - std::size_t len = ima.ncols() * sizeof(V); - for (p.row() = min_row; p.row() < max_row; ++p.row()) - file.read(reinterpret_cast(&ima(p)), len); - } - - /// load_ascii for Milena value types. - template - inline - void load_ascii_value(std::ifstream& file, image2d& ima) - { - typename image2d::value::equiv c; - typename image2d::fwd_piter p(ima.domain()); - for (p .start(); p .is_valid(); p .next()) - { - file >> c; - ima(p) = c; - } - } - - /// load_ascii for builtin value types. - template - inline - void load_ascii_builtin(std::ifstream& file, image2d& ima) - { - typename image2d::fwd_piter p(ima.domain()); - - // FIXME: May be wrong! - // Worked out with an image with a max value of 255 - // loaded in an image2d. - typename image2d::value n; - - for (p.start(); p.is_valid(); p.next()) - { - ::mln::trait::value_::read_value(file, n); - ima(p) = n; - } - } - - /// load_raw_2d. - /// for all pnm 8/16 bits formats - template - inline - void load_raw_2d(std::ifstream& file, image2d& ima) - { - if (sizeof(V) == 1) - load_raw_2d_contiguous(file, ima); - else - load_raw_2d_uncontiguous(file, ima); - } - - /// An other way to load pnm files : - /// the destination is an argument to check if - /// the type match the file to load. - template - inline - bool load(char type_, - image2d& ima, - const std::string& filename) - { - std::ifstream file(filename.c_str()); - if (! file) - { - return false; - } - - char type = 0; - int nrows, ncols; - unsigned int maxval; - if (!read_header(static_cast(type_ - 3), type_, file, type, - nrows, ncols, maxval)) { - return false; - } - - if (::mln::trait::value_::max() != maxval) - { - std::cerr << "error: file '" << filename - << "' cannot be loaded into this type of image\n" - << "input image have " << maxval - << " as maximum value while the destination's one is " - << ::mln::trait::value_::max() << "." - << std::endl; - return false; - } - - ima.init_(nrows, ncols); - if (type == type_) - load_raw_2d(file, ima); - else if (type == (type_ - 3)) - pnm::load_ascii_builtin(file, ima); - return file.eof() == true || file.rdbuf()->sgetc() == std::ifstream::traits_type::eof(); - } - - } // end of namespace mln::io::pnm - - } // end of namespace mln::io - -} // end of namespace mln - - -#endif // ! MLN_IO_PNM_LOAD_HH diff --git a/projects/ppocr/mln/io/pnm/load_header.hh b/projects/ppocr/mln/io/pnm/load_header.hh deleted file mode 100644 index 6cafdf89a3..0000000000 --- a/projects/ppocr/mln/io/pnm/load_header.hh +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see . -// -// As a special exception, you may use this file as part of a free -// software project without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to produce -// an executable, this file does not by itself cause the resulting -// executable to be covered by the GNU General Public License. This -// exception does not however invalidate any other reasons why the -// executable file might be covered by the GNU General Public License. - -#ifndef MLN_IO_PNM_LOAD_HEADER_HH -#define MLN_IO_PNM_LOAD_HEADER_HH - -/// \file -/// -/// Define a function which loads header for PNM image. - -#include -#include -#include - - -namespace mln -{ - - namespace io - { - - namespace pnm - { - -# ifndef MLN_INCLUDE_ONLY - - inline - bool read_header(std::ifstream& istr, - char& type, - int& nrows, int& ncols, - unsigned int& maxval, - bool test = false) - { - // check magic - if (istr.get() != 'P' ) - goto err; - type = static_cast(istr.get()); - - if (type < '1' || type > '6') - goto err; - if (istr.get() != '\n') - goto err; - - // skip comments - while (istr.peek() == '#') - { - std::string line; - std::getline(istr, line); - } - - // get size - istr >> ncols >> nrows; - if (nrows <= 0 || ncols <= 0) - goto err; - - // get maxvalue - if (istr.get() != '\n') - goto err; - if (type != '1' && type != '4') - { - istr >> maxval; - if (istr.get() != '\n') - goto err; - } - return true; - - err: - if (! test) - { - std::cerr << "error: badly formed header!"; - } - return false; - } - - inline - bool read_header(char ascii, char raw, - std::ifstream& istr, - char& type, - int& nrows, int& ncols, - unsigned int& maxval) - { - if (!read_header(istr, type, nrows, ncols, maxval) - || ! (type == ascii || type == raw)) - { - std::cerr << "error: bad pnm type; " - << "expected P" << ascii - << " or P" << raw - << ", get P" << type << "!" << std::endl; - return false; - } - return true; - } - - inline - bool read_header(char ascii, char raw, - std::ifstream& istr, - char& type, - int& nrows, int& ncols) - { - unsigned int maxval; - return read_header(ascii, raw, istr, type, - nrows, ncols, maxval); - } - -# endif // ! MLN_INCLUDE_ONLY - - } // end of namespace mln::io::pnm - - } // end of namespace mln::io - -} // end of namespace mln - - -#endif // ! MLN_IO_PNM_LOAD_HEADER_HH diff --git a/projects/ppocr/mln/io/pnm/macros.hh b/projects/ppocr/mln/io/pnm/macros.hh deleted file mode 100644 index 8283a3134f..0000000000 --- a/projects/ppocr/mln/io/pnm/macros.hh +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see . -// -// As a special exception, you may use this file as part of a free -// software project without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to produce -// an executable, this file does not by itself cause the resulting -// executable to be covered by the GNU General Public License. This -// exception does not however invalidate any other reasons why the -// executable file might be covered by the GNU General Public License. - -#ifndef MLN_IO_PNM_MACROS_HH -# define MLN_IO_PNM_MACROS_HH - -/*! \file - * - * \brief Definition of pnm formats macros. - */ - -/// Portable Pixel Map Format -# define PPM '6' -# define PPM_ASCII '3' - -/// Portable Gray Map Format -# define PGM '5' -# define PGM_ASCII '2' - -/// Portable Bit Map Format -# define PBM '4' -# define PBM_ASCII '1' - -#endif // ! MLN_IO_PNM_MACROS_HH diff --git a/projects/ppocr/mln/io/ppm/load.hh b/projects/ppocr/mln/io/ppm/load.hh deleted file mode 100644 index 398e27f93f..0000000000 --- a/projects/ppocr/mln/io/ppm/load.hh +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Olena. If not, see . -// -// As a special exception, you may use this file as part of a free -// software project without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to produce -// an executable, this file does not by itself cause the resulting -// executable to be covered by the GNU General Public License. This -// exception does not however invalidate any other reasons why the -// executable file might be covered by the GNU General Public License. - -#ifndef MLN_IO_PPM_LOAD_HH -#define MLN_IO_PPM_LOAD_HH - -/// \file -/// -/// Define a function which loads an image of kind ppm with -/// given path. - -#include - -#include -#include - - -namespace mln -{ - - namespace io - { - - namespace ppm - { - - /// Load a ppm image in a Milena image. - /// - /// \param[out] ima A reference to the image which will receive - /// data. - /// \param[in] filename The source. - template - bool load(image2d& ima, const std::string& filename) - { - return io::pnm::load(PPM, ima, filename); - } - - } // end of namespace mln::io::ppm - - } // end of namespace mln::io - -} // end of namespace mln - - -#endif // ! MLN_IO_PPM_LOAD_HH diff --git a/src/capture/ocr/bitmap_as_ocr_image.hpp b/src/capture/ocr/bitmap_as_ocr_image.hpp new file mode 100644 index 0000000000..c0e19489ea --- /dev/null +++ b/src/capture/ocr/bitmap_as_ocr_image.hpp @@ -0,0 +1,50 @@ +/* +SPDX-FileCopyrightText: 2024 Wallix Proxies Team +SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#pragma once + +#include "utils/bitmap_from_file.hpp" + +namespace ocr +{ + +class BitmapAsOcrImage +{ + Bitmap img; + +public: + explicit BitmapAsOcrImage(char const* filename) + : img(BitsPerPixel::BitsPP24, bitmap_from_file_impl(filename, BGRColor())) + {} + + bool is_valid() const { return img.is_valid(); } + + unsigned width() const { return img.cx() + 2; /* add a border */ } + unsigned height() const { return img.cy() + 2; /* add a border */ } + + struct Color + { + const uint8_t * c; + + uint8_t blue() const { return c[0]; } + uint8_t green() const { return c[1]; } + uint8_t red() const { return c[2]; } + }; + + using value_type = Color; + + Color operator()(unsigned row, unsigned col) const + { + // when border -> black color + if (row > 0 && col > 0 && col < width() - 1 && row < height() - 1) { + --row; + --col; + return {img.data() + (img.cy() - row) * img.line_size() + col * 3}; + } + return Color{reinterpret_cast("\0\0\0")}; + } +}; + +} // namespace ocr diff --git a/src/capture/ocr/image2dview.hpp b/src/capture/ocr/image2dview.hpp deleted file mode 100644 index b9917e999d..0000000000 --- a/src/capture/ocr/image2dview.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Product name: redemption, a FLOSS RDP proxy - * Copyright (C) Wallix 2010-2013 - * Author(s): Christophe Grosjean, Raphael Zhou, Jonathan Poelen, Meng Tan - */ - -#pragma once - -#include "mln/image/image2d.hh" - -namespace ocr -{ - template - class Image2dView - { - mln::image2d const & input; - - public: - using value_type = ImageValue; - - Image2dView(mln::image2d const & input_) - : input(input_) - {} - - [[nodiscard]] unsigned width() const - { return input.ncols(); } - - [[nodiscard]] unsigned height() const - { return input.nrows(); } - - const ImageValue & operator()(unsigned row, unsigned col) const - { return input.at(row, col); } - - const ImageValue & operator[](const ::mln::point2d & p) const - { return input(p); } - }; -} // namespace ocr diff --git a/src/capture/ocr/labelize.hh b/src/capture/ocr/labelize.hh index aef5290418..07db0428c0 100644 --- a/src/capture/ocr/labelize.hh +++ b/src/capture/ocr/labelize.hh @@ -35,7 +35,7 @@ namespace internal { }; inline - bool adjacent_rihgt(::mln::image2d const & input, unsigned row, unsigned nrows, unsigned col) + bool adjacent_right(::mln::image2d const & input, unsigned row, unsigned nrows, unsigned col) { for (; row < nrows; ++row) { if ( input.at(row, col) @@ -98,7 +98,7 @@ void labelize(std::vector & attributes, const ::mln::image2d unsigned min_row = info.row_first; unsigned max_row = info.row_last+1; while (ccol < ncols-1) { - if (!internal::adjacent_rihgt(input, min_row, max_row, ccol)) { + if (!internal::adjacent_right(input, min_row, max_row, ccol)) { break; } ++ccol; diff --git a/src/capture/ocr/main/extract_text.cc b/src/capture/ocr/main/extract_text.cc index 66d358fc62..cd6b9562c6 100644 --- a/src/capture/ocr/main/extract_text.cc +++ b/src/capture/ocr/main/extract_text.cc @@ -1,22 +1,21 @@ #include -#include #include #include #include #include +#include #include "capture/ocr/rgb8.hpp" +#include "capture/ocr/bitmap_as_ocr_image.hpp" #include "capture/ocr/extract_bars.hh" -#include "capture/ocr/image2dview.hpp" #include "capture/ocr/io_char_box.hpp" #include "capture/ocr/extract_text_classification.hh" #include "utils/sugar/chars_to_int.hpp" +#include "utils/bitmap_from_file.hpp" using namespace std::string_view_literals; -typedef ocr::Image2dView ImageView; - struct Classification { std::vector attrs; @@ -32,7 +31,7 @@ struct Classification , display_char(display_char_) {} - void operator()(ImageView const & input, unsigned tid, mln::box2d const & box, unsigned button_col) + void operator()(ocr::BitmapAsOcrImage const & input, unsigned tid, mln::box2d const & box, unsigned button_col) { ocr::image_view_to_image2d_bool(input, tid, this->ima, box); @@ -89,7 +88,7 @@ struct Classification private: void display_result( - ImageView const & input, unsigned tid, unsigned font_id, + ocr::BitmapAsOcrImage const & input, unsigned tid, unsigned font_id, mln::box2d const & box, unsigned button_col, const ocr::classifier_type & res) { auto id = static_cast(this->locale_id); @@ -119,7 +118,7 @@ struct ReferenceClassification : ref(ref_) {} - void operator()(ImageView const & input, unsigned tid, mln::box2d const & box, unsigned button_col) + void operator()(ocr::BitmapAsOcrImage const & input, unsigned tid, mln::box2d const & box, unsigned button_col) { this->ref(input, tid, box, button_col); } @@ -128,7 +127,7 @@ struct ReferenceClassification inline void usage(char** argv) { - std::cerr << "Usage: " << argv[0] << " input.ppm/pnm [latin|cyrillic] [font_id|font_name] [d]\n"; + std::cerr << "Usage: " << argv[0] << " input.png [latin|cyrillic] [font_id|font_name] [d]\n"; const auto max = static_cast(ocr::fonts::LocaleId::max); for (unsigned locale_id = 0; locale_id < max; ++locale_id) { std::cout << "\nlocale (" << locale_id << "): " << &"latin\0cyrillic"[locale_id * 6] << "\n"; @@ -165,11 +164,11 @@ int main(int argc, char** argv) if (iarg < argc) { arg = argv[iarg]; - if ('d' == arg[0] && !arg[1]) { + if (arg == "d"sv) { display_char = true; } else { - if (arg != "all"sv && arg != "-1") { + if (arg != "all"sv && arg != "-1"sv) { const auto n = parse_decimal_chars(arg); font_id = n.has_value ? unsigned(n.value) @@ -192,8 +191,8 @@ int main(int argc, char** argv) } } - mln::image2d input; - if (!mln::io::ppm::load(input, argv[1])) { + ocr::BitmapAsOcrImage input(argv[1]); + if (!input.is_valid()) { if (errno != 0) { std::cerr << argv[0] << ": " << strerror(errno) << std::endl; } @@ -209,7 +208,7 @@ int main(int argc, char** argv) using resolution_clock = std::chrono::high_resolution_clock; auto t1 = resolution_clock::now(); Classification classifiaction(font_id, display_char); - extract_titles.extract_titles(ImageView(input), ReferenceClassification(classifiaction)); + extract_titles.extract_titles(input, ReferenceClassification(classifiaction)); auto t2 = resolution_clock::now(); std::cerr << '\n' << std::chrono::duration(t2-t1).count() << "s\n"; diff --git a/src/capture/ocr/main/ppocr_extract_text.cpp b/src/capture/ocr/main/ppocr_extract_text.cpp index 9b1a8e0f59..1af643d68d 100644 --- a/src/capture/ocr/main/ppocr_extract_text.cpp +++ b/src/capture/ocr/main/ppocr_extract_text.cpp @@ -1,22 +1,21 @@ #include -#include #include #include #include #include +#include #include "capture/ocr/rgb8.hpp" +#include "capture/ocr/bitmap_as_ocr_image.hpp" #include "capture/ocr/extract_bars.hh" -#include "capture/ocr/image2dview.hpp" #include "capture/rdp_ppocr/extract_text.hpp" #include "capture/rdp_ppocr/get_ocr_constants.hpp" #include "capture/ocr/locale/latin_to_cyrillic.hpp" #include "capture/ocr/io_char_box.hpp" #include "capture/ocr/extract_text_classification.hh" - -using Image2dView = ocr::Image2dView; +using namespace std::string_view_literals; using resolution_clock = std::chrono::high_resolution_clock; @@ -34,7 +33,7 @@ struct Classification , display_char(display_char) {} - void operator()(Image2dView const & input, unsigned tid, mln::box2d const & box, unsigned button_col) + void operator()(ocr::BitmapAsOcrImage const & input, unsigned tid, mln::box2d const & box, unsigned button_col) { if (this->display_char) { mln::image2d ima; @@ -132,7 +131,7 @@ struct ReferenceClassification : ref(ref_) {} - void operator()(Image2dView const & input, unsigned tid, mln::box2d const & box, unsigned button_col) + void operator()(ocr::BitmapAsOcrImage const & input, unsigned tid, mln::box2d const & box, unsigned button_col) { this->ref(input, tid, box, button_col); } @@ -155,14 +154,14 @@ int main(int argc, char** argv) } ocr::fonts::LocaleId locale_id = ocr::fonts::LocaleId::latin; - chars_view dir = {argv[2], strlen(argv[2])}; + std::string_view dir = argv[2]; bool display_char = false; if (argc >= 4) { - if (strcmp(argv[3], "latin") == 0) { + if (argv[3] == "latin"sv) { locale_id = ocr::fonts::LocaleId::latin; } - else if (strcmp(argv[3], "cyrillic") == 0) { + else if (argv[3] == "cyrillic"sv) { locale_id = ocr::fonts::LocaleId::cyrillic; } else { @@ -171,7 +170,7 @@ int main(int argc, char** argv) } if (argc > 4) { - if ('d' != argv[4][0] || argv[4][1]) { + if (argv[4] == "d"sv) { usage(argv); return 4; } @@ -179,8 +178,8 @@ int main(int argc, char** argv) } } - mln::image2d input; - if (!mln::io::ppm::load(input, argv[1])) { + ocr::BitmapAsOcrImage input(argv[1]); + if (!input.is_valid()) { if (errno != 0) { std::cerr << argv[0] << ": " << strerror(errno) << std::endl; } @@ -194,7 +193,7 @@ int main(int argc, char** argv) auto t2 = resolution_clock::now(); std::cerr << "load: " << std::chrono::duration(t2-t1).count() << "s\n\n"; t1 = resolution_clock::now(); - extract_titles.extract_titles(Image2dView(input), ReferenceClassification(classification)); + extract_titles.extract_titles(input, ReferenceClassification(classification)); t2 = resolution_clock::now(); std::cerr << std::chrono::duration(t2-t1).count() << "s\n"; diff --git a/src/capture/utils/drawable_image_view.hpp b/src/capture/utils/drawable_image_view.hpp index 8431de6c0a..3cf9aaa8bb 100644 --- a/src/capture/utils/drawable_image_view.hpp +++ b/src/capture/utils/drawable_image_view.hpp @@ -21,19 +21,18 @@ #pragma once #include "utils/drawable.hpp" -#include "mln/core/point.hh" class DrawableImageView { - const Drawable & drawable; + const Drawable * drawable; unsigned w; unsigned h; public: - DrawableImageView(const Drawable & drawable_) - : drawable(drawable_) - , w(drawable_.width()) - , h(drawable_.height() > 50 ? drawable_.height() - 50 : 0) + DrawableImageView(const Drawable & drawable) + : drawable(&drawable) + , w(drawable.width()) + , h(drawable.height() > 50 ? drawable.height() - 50 : 0) // ignore last lines {} [[nodiscard]] unsigned width() const @@ -54,8 +53,7 @@ class DrawableImageView using value_type = Color; Color operator()(unsigned row, unsigned col) const - { return {this->drawable.data(int(col), int(row))}; } - - Color operator[](::mln::point2d p) const - { return {this->drawable.data(p.col(), p.row())}; } + { + return {this->drawable->data(int(col), int(row))}; + } }; diff --git a/targets.jam b/targets.jam index 04ad1d5500..1b154c1621 100644 --- a/targets.jam +++ b/targets.jam @@ -367,17 +367,32 @@ exe display_learning : exe extract_text : src/capture/ocr/main/extract_text.o : + crypto + png src/capture/ocr/locale/latin_to_cyrillic.o + src/core/error.o + src/utils/bitmap.o + src/utils/bitmap_data_allocator.o + src/utils/bitmap_from_file.o + src/utils/rle.o + src/utils/stacktrace.o src/utils/utf.o + $(BOOST_STACKTRACE_LINKFLAGS) ; exe ppocr_extract_text : src/capture/ocr/main/ppocr_extract_text.o : + crypto log_print.o + png ppocr src/capture/ocr/locale/latin_to_cyrillic.o src/core/error.o + src/utils/bitmap.o + src/utils/bitmap_data_allocator.o + src/utils/bitmap_from_file.o src/utils/drawable.o + src/utils/rle.o src/utils/stacktrace.o src/utils/strutils.o src/utils/utf.o