数据存取
在C++中读取cv::Mat的数据时, 如果数据不是8位单字节的, 不能使用mat.data[i]的形式读取, 因为data是char *型指针.
读取需要指定数据类型, 如mat.at<float>(i).
如果使用指针, 需要注意内存是否连续, 如下所示:
int nRows = image.rows ;
int nCols = image.cols * image.channels() ;
if(image.isContinuous())
{
nCols = nRows * nCols ;
nRows = 1 ;
}
for(int h = 0 ; h < nRows ; ++ h)
{
uchar *ptr = image.ptr<uchar>(h) ;
for(int w = 0 ; w < nCols ; ++ w)
{
//ptr[w] = 128 ;
*ptr ++ = 128 ;
}
}
数据赋值
mat2=mat1是浅拷贝, 深拷贝的方式为mat2=mat1.clone()
花屏问题
使用opecv处理后的图片,少数几张会花屏。用了几个小时后, 最终定位到问题了:
cv::copyMakeBorder 的src和dst用一个变量 加 imageROI功能 加 pybind11 合用引起的bug
另外像这个函数也不能src和dst用一个变量
imageROI.convertTo(t_imageROI, CV_32F);
windows平台没有触发这个bug, 而在linux平台上就会触发,测了十几张图片,有一张能触发这个BUG。