You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
1.8 KiB
76 lines
1.8 KiB
#ifndef _DetCommonDefine_
|
|
#define _DetCommonDefine_
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <opencv2/opencv.hpp>
|
|
|
|
// 映射
|
|
struct ROI2ROI_SCALE
|
|
{
|
|
int startx;
|
|
int starty;
|
|
float scalex;
|
|
float scaley;
|
|
ROI2ROI_SCALE()
|
|
{
|
|
Init();
|
|
}
|
|
void Init()
|
|
{
|
|
startx = 0;
|
|
starty = 0;
|
|
scalex = 1;
|
|
scaley = 1;
|
|
}
|
|
void SetCrop(int x, int y)
|
|
{
|
|
startx = x;
|
|
starty = y;
|
|
}
|
|
void setResize(int srcWidth, int srcHeight, int destWidth, int destHeight)
|
|
{
|
|
scalex = destWidth * 1.0f / srcWidth;
|
|
scaley = destHeight * 1.0f / srcHeight;
|
|
}
|
|
void setResize(cv::Mat srcImg, cv::Mat detImg)
|
|
{
|
|
scalex = srcImg.cols * 1.0f / detImg.cols;
|
|
scaley = srcImg.rows * 1.0f / detImg.rows;
|
|
}
|
|
void print(std::string str = "")
|
|
{
|
|
printf("%s startx %d starty %d scalex %f scaley %f\n", str.c_str(), startx, starty, scalex, scaley);
|
|
}
|
|
// 表示先自己 变化 然后做tem
|
|
void add(ROI2ROI_SCALE tem)
|
|
{
|
|
this->startx = this->startx * tem.scalex + tem.startx;
|
|
this->scalex = this->scalex * tem.scalex;
|
|
|
|
this->starty = this->starty * tem.scaley + tem.starty;
|
|
this->scaley = this->scaley * tem.scaley;
|
|
}
|
|
cv::Rect Getroi(cv::Rect roi)
|
|
{
|
|
cv::Rect rect;
|
|
rect.x = roi.x * scalex + startx;
|
|
rect.y = roi.y * scaley + starty;
|
|
rect.width = roi.width * scalex;
|
|
rect.height = roi.height * scaley;
|
|
return rect;
|
|
}
|
|
int UPdateRoi(cv::Rect &roi)
|
|
{
|
|
cv::Rect rect;
|
|
rect.x = roi.x * scalex + startx;
|
|
rect.y = roi.y * scaley + starty;
|
|
rect.width = roi.width * scalex;
|
|
rect.height = roi.height * scaley;
|
|
|
|
roi = rect;
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
#endif |