Повысить ошибки чтения изображений - PullRequest
0 голосов
/ 02 июля 2018

Я хотел написать простую программу для чтения и редактирования изображений с помощью boost :: gil. Ошибка происходит всегда с функцией чтения изображения. Я продолжаю учебники, найденные на буст-сайте.

#include <iostream>
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>
#include <boost/gil/extension/dynamic_image/any_image.hpp>
#include <boost/gil/channel.hpp>
#include <boost/mpl/vector.hpp>

int main(int argc, char *argv[])
{
    namespace bg = boost::gil;
    static const std::string resources_dir = "../resources";
    static const std::string filename = "face.jpg";
    typedef boost::mpl::vector<bg::gray8_image_t, bg::gray16_image_t, bg::rgb8_image_t, bg::rgb16_image_t> my_img_types;

    bg::any_image<my_img_types> runtime_image;
    try{
    bg::jpeg_read_image(resources_dir + filename, runtime_image);
    } catch (const std::ios_base::failure &e) {
        std::cout << e.what() << std::endl;
    }

    return 0;
}

Ошибка довольно длинная, не знаю, что не так. Похоже на передачу неподдерживаемого типа изображения в шаблон изображения, но оно отображается независимо от аргументов - я также попытался передать один тип.

[ 50%] Building CXX object src/CMakeFiles/edges.dir/main.cpp.o
In file included from /usr/include/boost/config.hpp:57:0,
             from /usr/include/boost/gil/gil_config.hpp:24,
             from /usr/include/boost/gil/gil_all.hpp:25,
             from /home/mateusz/projects/edges1/src/main.cpp:2:
/usr/include/boost/gil/extension/io/jpeg_io.hpp: In instantiation of ‘const bool boost::gil::jpeg_read_support<boost::gil::any_image_view<boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::vector0<mpl_::na>, 0>, 0>, 0>, 0> > >::is_supported’:
/usr/include/boost/gil/extension/io/jpeg_io.hpp:91:5:   required from ‘void boost::gil::jpeg_read_image(const char*, Image&) [with Image = boost::gil::any_image<boost::mpl::vector<boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> > > >]’
/usr/include/boost/gil/extension/io/jpeg_io.hpp:101:40:   required from ‘void boost::gil::jpeg_read_image(const string&, Image&) [with Image = boost::gil::any_image<boost::mpl::vector<boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> >, boost::gil::image<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >, false, std::allocator<unsigned char> > > >; std::string = std::basic_string<char>]’
/home/mateusz/projects/edges1/src/main.cpp:18:64:   required from here
/usr/include/boost/gil/extension/io/jpeg_io.hpp:40:5: error: invalid use of incomplete type ‘struct boost::gil::channel_type<boost::gil::any_image_view<boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::vector0<mpl_::na>, 0>, 0>, 0>, 0> > >’
     BOOST_STATIC_CONSTANT(bool,is_supported=
     ^
In file included from /usr/include/boost/gil/algorithm.hpp:25:0,
             from /usr/include/boost/gil/gil_all.hpp:27,
             from /home/mateusz/projects/edges1/src/main.cpp:2:
/usr/include/boost/gil/gil_concept.hpp:49:30: error: declaration of ‘struct boost::gil::channel_type<boost::gil::any_image_view<boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<short unsigned int, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::v_item<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t> > >*> > >, boost::mpl::vector0<mpl_::na>, 0>, 0>, 0>, 0> > >’
 template <typename T> struct channel_type;

Я тоже новичок в написании CMakeLists.txt, поэтому я включил эти файлы. CMakeLists в главной папке:

cmake_minimum_required(VERSION 2.8)
project(edges1)

set(CMAKE_BUILD_TYPE "Debug")
add_subdirectory(src)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})

CMakeLists.txt в папке src:

set(SOURCES main.cpp)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)

find_package(Boost REQUIRED COMPONENTS)
include_directories(${BOOST_INCLUDE_DIRS})

#link_directoires(${CMAKE_SOURCE_ROOT}/lib)
#link_directoires(${LIBRARY_OUTPUT_PATH})
add_executable(edges ${SOURCES})

использование read_and_convert_image дает другую ошибку ...

EDIT:

Установленные libjpeg, CMakeLists в каталоге src:

set(SOURCES main.cpp)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
add_executable(edges ${SOURCES})

find_package(Boost REQUIRED COMPONENTS)
IF(BOOST_FOUND)
  target_link_libraries(edges Boost::boost)
ENDIF()
find_package(JPEG REQUIRED)
IF(JPEG_FOUND)
  include_directories(${JPEG_INCLUDE_DIR})
  target_link_libraries(edges ${JPEG_INCLUDE_DIR})
ENDIF()

команда cmake:

cmake -DJPEG_LIBRARY:PATH=/usr/lib/x86_64-linux-gnu/libjpeg.so --libdir=/usr/lib64 ..

после изготовления:

[ 50%] Linking CXX executable ../edges
CMakeFiles/edges.dir/main.cpp.o: In function `boost::gil::detail::jpeg_reader::init()':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:89: undefined reference to `jpeg_std_error'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:90: undefined reference to `jpeg_CreateDecompress'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:91: undefined reference to `jpeg_stdio_src'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:92: undefined reference to `jpeg_read_header'
CMakeFiles/edges.dir/main.cpp.o: In function `boost::gil::detail::jpeg_reader::~jpeg_reader()':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:98: undefined reference to `jpeg_destroy_decompress'
CMakeFiles/edges.dir/main.cpp.o: In function `void boost::gil::detail::jpeg_reader::apply<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > >*> > > >(boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector1<boost::gil::gray_color_t>, boost::mpl::range_c<int, 0, 1> > >*> > > const&)':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:102: undefined reference to `jpeg_start_decompress'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:111: undefined reference to `jpeg_read_scanlines'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:115: undefined reference to `jpeg_finish_decompress'
CMakeFiles/edges.dir/main.cpp.o: In function `void boost::gil::detail::jpeg_reader::apply<boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t>, boost::mpl::range_c<int, 0, 3> > >*> > > >(boost::gil::image_view<boost::gil::memory_based_2d_locator<boost::gil::memory_based_step_iterator<boost::gil::pixel<unsigned char, boost::gil::layout<boost::mpl::vector3<boost::gil::red_t, boost::gil::green_t, boost::gil::blue_t>, boost::mpl::range_c<int, 0, 3> > >*> > > const&)':
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:102: undefined reference to `jpeg_start_decompress'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:111: undefined reference to `jpeg_read_scanlines'
/usr/include/boost/gil/extension/io/jpeg_io_private.hpp:115: undefined reference to `jpeg_finish_decompress'

все еще проблема с jpeg, но включение всех трех файлов с расширением / io не работает: (

Ответы [ 2 ]

0 голосов
/ 18 сентября 2018

Ответ, предоставленный @sehe, совершенно корректен для GIL, выпущенного в Boost 1.67 или более ранних версиях.

С тех пор, как расширения ввода / вывода были полностью переписаны в Boost.GIL, выпущенном в Boost 1,68 , ваш пример нуждается в корректировках. Вот обновленная минимальная версия:

#include <boost/gil.hpp>
#include <boost/gil/extension/dynamic_image/any_image.hpp>
#include <boost/gil/extension/io/jpeg.hpp>
#include <boost/mpl/vector.hpp>

int main()
{
    namespace bg = boost::gil;
    using my_img_types = boost::mpl::vector<bg::gray8_image_t, bg::gray16_image_t, bg::rgb8_image_t, bg::rgb16_image_t>;
    bg::any_image<my_img_types> runtime_image;
    bg::read_image("file.jpg", runtime_image, bg::jpeg_tag());
}

Также стоит отметить, что для последней версии Boost.GIL теперь требуется компилятор, совместимый с C ++ 11 .

0 голосов
/ 04 июля 2018

Вам не хватает включает

#include <boost/gil/extension/io/dynamic_io.hpp>
#include <boost/gil/extension/io/jpeg_dynamic_io.hpp>

Затем компилирует и ссылки:

g++ -Wall -Wextra -pedantic -pthread -o sotest test.cpp -ljpeg
...