OpenCV - C++ - cv::Mat image_height = image.rows - image_weight = image.cols

OpenCV - C++ - cv::Mat image_height = image.rows - image_weight = image.cols

1. image_height = image.rows - image_weight = image.cols

//============================================================================
// Name        : cv::rectangle
// Author      : Yongqiang Cheng
// Version     : Feb 22, 2020
// Copyright   : Copyright (c) 2019 Yongqiang Cheng
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>

int main(int argc, char** argv)
{
	// First create a black image.
	cv::Mat image(400, 900, CV_8UC3, cv::Scalar(0, 0, 0));

	// Check if the image is created successfully.
	if (!image.data)
	{
		std::cout << "Could not open or find the image" << std::endl;
		exit(EXIT_FAILURE);
	}

	std::cout << "image_height: image.rows = " << image.rows << std::endl;
	std::cout << "image_weight: image.cols = " << image.cols << std::endl;

	// unfilled
	cv::Point p3(400, 300), p4(550, 350);
	cv::Scalar colorRectangle1(0, 0, 255); // (B, G, R) = RED
	int thicknessRectangle1 = 3;

	cv::rectangle(image, p3, p4, colorRectangle1, thicknessRectangle1);

	// filled
	cv::Point p5(100, 250), p6(150, 350);
	cv::Scalar colorRectangle2(255, 0, 0); // (B, G, R) = BLUE

	cv::rectangle(image, p5, p6, colorRectangle2, cv::FILLED);

	cv::namedWindow("Display window", cv::WINDOW_AUTOSIZE);
	cv::imshow("Display window", image);

	cv::waitKey(0);

	return 0;
}

2. Console

image_height: image.rows = 400
image_weight: image.cols = 900

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yongqiang Cheng

梦想不是浮躁,而是沉淀和积累。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值