c++ 中矩形函数的使用 objective-c
rectangle function use in c++ objective-c
您好,我一直在尝试在面部检测矩形之后绘制第二个矩形,但参数 x、y、h、w 让我感到困惑。我在变量中尝试了不同的值,但我不明白它们的确切含义。
我知道 x, y 应该移动到所需的位置,而 h, w, 应该重新调整它的大小。
- (void)processImage:(cv::Mat &)image {
Mat gray;
std::vector<cv::Rect> faces;
Scalar color = Scalar(0, 255, 0);
cvtColor(image, gray, COLOR_BGR2GRAY);
_faceDetector.detectMultiScale(gray, faces, 1.1, 2, 0, cv::Size(60, 60));
for (int i = 0; i < faces.size(); i++) {
rectangle(image, faces[i], color, 1);
// x, y should move the rectangle to the desired position
int x = faces[i].x;
int y = faces[i].y;
x=x+y;
y=y+x;
// h, w should resize the rectangle
int he = y+faces[i].height*0.1 ;
int we = x+faces[i].width*0.1;
rectangle(image, cv::Point (x, y), cv::Point (we, he), Scalar(255,0,255),2,8,0);
}
}
任何人都可以向我提供带有矩形的示意图(图形)并请放置 x、y、h、w 的值。谢谢
x
是X坐标,y
是Y坐标。 h
和w
分别代表高度和宽度。
考虑以下矩形:
A --------- B
| |
| |
C --------- D
它的位置(原点)由点A
定义,其他角点相对于A
定义。
A = (x, y)
B = (x + width, y)
C = (x, y + height)
D = (x + width, y + height)
您可能还应该重新访问
x=x+y;
y=y+x;
为什么跨不同轴添加坐标有意义?
此外,使用在上一行中被覆盖的 x
值很可能会出现问题。与初始值相比,您的计算结果为
finalX = x + y
finalY = y + (x + y) // because you're using the modified value of x
您好,我一直在尝试在面部检测矩形之后绘制第二个矩形,但参数 x、y、h、w 让我感到困惑。我在变量中尝试了不同的值,但我不明白它们的确切含义。 我知道 x, y 应该移动到所需的位置,而 h, w, 应该重新调整它的大小。
- (void)processImage:(cv::Mat &)image {
Mat gray;
std::vector<cv::Rect> faces;
Scalar color = Scalar(0, 255, 0);
cvtColor(image, gray, COLOR_BGR2GRAY);
_faceDetector.detectMultiScale(gray, faces, 1.1, 2, 0, cv::Size(60, 60));
for (int i = 0; i < faces.size(); i++) {
rectangle(image, faces[i], color, 1);
// x, y should move the rectangle to the desired position
int x = faces[i].x;
int y = faces[i].y;
x=x+y;
y=y+x;
// h, w should resize the rectangle
int he = y+faces[i].height*0.1 ;
int we = x+faces[i].width*0.1;
rectangle(image, cv::Point (x, y), cv::Point (we, he), Scalar(255,0,255),2,8,0);
}
}
任何人都可以向我提供带有矩形的示意图(图形)并请放置 x、y、h、w 的值。谢谢
x
是X坐标,y
是Y坐标。 h
和w
分别代表高度和宽度。
考虑以下矩形:
A --------- B
| |
| |
C --------- D
它的位置(原点)由点A
定义,其他角点相对于A
定义。
A = (x, y)
B = (x + width, y)
C = (x, y + height)
D = (x + width, y + height)
您可能还应该重新访问
x=x+y;
y=y+x;
为什么跨不同轴添加坐标有意义?
此外,使用在上一行中被覆盖的 x
值很可能会出现问题。与初始值相比,您的计算结果为
finalX = x + y
finalY = y + (x + y) // because you're using the modified value of x