1
我正在尝试在Python中使用libccv(我使用SWIG创建了包装器)。我的情况是这样的:libccv - 如何从内存中的字节读取图像
- 我已经在内存中的图像
- 我想通过这种图像(字节)C函数,裹的Python与SWIG。
- 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或th e image
变量是0
。
我不想使用ccv_read
函数重载,它采用文件路径,因为我不想介绍将映像写入磁盘的开销。
什么是使用libccv从内存中读取图像的正确方法?
您传递给C函数的指针是有效的(* bytes ptr)?我的意思是,一个健全的检查可能是好的,以防万一。 – phyloflash
是的,它是有效的。我可以用C函数中的''''fwrite()''将这些字节写回到文件中,并且它产生完全相同的图像。 –