如何将内存映像分配给DLIB array2d或映像? [英] How to assign memory images to a DLIB array2d or image?
问题描述
这可能更多是c ++问题,但确实与DLIB有关.我正在使用另一个库将图像加载到内存中(Leadtools).我想用赋值替换"load_image"函数,但是我很难弄清楚该怎么做.我已经从负载中分配了我需要分配的所有信息和内存,例如像素位深度,宽度,高度,width_step,rgb/bgr顺序以及指向数据的指针.
This is likely more of a c++ question, but it does relate to DLIB. I am using another library to load images into memory (Leadtools). I want to replace the "load_image" function with assignments, but I am having trouble figuring out how to do so. I have all the information and memory allocated I need from my load, such as pixel bit depth, width, height, width_step, rgb/bgr order, and a pointer to the data.
因此在示例中,有:
array2d<bgr_pixel> img;
我可以这样做:
img.set_size(mywidth, myheight);
但是(假设数据mypointer是bgr连续char *字节):
But (assuming the data mypointer is bgr contiguous char * bytes):
img.data = mydatapointer;
不起作用-没有img.data,而且我不知道如何使用image_view.
does not work - there is no img.data, plus I can't figure out how to use image_view.
设置该数据指针的正确方法是什么?请注意,我不想复制内存:-)
What is the right way to setup that data pointer? Note that I do NOT want to duplicate memory :-)
为了模拟load_image并在dlib中使用正确的结构,还有其他需要设置的东西吗?
Is there anything else that needs setting in order to simulate the load_image and have the correct structure to use within dlib?
TIA
推荐答案
基于戴维斯·金(Davis King)的评论.
Based on Davis King's comment.
为避免将数据从您自己的图像结构复制到dlib内部格式,dlib允许您实现一个通用的图像接口,该接口将允许dlib直接使用您的图像.需要实现的接口如下:
To avoid copying data from your own image structure to dlib internal format, dlib allows you to implement a generic image interface that will allows dlib to use directly your image. The interface that needs to be implemented looks like this:
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
You can find more details here: http://dlib.net/dlib/image_processing/generic_image.h.html
这篇关于如何将内存映像分配给DLIB array2d或映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!