Повысить ошибки чтения изображений

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

#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 дает другую ошибку …

РЕДАКТИРОВАТЬ:

Установленный 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

Решение

Вы пропали без вести включает

#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
1

Другие решения

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

Поскольку, расширения ввода / вывода были полностью переписаны в Boost.GIL выпущен в Увеличение 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

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector