OpenCV中怎么使用cv::
#include"cv.h"#include"cxcore.h"#include"highgui.h"#include<iostream>usingnamespacest...
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <iostream>
using namespace std;
int main()
{
cv::Mat image=cv::imread("C:\\1.jpg");
cv::Mat image2=cv::imread("C:\\3.jpg");
cv::Mat imageROI;
imageROI=image(cv::Rect(100,100,image2.cols,image2.rows));
image2.copyTo(imageROI);
cv::namedWindow("src");
cv::imshow("src",image);
cv::waitKey();
return 0;
}
出现错误:C:\Users\Jeason\Desktop\新程序\overlay\overlay.cpp(85) : error C2653: 'cv' : is not a class or namespace name
我用的opencv1.0,用c++写的程序 展开
#include "cxcore.h"
#include "highgui.h"
#include <iostream>
using namespace std;
int main()
{
cv::Mat image=cv::imread("C:\\1.jpg");
cv::Mat image2=cv::imread("C:\\3.jpg");
cv::Mat imageROI;
imageROI=image(cv::Rect(100,100,image2.cols,image2.rows));
image2.copyTo(imageROI);
cv::namedWindow("src");
cv::imshow("src",image);
cv::waitKey();
return 0;
}
出现错误:C:\Users\Jeason\Desktop\新程序\overlay\overlay.cpp(85) : error C2653: 'cv' : is not a class or namespace name
我用的opencv1.0,用c++写的程序 展开
2个回答
2015-07-04 · 知道合伙人互联网行家
关注
展开全部
1、使用准备:
using namespace cv;
2、Mat的声明
Mat m=Mat(rows, cols, type);
Mat m=Mat(Size(width,height), type);
Mat A=Mat(3,4,CV_32FC1);
Mat B=Mat(4,3,CV_32FC1);
3、Mat赋值
vector<Point3f>v;//suppose it is already full
Mat m1=Mat(v,true);//boolean value true is necessary in order to copy data from v to m1
CvMat *p1=====??
Mat m2=Mat(p1);
4、Mat之间运算
MatC=2*A*B;
Mat C=C.inv();//Now C is its own inverse matrix
Mat D=A.t();//D is the transposed matrix of A
Mat a=Mat(4,1, CV_32FC3);//a is 4x1, 3 channels
Mat b=a.reshape(1);//b is 4x3, 1 channel
5、单通道Mat元素读写
Mat a=Mat(4,3, CV_32FC1);
floatelem_a=a.at<float>(i,j);//access element aij, with i from 0 to rows-1 and j from 0 to cols-1
Point p=Point(x,y);
floatelem_a=a.at<float>(p);//Warning: y ranges from 0 to rows-1 and x from 0 to cols-1
6、多通道Mat元素读写
template<typename _Tp> _Tp& at(int y,int x); // cxcore.hpp (868)
template<typename _Tp>const _Tp& at(int y,int x)const; // cxcore.hpp (870)
template<typename _Tp> _Tp& at(Point pt); // cxcore.hpp (869)
template<typename _Tp>const _Tp& at(Point pt)const; // cxcore.hpp (871)
// defineded in cxmat.hpp (454-468)
typedefVec<float,2>Vec2f;// cxcore.hpp (254)
// we can access the element like this :
Mat m(Size(3,3), CV_32FC2 );
Vec2f& elem = m.at<Vec2f>( row , col );// or m.at<Vec2f>( Point(col,row) );
elem[0]=1212.0f;
elem[1]=326.0f;
float c1 = m.at<Vec2f>( row , col )[0];// or m.at<Vec2f>( Point(col,row) );
float c2 = m.at<Vec2f>( row , col )[1];
m.at<Vec2f>( row, col )[0]=1986.0f;
m.at<Vec2f>( row, col )[1]=326.0f;
7.选取Mat上指定区域方法
Mat src; Rect rect;
Mat dst = src(rect); 或者Mat dst(src,rect);
using namespace cv;
2、Mat的声明
Mat m=Mat(rows, cols, type);
Mat m=Mat(Size(width,height), type);
Mat A=Mat(3,4,CV_32FC1);
Mat B=Mat(4,3,CV_32FC1);
3、Mat赋值
vector<Point3f>v;//suppose it is already full
Mat m1=Mat(v,true);//boolean value true is necessary in order to copy data from v to m1
CvMat *p1=====??
Mat m2=Mat(p1);
4、Mat之间运算
MatC=2*A*B;
Mat C=C.inv();//Now C is its own inverse matrix
Mat D=A.t();//D is the transposed matrix of A
Mat a=Mat(4,1, CV_32FC3);//a is 4x1, 3 channels
Mat b=a.reshape(1);//b is 4x3, 1 channel
5、单通道Mat元素读写
Mat a=Mat(4,3, CV_32FC1);
floatelem_a=a.at<float>(i,j);//access element aij, with i from 0 to rows-1 and j from 0 to cols-1
Point p=Point(x,y);
floatelem_a=a.at<float>(p);//Warning: y ranges from 0 to rows-1 and x from 0 to cols-1
6、多通道Mat元素读写
template<typename _Tp> _Tp& at(int y,int x); // cxcore.hpp (868)
template<typename _Tp>const _Tp& at(int y,int x)const; // cxcore.hpp (870)
template<typename _Tp> _Tp& at(Point pt); // cxcore.hpp (869)
template<typename _Tp>const _Tp& at(Point pt)const; // cxcore.hpp (871)
// defineded in cxmat.hpp (454-468)
typedefVec<float,2>Vec2f;// cxcore.hpp (254)
// we can access the element like this :
Mat m(Size(3,3), CV_32FC2 );
Vec2f& elem = m.at<Vec2f>( row , col );// or m.at<Vec2f>( Point(col,row) );
elem[0]=1212.0f;
elem[1]=326.0f;
float c1 = m.at<Vec2f>( row , col )[0];// or m.at<Vec2f>( Point(col,row) );
float c2 = m.at<Vec2f>( row , col )[1];
m.at<Vec2f>( row, col )[0]=1986.0f;
m.at<Vec2f>( row, col )[1]=326.0f;
7.选取Mat上指定区域方法
Mat src; Rect rect;
Mat dst = src(rect); 或者Mat dst(src,rect);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询