OpenCv基础学习(二)

    科技2023-09-29  76

    今日学习内容:

    获取图像像素指针掩膜操作演示代码演示

    获取图像像素指针

    Mat.ptr<uchar>(int i = 0) //ptr表示像素的指针吗,索引i表示第几行,从0开始计数

    获取当前行指针

    const*ptr current = myImage.ptr<uchar>(row);

    获取像素点P(row,col)的像素值

    p(row,col) = current[col]; //row表示行,col表示列

    像素处理函数saturate_cast< uchar >

    saturate_cast < uchar >(-100),返回值为0saturate_cast < uchar >(299),返回值为255saturate_cast < uchar >(125),返回值为125

    这个函数的功能是确保RGB值的范围在0~255的范围之间

    范例题目:使用掩膜操作改变图片的对比度 函数调用filter2D的功能

    定义掩膜:Mat kernel = (Mat_< char >(3,3)<<0,-1,0,-1,5,-1,0,-1,0,0);dilter2D(src,dst,src.depth(),kernel);其中src和dst是Mat类型变量、src.depth(),表示位图深度,有32、24、8.

    具体代码实现:

    Processed: 0.017, SQL: 8