我是靠谱客的博主 拼搏云朵,最近开发中收集的这篇文章主要介绍OpenCV - C++ - cv::Rect OpenCV - C++ - cv::Rect ,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

OpenCV - C++ - cv::Rect

https://docs.opencv.org/4.2.0/dc/d84/group__core__basic.html

cv::Rect_< _Tp > Class Template Reference
Template class for 2D rectangles.

1. cv::Rect - Open Declaration

For your convenience, the Rect_<> alias is available: cv::Rect

template<typename _Tp> class Rect_
{
public:
    typedef _Tp value_type;

    //! default constructor
    Rect_();
    Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
    Rect_(const Rect_& r);
    Rect_(Rect_&& r) CV_NOEXCEPT;
    Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
    Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);

    Rect_& operator = ( const Rect_& r );
    Rect_& operator = ( Rect_&& r ) CV_NOEXCEPT;
    //! the top-left corner
    Point_<_Tp> tl() const;
    //! the bottom-right corner
    Point_<_Tp> br() const;

    //! size (width, height) of the rectangle
    Size_<_Tp> size() const;
    //! area (width*height) of the rectangle
    _Tp area() const;
    //! true if empty
    bool empty() const;

    //! conversion to another data type
    template<typename _Tp2> operator Rect_<_Tp2>() const;

    //! checks whether the rectangle contains the point
    bool contains(const Point_<_Tp>& pt) const;

    _Tp x; //!< x coordinate of the top-left corner
    _Tp y; //!< y coordinate of the top-left corner
    _Tp width; //!< width of the rectangle
    _Tp height; //!< height of the rectangle
};

typedef Rect_<int> Rect2i;
typedef Rect_<float> Rect2f;
typedef Rect_<double> Rect2d;
typedef Rect2i Rect;

2. Example

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

#include <iostream>
#include <opencv2/opencv.hpp>
#include <X11/Xlib.h>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
	int screen_num(0);
	int width(0);
	int height(0);
	unsigned long background(0);
	unsigned long border(0);

	Display *x11_info;
	Screen *screen_info;

	/* First connect to the display server. */
	x11_info = XOpenDisplay(NULL);
	if (!x11_info)
	{
		cerr << "Unable to connect to display" << endl;
		return 1;
	}

	screen_info = DefaultScreenOfDisplay(x11_info);
	height = screen_info->height;
	width = screen_info->width;

	Rect screen_rect(0, 0, screen_info->width, screen_info->height);

	/* These are macros that pull useful data out of the display object. */
	/* We use these bits of info enough to want them in their own variables. */
	screen_num = DefaultScreen(x11_info);

	background = BlackPixel(x11_info, screen_num);
	border = WhitePixel(x11_info, screen_num);

	cout << "the height of the screen in pixels: " << height << endl;
	cout << "the width of the screen in pixels: " << width << endl;
	cout << "the black pixel value for the specified screen: " << background << endl;
	cout << "the white pixel value for the specified screen: " << border << endl;
	cout << "the default screen number referenced by the XOpenDisplay() function: " << screen_num << endl;

	cout << "nx coordinate of the top-left corner: " << screen_rect.x << endl;
	cout << "y coordinate of the top-left corner: " << screen_rect.y << endl;
	cout << "width of the rectangle: " << screen_rect.width << endl;
	cout << "height of the rectangle: " << screen_rect.height << endl;

	return 0;
}

15:36:43 **** Build of configuration Debug for project DisplayImage ****
make all 
Building file: ../src/DisplayImage.cpp
Invoking: GCC C++ Compiler
g++ -std=c++0x -I/usr/local/include -I/usr/local/include/opencv4 -I/usr/local/include/opencv4/opencv2 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/DisplayImage.d" -MT"src/DisplayImage.o" -o "src/DisplayImage.o" "../src/DisplayImage.cpp"
Finished building: ../src/DisplayImage.cpp
 
Building target: DisplayImage
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "DisplayImage"  ./src/DisplayImage.o   -lopencv_core -lX11 -lopencv_video -lopencv_ml -lopencv_imgproc -lopencv_img_hash -lopencv_flann -lopencv_features2d -lopencv_calib3d -lopencv_dnn -lopencv_dnn_objdetect -lopencv_cvv -lopencv_text -lopencv_datasets -lopencv_aruco -lopencv_bgsegm -lopencv_shape -lopencv_imgcodecs -lopencv_videoio -lopencv_highgui -lopencv_bioinspired
Finished building target: DisplayImage
 

15:36:46 Build Finished (took 2s.733ms)
the height of the screen in pixels: 1080
the width of the screen in pixels: 1920
the black pixel value for the specified screen: 0
the white pixel value for the specified screen: 16777215
the default screen number referenced by the XOpenDisplay() function: 0

x coordinate of the top-left corner: 0
y coordinate of the top-left corner: 0
width of the rectangle: 1920
height of the rectangle: 1080

最后

以上就是拼搏云朵为你收集整理的OpenCV - C++ - cv::Rect OpenCV - C++ - cv::Rect 的全部内容,希望文章能够帮你解决OpenCV - C++ - cv::Rect OpenCV - C++ - cv::Rect 所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部