opencv开发之路

opencv学习过程

一.编译环境

1.Android NDK
2.opencv 3.4 android sdk

二.opencv 基本理解

Mat数据类型,指定了数据通道数、宽和高。

  • 1.opencv中的函数打大部分只能针对简单的、规则的 通道数的数据格式处理,如 RGB,RGBA,GRAY
  • 2.对于复杂的yuv格式,必须对每一个通道分别处理。对YUYV格式没有处理函数
    对于规则的GRB格式处理比较简单,对于复杂的图形,opencv 没有明确的支持处理,需要自行解决

三. opencv 常用函数

1.cvtColor

imgproc.hpp
如COLOR_RGB2BGR

//C++,本质是修改mat中数据的排列方式。头文件为color.hpp
void cvtColor( InputArray _src, OutputArray _dst, int code/转换类型/, int dcn/目标通道数目/ )
//code在[imgproc.hpp](https://gitee.com/vicent_zeng/opencv/blob/master/modules/imgproc/include/opencv2/imgproc.hpp#155)中定义
#python
image_hsv = cv2.cvtColor(image_src,cv2.COLOR_BGR2HSV)

2.Mat

构造函数:
Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP); //直接用指针初始化Mat,浅copy。

3.imread

Mat imread( const String& filename, int flags )

enum ImreadModes {
       IMREAD_UNCHANGED            = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).
       IMREAD_GRAYSCALE            = 0,  //!< If set, always convert image to the single channel grayscale image.
       IMREAD_COLOR                = 1,  //!< If set, always convert image to the 3 channel BGR color image.
       IMREAD_ANYDEPTH             = 2,  //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
       IMREAD_ANYCOLOR             = 4,  //!< If set, the image is read in any possible color format.
       IMREAD_LOAD_GDAL            = 8,  //!< If set, use the gdal driver for loading the image.
       IMREAD_REDUCED_GRAYSCALE_2  = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.
       IMREAD_REDUCED_COLOR_2      = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.
       IMREAD_REDUCED_GRAYSCALE_4  = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.
       IMREAD_REDUCED_COLOR_4      = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.
       IMREAD_REDUCED_GRAYSCALE_8  = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8.
       IMREAD_REDUCED_COLOR_8      = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.
       IMREAD_IGNORE_ORIENTATION   = 128 //!< If set, do not rotate the image according to EXIF's orientation flag.
     };
4. threshold:固定阈值二值化
//C++
double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double maxval, int type )
#python
ret, dst = threshold(src, thresh, maxval, type)
	src: 输入图,单通道如U8C1   dst : 输出图 thresh:阈值
	maxval: 当像素值超过了阈值(或者小于阈值,根据type来决定),所赋予的值
	type: 二值化操作的类型,包含以下5种类型: 
THRESH_BINARY
THRESH_BINARY_INV
THRESH_TRUNC
THRESH_TOZERO
THRESH_TOZERO_INV
5.bitwise_and、bitwise_or、bitwise_xor、bitwise_not 四个按位操作函数。
void bitwise_and(InputArray src1, InputArray src2,OutputArray dst, InputArray mask=noArray());//dst = src1 & src2
void bitwise_or(InputArray src1, InputArray src2,OutputArray dst, InputArray mask=noArray());//dst = src1 | src2
void bitwise_xor(InputArray src1, InputArray src2,OutputArray dst, InputArray mask=noArray());//dst = src1 ^ src2
void bitwise_not(InputArray src, OutputArray dst,InputArray mask=noArray());//dst = ~src

四 项目实践

1.bayer 灰度图

imread(imgbuffer);
Mat mat(h,w, U8C1,imgbuffer)
cvtColor(); //bayer转灰度图

2.贴图

博客之星

opencv python 图像金字塔
https://segmentfault.com/a/1190000015661093

opencv python 直方图
https://segmentfault.com/a/1190000015674654

opencv python 角点检测/FAST算法
https://segmentfault.com/a/1190000015731543

opencv python 图像缩放/图像平移/图像旋转/仿射变换/透视变换
https://segmentfault.com/a/1190000015645951

opencv python 图像金字塔
https://segmentfault.com/a/1190000015661093

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值