opencv reshape函数说明
转自http://blog.csdn.net/yang6464158/article/details/20129991
reshape有两个参数:
其中,参数:cn为新的通道数,如果cn = 0,表示通道数不会改变。
参数rows为新的行数,如果rows = 0,表示行数不会改变。
注意:新的行*列必须与原来的行*列相等。就是说,如果原来是5行3列,新的行和列可以是1行15列,3行5列,5行3列,15行1列。仅此几种,否则会报错。
具体调用也很简单,代码如下所示:
- #include <iostream>
- #include <opencv/cv.h>
- #include <opencv/highgui.h>
- int main()
- {
- cv::Mat testMat = cv::Mat::zeros ( 5, 3, CV_8UC3 );
- std::cout << "size of testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
- std::cout<<"testMat = "<<testMat<<std::endl;
- cv::Mat result = testMat.reshape ( 0, 3 );
- std::cout << " size of original testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
- std::cout << " size of reshaped testMat: " << result.rows << " x " << result.cols << std::endl;
- std::cout << "result = " << result << std::endl;
- cv::waitKey(0);
- system("pause");
- return 0;
- }
结果如下:
比如说:下面的情况就会报错:
- #include <iostream>
- #include <opencv/cv.h>
- #include <opencv/highgui.h>
- int main()
- {
- cv::Mat testMat = cv::Mat::ones ( 5, 3, CV_8UC3 );
- std::cout << "size of testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
- std::cout<<"testMat = "<<testMat<<std::endl;
- cv::Mat result = testMat.reshape ( 0, 6 );
- std::cout << " size of original testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
- std::cout << " size of reshaped testMat: " << result.rows << " x " << result.cols << std::endl;
- std::cout << "result = " << result << std::endl;
- cv::waitKey(0);
- system("pause");
- return 0;
- }
因为行和列的乘积不相等
结果如下:
我们在使用reshape的时候一定不能用定义的Mat类型赋给原来的类型,必须重新定义一个新类。
可以这样:
- unsigned char v11[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
- cv::Mat A = cv::Mat(3, 4, CV_8U, v11);
- cv::Mat B = A.reshape(1, 12);
但不能这样:
- cv::Mat testMat = cv::Mat::zeros ( 5, 3, CV_8UC3 );
- std::cout << "size of testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
- testMat.reshape ( 0, 1 );
- std::cout << " size of reshaped testMat: " << testMat.rows << " x " << testMat.cols << std::endl;
opencv reshape函数说明的更多相关文章
- opencv3学习:reshape函数
在opencv中,reshape函数比较有意思,它既可以改变矩阵的通道数,又可以对矩阵元素进行序列化,非常有用的一个函数. 函数原型: C++: Mat Mat::reshape() const 参数 ...
- Matlab 的reshape函数
看Matlab的help文档讲得不是清楚. 先给上一段代码: >> a=[1 2 3;4 5 6;7 8 9;10 11 12]; >> b=reshape(a,2,6); 这 ...
- Matlab 的reshape函数(转)
看Matlab的help文档讲得不是清楚. 先给上一段代码: >> a=[1 2 3;4 5 6;7 8 9;10 11 12]; >> b=reshape(a,2,6); 这 ...
- OpenCV reshape The Matrix is not continuous, thus its number of rows can not be changed
When using OpenCV reshape and gets this error: OpenCV Error: Image step is wrong (The matrix is not ...
- python numpy.shape 和 numpy.reshape函数
导入numpy模块 from numpy import * import numpy as np ############################################### ...
- opencv-6-图像绘制与opencv Line 函数剖析
opencv-6-图像绘制与opencv Line 函数剖析 opencvc++qt 开始之前 越到后面, 写的越慢, 之前还抽空去看了下 学堂在线那篇文章提供的方法, 博客第一个人评论的我, 想想还 ...
- 【记录一个问题】macos下lldb调试opencv的一个程序,出现“failed to load objfile for”错误,并且无法调试进入opencv的函数
opencv编译使用了Debug版本,打开了BUILD_WITH_DEBUG_INFO=ON选项. 发现问题后,我又在CMAKE_CXX_FLAGS_DEBUG中设置为 -g -ggdb3,在CMAK ...
- 学习OpenCV——Gabor函数的应用
原文:http://blog.csdn.net/yao_zhuang/article/details/2532279 下载cvgabor.cpp和cvgabor.h到你的C/C++工程目录下 注:在我 ...
- 【麦子学院】OpenCV教程函数总结
个自带样例. parter 1: No1. adaptiveskindetector.cpp 利用HSV空间的色调信息的皮肤检測,背景不能有太多与肤色相似的颜色.效果不是特别好. No2. bagof ...
随机推荐
- Spring_总结_04_高级配置(一)_Profile
一.前言 本文承接上一节:Spring_总结_03_装配Bean(四)之导入与混合配置 这一节,来总结一下profile. 我们在开发软件时,通常会进行跨环境部署.而在跨环境部署时,经常会遇到某些环境 ...
- 条款47:请使用traits class表示类型信息
在stl的算法中,我们的希望往往是根据不同的迭代器类型进行不同的更有效率的操作: template<typename IterT, typename DistT> void advance ...
- 201621123014《Java程序设计》第十四周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结与数据库相关内容. 2. 使用数据库技术改造你的系统 2.1 简述如何使用数据库技术改造你的系统.要建立什么表?截图你的表设计. 答 ...
- NYOJ-626-intersection set(二分查找)
题目链接 /* Name:NYOJ-626-intersection set Copyright: Author: Date: 2018/4/12 21:30:10 Description: 二分查找 ...
- SQL Server数据文件迁移
需求:源SQL Server安装目录及数据目录 与 目标SQL Server安装目录及数据目录 完全不同. 步骤: 1.拷贝源数据目录下需要移植的库文件(rpBrInfo_TA.mdf.rpBrInf ...
- 【java规则引擎】简单规则的rete网络示意图
一个Fact通过Session添加到规则网络中,如何进行规则匹配的大致过程如下 (1)通过根结点对象从EntryPointNode的Map集合中找到相应的EntryPointNode对象 (2)Ent ...
- python模型字段
http://python.usyiyi.cn/translate/django_182/ref/models/fields.html#model-field-types
- swing之gridlayout
package gui1; import java.awt.FlowLayout; import java.awt.GridLayout; import javax.swing.JButton; im ...
- webpack入门(四)——webpack loader 和plugin
什么是loader loaders是你用在app源码上的转换元件.他们是用node.js运行的,把源文件作为参数,返回新的资源的函数. 例如,你可以用loaders告诉webpack加载 coffee ...
- liferay-ui:search-container reset cur page 当点列排序时,把当前页号重置为1.
问题描述: liferay里面要用liferay-ui:search-container 来展示结果集.并要求点列时,可以排序.然后,如果当前页数不为1时,点列排序,自动设置为1. 解决: // 列排 ...