OpenCV2411 数据类型
2016-03-05 18:58
393 查看
#include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int OpenCVDataTypes() { ////point 类 cv::Point2d p2d(0,1); cv::Point2d p2d_2(6,7); cv::Point3i p3i(12,25,56); cv::Point3d p3d(p3i); //寻址方式 cout<<"Point3d:"<<p3d.x<<" "<<p3d.y<<" "<<p3d.z<<endl; //点积 double dot_p3d=p3i.dot(p3d); cout<<"the dot p3d:"<<dot_p3d<<endl; ////Scalar类 cv::Scalar s(1,2,4,5); //寻址方式 cout<<"the Scalar: "<<s[0]<<" "<<s[1]<<" "<<s[2]<<" "<<s[3]<<endl; ////Size 类 cv::Size sz(10,13); //寻址方式 cout<<"the size, width="<<sz.width<<" , height="<<sz.height<<endl; ////矩阵Rect 类 cv::Rect re(1,2,7,8); cv::Rect re2(p2d,sz); //寻址方式 cout<<"the Rect, x="<<re2.x<<", y="<<re2.y<<", width=" <<re2.width<<", height="<<re2.height<<endl; //旋转矩阵 RotateRect 类 cv::RotatedRect rre(p2d,sz,0);//(center,size,angle) //cv::RotatedRect rre2(p2d,p2d_2);//两个corner, 有误 //寻址方式 cout<<"RotateRect:\n \tthe center: x="<<rre.center.x<<", y="<<rre.center.y <<", \n \tthe size: width="<<rre.size.width<<", height="<<rre.size.height <<", \n \tthe angle="<<rre.angle<<endl; ////The Fixed Matrix Classes cv::Matx 类 cv::Matx44f m44f=cv::Matx44f::randn(4,6); //指定每个元素值 cv::Matx22d m22d(4,5,6,7); //寻址方式 cout<<"the cv::Matx44f\n"; for(int i=0;i<4;i++) { cout<<"\n\t"; for(int j=0;j<4;j++) cout<<m44f(i,j)<<" "; cout<<endl; } ////The Fixed Vector Classes cv::Vec<> cv::Vec3d v3d(1,2,3); cout<<"\nVec3d:\n"<<"\t "<<v3d[0]<<" "<<v3d(1)<<" "<<v3d[2] <<endl; ////The Complex Number Classes cv::Complex<> cv::Complexd cpd(8,-10); //寻值方式 cout<<"\nComplexd, real="<<cpd.re<<", image="<<cpd.im<<endl; //判定方式 TermCriteria( int type, int maxCount, double epsilon ) cv::TermCriteria tc(cv::TermCriteria::COUNT|cv::TermCriteria::EPS, 15,0.01); ////cv::Range 连续的整数序列 cv::Range rg(0,6); //寻值方式 cout<<"\nthe range, size"<<rg.size()<<" Range start "<<rg.start<<" Range End "<<rg.end <<endl; //static Range all() 何用? ////cv::Mat 大矩阵类 //cv::Mat( int rows, int cols, int type, const Scalar& s ); cv::Mat m(3,10,CV_32FC3,cv::Scalar(1.0f,2.0f,3.0f)); //cv::Mat( cv::Size sz, int type ); cv::Mat m2(cv::Size(100,100),CV_32FC3); //cv::Mat( const Mat& mat, const cv::Range& rows, const cv::Range& cols ); cv::Mat m3(m2,cv::Range(0,5),cv::Range(0,5)); //二维矩阵单通道寻值方式 cv::Mat m4 = cv::Mat::eye(10, 10, CV_32FC1); printf( "cv::Mat \n\tElement (3,3) is %f\n", m4.at<float>(3,3) //(row, col) ); //二维矩阵多通道寻值方式 cv::Mat m5 = cv::Mat::eye( 10, 10, CV_32FC2); printf( "cv::Mat \n\tElement (3,3) is (%f,%f)\n", m5.at<cv::Vec2f>(3,3)[0], m5.at<cv::Vec2f>(3,3)[1] ); //类似二维矩阵多通道的取值方式 cv::Mat m6 = cv::Mat::eye( 10, 10, cv::DataType<cv::Complexf>::type ); printf( "Element (3,3) is %f + i%f\n", m6.at<cv::Complexf>(3,3).re, m6.at<cv::Complexf>(3,3).im ); //iterator遍历寻址 int sz2[3]={4,4,4}; cv::Mat m7(3,sz2,CV_32FC3); cv::randu(m7,-1.0f,1.0f); float max=-1000.0f; float len2=0.0f; cv::MatConstIterator_<cv::Vec3f> it=m7.begin<cv::Vec3f>(); while(it!=m7.end<cv::Vec3f>()) { len2=(*it)[0]*(*it)[0]+(*it)[1]*(*it)[1]+(*it)[2]*(*it)[2]; //cout<<(*it)[0]<<" "<<(*it)[1]<<" "<<(*it)[2]<<endl; if(max<len2) max=len2; it++; } cout<<"\nthe Max of Mat 4*4*4 32FC3: "<<max<<endl; //randu cv::Vec4d v4d; cv::randu(v4d,0.0f,1.0f); cout<<v4d[0]<<" "<<v4d[1]<<" "<<v4d[2]<<" "<<v4d[3]<<endl; ////The N-ary Array Iterator: NAryMatIterator const int n_mat_size = 5; const int n_mat_sz[] = { n_mat_size, n_mat_size, n_mat_size }; cv::Mat n_mat( 3, n_mat_sz, CV_32FC1 ); cv::RNG rng; rng.fill( n_mat, cv::RNG::UNIFORM, 0.0f, 1.0f ); const cv::Mat* arrays[] = { &n_mat, 0 }; cv::Mat my_planes[1]; cv::NAryMatIterator nit( arrays, my_planes ); // On each iteration, it.planes[i] will be the current plane of the // i-th array from ‘arrays’. double SumPlanes = 0.f; // Total sum over all planes int n = 0; // Total number of planes for (unsigned int p = 0; p < nit.nplanes; p++, ++nit) { SumPlanes += cv::sum(nit.planes[0])[0]; n++; } cout<<"the sum of NaryIterator: "<<SumPlanes<<endl; return 0; }
相关文章推荐
- python 调用 shell 命令方法
- device eth0 does not seem to be present, delaying initialization
- hadoop 主要配置文件
- [国嵌攻略][106][Linux内存管理子系统]
- linux根目录空间不足解决方案
- Docker Tomcat容器中引用mysql容器
- hadoop 相关操作
- Nginx
- hdu 4405 Aeroplane chess (概率DP)
- CentOS hadoop 分布式集群的搭建
- 极路由 openwrt 使用 SyncY 实现百度云同步
- 安装 Apache 2.4
- Linux内核页表
- linux及安全第二周总结——20135227黄晓妍
- Linux /etc/rc.d 下面 rc${runlevel}.d rc.local init.d 区别
- Docker实践之自定义镜像、推送至远程docker hub
- Python IDLE或Python Shell不支持中文编码的解决方案
- linux dmesg命令参数及用法详解(linux显示开机信息命令)
- CentOS7 yum 安装git
- apache的三种工作模式