1. 代码的括号注意位置,括号位置配对错了。。就不会对了。。。
2.cv::Mat img1 = cv::imread(left_files[i], -1); //-1 读取uint16 ??
(按原样返回加载的图像,如果有alpha通道,则加载的图像,也包含alpha通道,反之则没有alpha通道。为方便,编程时可以写成flags = -1).
opencv 3.3.1 文档
Mat cv::imread ( const String & filename,
int flags = IMREAD_COLOR
)
flags:
enum cv::ImreadModes {
cv::IMREAD_UNCHANGED = -1,
cv::IMREAD_GRAYSCALE = 0,
cv::IMREAD_COLOR = 1,
cv::IMREAD_ANYDEPTH = 2,
cv::IMREAD_ANYCOLOR = 4,
cv::IMREAD_LOAD_GDAL = 8,
cv::IMREAD_REDUCED_GRAYSCALE_2 = 16,
cv::IMREAD_REDUCED_COLOR_2 = 17,
cv::IMREAD_REDUCED_GRAYSCALE_4 = 32,
cv::IMREAD_REDUCED_COLOR_4 = 33,
cv::IMREAD_REDUCED_GRAYSCALE_8 = 64,
cv::IMREAD_REDUCED_COLOR_8 = 65,
cv::IMREAD_IGNORE_ORIENTATION = 128
}
3. 初始化 给zeros,注意通道数目
cv::Mat mTangeMask= cv::Mat::zeros(imgDepth.rows, imgDepth.cols, CV_8UC1);
4.问题:linux下free(): invalid next size (fast)的问题
一般是,free了不存在的变量(已经free过了);或者 访问越界; 操作不存在的指针等
最终发现问题在:
mTangeMask.at<int>(m,n)= 1;
这里的mTangeMask 是CV_8UC1,8 bits unsigned char== uchar,怎么能用 32 bits的 int访问呢? 改为:
mTangeMask.at<uchar>(m,n)= 1;
5. int main(int argc,char* argv[])传入的参数转成整数(int)
int a = atoi(argv[1]);
6.
depth()
返回是基本的数据类型,也就是说每个数据元素的类型,该函数并不关心矩阵cv::Mat的维度
// <interface.h>
#define CV_8U 0
#define CV_8S 1
#define CV_16U 2
#define CV_16S 3
#define CV_32S 4
#define CV_32F 5
#define CV_64F 6
#define CV_16F 7
type()
返回了 #矩阵相关的数据类型信息#,除元素的数据类型(低3们)外,还包括通道(channel)的个数(高3位),
举个例子来说,
cv::Mat test(100, 100, CV_32FC3);
int type = test.type();
int depth = test.depth();
这里
type得到的是CV_32FC3 == 0x15, 因为CV_32F==>0x05, (3-1)<<3 ==>0x10;
depth得到的是CV_32F,也就是0x05
//<interface.h>
#define CV_CN_MAX 512
#define CV_CN_SHIFT 3
#define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
#define CV_MAKE_TYPE CV_MAKETYPE
#define CV_8UC1 CV_MAKETYPE(CV_8U,1)
#define CV_8UC2 CV_MAKETYPE(CV_8U,2)
#define CV_8UC3 CV_MAKETYPE(CV_8U,3)
#define CV_8UC4 CV_MAKETYPE(CV_8U,4)
#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n))
#define CV_8SC1 CV_MAKETYPE(CV_8S,1)
#define CV_8SC2 CV_MAKETYPE(CV_8S,2)
#define CV_8SC3 CV_MAKETYPE(CV_8S,3)
#define CV_8SC4 CV_MAKETYPE(CV_8S,4)
#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n))
#define CV_16UC1 CV_MAKETYPE(CV_16U,1)
#define CV_16UC2 CV_MAKETYPE(CV_16U,2)
#define CV_16UC3 CV_MAKETYPE(CV_16U,3)
#define CV_16UC4 CV_MAKETYPE(CV_16U,4)
#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n))
#define CV_16SC1 CV_MAKETYPE(CV_16S,1)
#define CV_16SC2 CV_MAKETYPE(CV_16S,2)
#define CV_16SC3 CV_MAKETYPE(CV_16S,3)
#define CV_16SC4 CV_MAKETYPE(CV_16S,4)
#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n))
#define CV_32SC1 CV_MAKETYPE(CV_32S,1)
#define CV_32SC2 CV_MAKETYPE(CV_32S,2)
#define CV_32SC3 CV_MAKETYPE(CV_32S,3)
#define CV_32SC4 CV_MAKETYPE(CV_32S,4)
#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n))
#define CV_32FC1 CV_MAKETYPE(CV_32F,1)
#define CV_32FC2 CV_MAKETYPE(CV_32F,2)
#define CV_32FC3 CV_MAKETYPE(CV_32F,3)
#define CV_32FC4 CV_MAKETYPE(CV_32F,4)
#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n))
#define CV_64FC1 CV_MAKETYPE(CV_64F,1)
#define CV_64FC2 CV_MAKETYPE(CV_64F,2)
#define CV_64FC3 CV_MAKETYPE(CV_64F,3)
#define CV_64FC4 CV_MAKETYPE(CV_64F,4)
#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
#define CV_16FC1 CV_MAKETYPE(CV_16F,1)
#define CV_16FC2 CV_MAKETYPE(CV_16F,2)
#define CV_16FC3 CV_MAKETYPE(CV_16F,3)
#define CV_16FC4 CV_MAKETYPE(CV_16F,4)
#define CV_16FC(n) CV_MAKETYPE(CV_16F,(n))
7. 积分图
void cv::integral (
InputArray src,
OutputArray sum,
OutputArray sqsum,
OutputArray tilted,
int sdepth = -1,
int sqdepth = -1
)
Parameters
src | input image as W×H, 8-bit or floating-point (32f or 64f). |
sum | integral image as (W+1)×(H+1) , 32-bit integer or floating-point (32f or 64f). |
sqsum | integral image for squared pixel values; it is (W+1)×(H+1), double-precision floating-point (64f) array. |
tilted | integral for the image rotated by 45 degrees; it is (W+1)×(H+1) array with the same data type as sum. |
sdepth | desired depth of the integral and the tilted integral images, CV_32S, CV_32F, or CV_64F. |
sqdepth | desired depth of the integral image of squared pixel values, CV_32F or CV_64F. |