当前位置: 首页 > news >正文

OpenCV之reshape函数

函数原型:

/** @brief Changes the shape and/or the number of channels of a 2D matrix without copying the data.The method makes a new matrix header for \*this elements. The new matrix may have a different sizeand/or different number of channels. Any combination is possible if:-   No extra elements are included into the new matrix and no elements are excluded. Consequently,the product rows\*cols\*channels() must stay the same after the transformation.-   No data is copied. That is, this is an O(1) operation. Consequently, if you change the number ofrows, or the operation changes the indices of elements row in some other way, the matrix must becontinuous. See Mat::isContinuous .For example, if there is a set of 3D points stored as an STL vector, and you want to represent thepoints as a 3xN matrix, do the following:@codestd::vector<Point3f> vec;...Mat pointMat = Mat(vec). // convert vector to Mat, O(1) operationreshape(1). // make Nx3 1-channel matrix out of Nx1 3-channel.// Also, an O(1) operationt(); // finally, transpose the Nx3 matrix.// This involves copying all the elements@endcode@param cn New number of channels. If the parameter is 0, the number of channels remains the same.@param rows New number of rows. If the parameter is 0, the number of rows remains the same.*/Mat reshape(int cn, int rows=0) const;

 cn表示通道数,默认为0,表示跟原图通道数一致,

rows表示行数,rows默认为0表示跟原图排列一致;

若原图大小为MxN

当rows=1时,输出矩阵为1x(M*N);

当rows=M*N时,输出 (M*N)x1。

测试1:

Mat src(3, 3, CV_8UC1, Scalar(1));//通道数为1的3*3矩阵,值为1
Mat dst = src.reshape(0, 1);
cout << dst << endl;

输出:

[ 1,  1,  1,  1,  1,  1,  1,  1,  1]

 测试2:

Mat src(3, 3, CV_8UC1, Scalar(2));//通道数为1的3*3矩阵,值为1
Mat dst = src.reshape(0, 3*3);
cout << dst << endl;

输出:

[ 1; 1; 1;  1;  1;  1;  1;  1;  1]

http://www.lryc.cn/news/141898.html

相关文章:

  • 【JavaEE】Spring事务-@Transactional参数介绍-事务的隔离级别以及传播机制
  • 微信小程序canvas type=2d生成海报保存到相册、文字换行溢出显示...、文字删除线、分享面板
  • C++卷积神经网络
  • go 读取yaml映射到struct
  • Redis 10 大数据类型
  • 优化生产流程:数字化工厂中的OPC UA分布式IO模块应用
  • Elasticsearch(十四)搜索---搜索匹配功能⑤--全文搜索
  • 已解决Gradle错误:“Unable to load class ‘org.gradle.api.plugins.MavenPlugin‘”
  • windows中安装sqlite
  • 前端面试:【系统设计与架构】前端架构模式的演进
  • 【CSS】em单位的理解
  • 无涯教程-Python机器学习 - Based on human supervision函数
  • 【滑动窗口】leetcode209:长度最小的子数组
  • C++ STL unordered_map
  • 全流程R语言Meta分析核心技术应用
  • Go并发可视化解释 - Select语句
  • 在线SM4(国密)加密解密工具
  • golang的类型断言语法
  • 提速换挡 | 至真科技用技术打破业务壁垒,助力出海破局增长
  • 第3篇:vscode搭建esp32 arduino开发环境
  • Apache Shiro是什么
  • Socket基本原理
  • Docker容器:本地私有仓库、harbor私有仓库部署与管理
  • Mobx在非react组件中修改数据,在ts/js中修改数据实现响应式更新
  • 什么是异步编程?什么是回调地狱(callback hell)以及如何避免它?
  • Java8 Stream流常见操作--持续更新中
  • 【Linux】多线程概念线程控制
  • Qt --- 自定义提示框 类似QMessagebox
  • Redis 分布式锁与 Redlock 算法实现
  • 【附安装包】Inventor2024安装教程 机械制图|三维制图