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

在这里插入图片描述

发布了509 篇原创文章 · 获赞 1824 · 访问量 110万+

猜你喜欢

转载自blog.csdn.net/chengyq116/article/details/104648780
今日推荐