微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何使用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 举报,一经查实,本站将立刻删除。