shouxieai / infer

A new tensorrt integrate. Easy to integrate many tasks
MIT License
388 stars 80 forks source link

关于Image结构体 #10

Closed jstzwjr closed 1 year ago

jstzwjr commented 1 year ago

你好,我想请教下关于Image数据传递的问题。 Image(const uint8_t bgrptr, int width, int height) : bgrptr(bgrptr), width(width), height(height) {} Image(const uint8_t data_device, int width, int height, int device_id, cudaStream_t stream, ImageType type) : device_data(data_device), width(width), height(height), device_id(device_id), stream(stream), type(type) {} 好像只做了bgrptr地址的赋值,并没有进行memcpy操作。 下面的代码,如果必须在循环内定义Mat变量,每次循环commit过后,img指向的内存有可能在推理之前释放吗 int main() { cv::VideoCapture cap("1.mp4"); while(1) { cv::Mat img; cap.read(img); cpm.commit(img); } }

shouxieai commented 1 year ago

Image is a lightweight design, it does not copy your image data. Here it is left to you to manage the life cycle of the image data. That can greatly simplify the complexity of multi-threaded.

You should ensure that the data is not freed until the result is received. Of course, you can modify the CPM code to allow the input data to be freed as soon as it is consumed.

The same issue has been discussed here.