#ifndef _DetCommonDefine_ #define _DetCommonDefine_ #include #include #include // 映射 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; } }; struct BlobResult { int nresult; int nYsresult; int type; int area_piexl; float area_mm2; int hj; cv::Rect roi; BlobResult() { Init(); } void Init() { nresult = 0; nYsresult = 0; type = 0; area_piexl = 0; area_mm2 = 0; hj = 0; roi = cv::Rect(0, 0, 0, 0); } }; #endif