直接上代码!
#pragma once
#include <opencv2/opencv.hpp>
class MyRect
{
public:
MyRect(cv::Point pt, cv::Size size);
MyRect(int x, int y, int width, int height);
cv::Rect get();
int area();
int width();
int height();
bool contains(cv::Point pt);
cv::Size size();
cv::Point tl();
cv::Point br();
bool isInside(cv::Rect rect1, cv::Rect rect2);
cv::Point getCenterPoint(cv::Rect rect);
cv::Rect rectCenterScale(cv::Rect rect, cv::Size size);
int distance(cv::Rect rect2);
private:
cv::Rect rect;
};
#include "MyRect.h"
MyRect::MyRect(cv::Point pt, cv::Size size)
: rect(pt, size)
{
}
MyRect::MyRect(int x, int y, int width, int height)
: rect(x, y, width, height)
{
}
cv::Rect MyRect::get()
{
return rect;
}
int MyRect::area()
{
return rect.area();
}
int MyRect::width()
{
return rect.width;
}