【发布时间】:2017-08-10 09:02:30
【问题描述】:
我正在尝试将 libccv 与 Python 一起使用(我已经使用 SWIG 创建了包装器)。我的情况如下:
- 我有内存图像
- 我想将此图像(字节)传递给 C 函数,用 SWIG 为 Python 包装。
- C 代码将使用
libccv函数处理图像
Python 代码:
bytes = open("input.jpg","rb").read()
result = ccvwrapper.use_ccv(bytes, 800, 600)
C 代码:
int use_ccv(char *bytes, int width, int height){
int status = 0;
ccv_enable_default_cache();
ccv_dense_matrix_t* image = 0;
ccv_read(bytes, &image, CCV_IO_ANY_RAW, width, height, width * 3);
if (image != 0)
{
//process the image
ccv_matrix_free(image);
status = 1;
}
ccv_drain_cache();
return status;
}
我尝试了ccv_read 的type, rows, cols, scanline 参数的一些组合,但每次我得到SIGSEV 或image 变量都是0。
我不想使用ccv_read函数重载,它需要文件路径,因为我不想引入将图像写入磁盘的开销。
使用 libccv 从内存中读取图像的正确方法是什么?
【问题讨论】:
-
您传递给 C 函数的指针是否有效(*bytes ptr)?我的意思是,为了以防万一,进行健全性检查可能会很好。
-
是的,它是有效的。我可以在 C 函数中使用
fwrite()将这些字节写回文件,它会产生完全相同的图像。
标签: python c computer-vision swig