#include
#include
int main(){
// 新建4x5大小的0 矩阵 不要用4行5列来理解
cv::Mat zeros = cv::Mat::zeros(cv::Size(4,5),CV_8UC1);
std::cout<
输出:
[ 0, 0, 0, 0;
0, 0, 0, 0;
0, 0, 0, 0;
0, 0, 0, 0;
0, 0, 0, 0]
5
4
实际业务中一般都是填充不规则区域,这里为了演示的直观点,直接填充了一个矩形区域,我们将4x5大小的矩阵 第1,2(起点为0)行全部填充1
#include
#include
#include
int main(){
// 新建4x5大小的0 矩阵 不要用4行5列来理解
cv::Mat zeros = cv::Mat::zeros(cv::Size(4,5),CV_8UC1);
// std::cout< pts;
pts.push_back(cv::Point(0,1));
pts.push_back(cv::Point(0,2));
pts.push_back(cv::Point(3,1));
pts.push_back(cv::Point(3,2));
std::vector> ppts;
ppts.push_back(pts);
cv::fillPoly(zeros , ppts, (1));
std::cout<
输出:
[ 0, 0, 0, 0;
1, 1, 1, 1;
1, 1, 1, 1;
0, 0, 0, 0;
0, 0, 0, 0]
假设我现在需要把上面第1,2(起点为0)填充为1的矩阵,取出点(1,0)的坐标
#include
#include
#include
int main(){
// 新建4x5大小的0 矩阵 不要用4行5列来理解
cv::Mat zeros = cv::Mat::zeros(cv::Size(4,5),CV_8UC1);
// std::cout< pts;
pts.push_back(cv::Point(0,1));
pts.push_back(cv::Point(0,2));
pts.push_back(cv::Point(3,1));
pts.push_back(cv::Point(3,2));
std::vector> ppts;
ppts.push_back(pts);
cv::fillPoly(zeros , ppts, (1));
std::cout<(1,0)< (cv::Point(1,0))<(0,1)<
输出:
[ 0, 0, 0, 0;
1, 1, 1, 1;
1, 1, 1, 1;
0, 0, 0, 0;
0, 0, 0, 0]
0
0
现在我们打印上面矩阵的所有行,0-2列(起点为0),下面的代码实际没有打印出第二列
#include
#include
#include
int main(){
// 新建4x5大小的0 矩阵 不要用4行5列来理解
cv::Mat zeros = cv::Mat::zeros(cv::Size(4,5),CV_8UC1);
// std::cout< pts;
pts.push_back(cv::Point(0,1));
pts.push_back(cv::Point(0,2));
pts.push_back(cv::Point(3,1));
pts.push_back(cv::Point(3,2));
std::vector> ppts;
ppts.push_back(pts);
cv::fillPoly(zeros , ppts, (1));
std::cout<(1,0)< (cv::Point(1,0))<(0,1)<
输出:
[ 0, 0, 0, 0;
1, 1, 1, 1;
1, 1, 1, 1;
0, 0, 0, 0;
0, 0, 0, 0]
[ 0, 0;
1, 1;
1, 1;
0, 0;
0, 0]