如何使用C++实现渐变的放大和缩小效果?

问题描述

我在“矩形”中有一个图像框。该图像中可能有一张或多张面孔。 “faces”数组包含围绕该图像中的人脸绘制的边界框的属性。现在我必须自动放大或缩小到该图像中的那张脸。

我附上了我尝试放大脸部的代码。它运作良好,但我需要帮助转换此功能以执行缩小。还有我使用的放大功能,会立即放大到脸部,但我需要该功能逐渐放大到脸部,以便我可以看到缩放效果。有人可以解决这个问题吗?

提前致谢

copyRectangle = Rectangle;
for (vector<cv::Rect>::const_iterator rect = faces.begin(); rect != faces.end(); ++rect)
 {
                    cv::Rect rr = *rect;
#if 0
                    rr.y = rect->y - 50;
                    rr.x = rect->x - 50;
                    rr.height = rect->height + 50;
                    rr.width = rect->width + 50;
#endif
                    RECT cpyRt;
                    double zf = 0.3;
                    double f1 = static_cast<double>(Rectangle.right - Rectangle.left) / static_cast<double>(Rectangle.bottom - Rectangle.top);
                    double h = rr.height;
                    double w = rr.width * f1;
                    double f2 = w / (static_cast<double>(Rectangle.right) - static_cast<double>(Rectangle.left));
                    
                    if (f2 < zf) {
                        w = w * zf / f2;
                        h = h * zf / f2;
                    }
                    double t = rr.y - ((w - (rr.width * f1)) / 2);
                    double l = rr.x - ((h - rr.height) / 2);
                    if (t < 0) t = 0;
                    if (l < 0) l = 0;
                    if (t + h > Rectangle.bottom) t -= t + h - Rectangle.bottom;
                    if (l + w > Rectangle.right) l -= l + w - Rectangle.right;
                    cpyRt.top = static_cast<int>(t);
      cpyRt.left = static_cast<int>(l);
      cpyRt.bottom = static_cast<int>(t + h); 
      cpyRt.right = static_cast<int>(l + w);

                    if ((copyRectangle.top > cpyRt.top + 50 || copyRectangle.top < cpyRt.top - 50) && (copyRectangle.left > cpyRt.left + 50 || copyRectangle.left < cpyRect.left - 50))
                        copyRectangle = cpyRt;

                    break;
                }```

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)