gpt4 book ai didi

c++ - 如何将内存图像分配给 DLIB array2d 或图像?

转载 作者:太空狗 更新时间:2023-10-29 23:13:03 26 4
gpt4 key购买 nike

这可能更像是一个 C++ 问题,但它确实与 DLIB 相关。我正在使用另一个库将图像加载到内存中 (Leadtools)。我想用赋值替换“load_image”函数,但我不知道该怎么做。我已从加载中分配了我需要的所有信息和内存,例如像素位深度、宽度、高度、width_step、rgb/bgr 顺序和指向数据的指针。

所以在示例中,有:

array2d<bgr_pixel> img;

我能做到:

img.set_size(mywidth, myheight);

但是(假设数据 mypointer 是 bgr contiguous char * bytes):

img.data = mydatapointer;  

不起作用 - 没有 img.data,而且我不知道如何使用 image_view。

设置数据指针的正确方法是什么?请注意,我不想复制内存:-)

为了模拟 load_image 并在 dlib 中使用正确的结构,是否还有其他需要设置的东西?

TIA

最佳答案

基于 Davis King 的评论。

为了避免将数据从您自己的图像结构复制到 dlib 内部格式,dlib 允许您实现一个通用图像接口(interface),该接口(interface)将允许 dlib 直接使用您的图像。需要实现的接口(interface)如下所示:

    In dlib, an "image" is any object that implements the generic image interface.  In
particular, this simply means that an image type (let's refer to it as image_type
from here on) has the following seven global functions defined for it:
- long num_rows (const image_type& img)
- long num_columns (const image_type& img)
- void set_image_size( image_type& img, long rows, long cols)
- void* image_data ( image_type& img)
- const void* image_data (const image_type& img)
- long width_step (const image_type& img)
- void swap ( image_type& a, image_type& b)
And also provides a specialization of the image_traits template that looks like:
namespace dlib
{
template <>
struct image_traits<image_type>
{
typedef the_type_of_pixel_used_in_image_type pixel_type;
};
}

您可以在此处找到更多详细信息: http://dlib.net/dlib/image_processing/generic_image.h.html

关于c++ - 如何将内存图像分配给 DLIB array2d 或图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41991651/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com