#include <opencv/opencv2.hpp>
using namespace std;
int main()
{
Rect rect = rect1 & rect2; // 并集
Rect rect = rect1 | rect2; // 交集
Rect rect = rect + point; // 平移
Rect rect = rect + size; // 缩放
rect.Size(); // 返回值 Size
rect.area(); // 返回矩阵面积
rect.contains(Point); // 返回是否包含点
rect.inside(Rect); // 返回是否处于Rect中
rect.tl(); //返回左上角的点
rect.br(); //返回右上角的点
return 0;
}
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat A, C; // 仅创建信息头
A = imread("1.jpg", 1);
Mat B(A); // copy constructor
C = A; // assignment op
Mat D(A, Rect(10, 10, 100, 100)); // 仅新建信息头和指针,共享一个矩阵数据
Mat E = A(Range:all(), Range(1,3)); // 用行和列来定义
Mat F = A.clone(); // 新建一个矩阵数据,复制信息头
Mat G;
A.copyTo(G); // 新建一个矩阵数据,复制信息头
Mat M(2, 2, CV_8UC3, Scalar(0, 0, 255));
M.create(4, 4, CV_8UC3);
Mat E = Mat::eye(4, 4, CV_64F);
Mat O = Mat::ones(2, 2, CV_32F);
Mat Z = Mat::zeros(3, 3, CV_8UC1);
Mat C = (Mat_<double>(3, 3) << 0, -1, 0, -1, 6, -1, 0, 0, 0);
cout << format(C, "python") << ";" << endl; // "python" 可以换成csv, numpy, C
return 0;
}
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
string type2str(int type) {
string r;
uchar depth = type & CV_MAT_DEPTH_MASK;
uchar chans = 1 + (type >> CV_CN_SHIFT);
switch (depth) {
case CV_8U: r = "8U"; break;
case CV_8S: r = "8S"; break;
case CV_16U: r = "16U"; break;
case CV_16S: r = "16S"; break;
case CV_32S: r = "32S"; break;
case CV_32F: r = "32F"; break;
case CV_64F: r = "64F"; break;
default: r = "User"; break;
}
r += "C";
r += (chans + '0');
return r;
}
int main(int argc, char *argv[])
{
Mat srcImage = imread("1.jpg", 100);
cout << type2str(srcImage.type()) << endl;
return 0;
}