In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use pytorch expansion algorithm to achieve big eye effect," interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to use pytorch expansion algorithm to achieve big eye effect"!
Algorithm idea:
With the eye center as the center point, the eye area is enlarged outward to achieve the effect of large eyes. The basic formula for large eyes is as follows:
Suppose that the eye center point is O(x,y), the radius of the large eye area is Radius, and the current point is A(x1,y1). Improve it by adding the large eye degree control variable Intensity, where the intensity range is 0~100.
where dis represents the Euclidean distance of AO, k represents the scaling factor, k0 represents the degree of eye widening, and xd,yd represents the coordinates of the target point B after the eye widening transformation of point A.
When k=0, target point B coincides with point O.
When k=1, target point B coincides with point A.
When k1.0, the calculation function of the target point B decreases monotonically, and the eye shrinks.
radius of human eye,
Calculate the radius of the big eye area according to the two key points on the left and right of the eye
Big eye intensity calculation method
According to the image resolution, combined with practical experience to calculate the Intensity of large eye degree.
Intensity = 15*512*512/(width*height)
Application scenarios:
Works well with any spherical partial deformation scene, such as big eyes, such as lips smiling.
code implementation: import cv2import mathimport numpy as np def big_eye_adjust_fast(src, PointX, PointY, Radius, Strength): processed_image = np.zeros(src.shape, np.uint8) processed_image = src.copy() height = src.shape[0] width = src.shape[1] PowRadius = Radius * Radius maskImg = np.zeros(src.shape[:2], np.uint8) cv2.circle(maskImg, (PointX, PointY), math.ceil(Radius), (255, 255, 255), -1) mapX = np.vstack([np.arange(width).astype(np.float32).reshape(1, -1)] * height) mapY = np.hstack([np.arange(height).astype(np.float32).reshape(-1, 1)] * width) OffsetX = mapX - PointX OffsetY = mapY - PointY XY = OffsetX * OffsetX + OffsetY * OffsetY ScaleFactor = 1 - XY / PowRadius ScaleFactor = 1 - Strength / 100 * ScaleFactor UX = OffsetX * ScaleFactor + PointX UY = OffsetY * ScaleFactor + PointY UX[UX
< 0] = 0 UX[UX >= width] = width - 1 UY[UY
< 0] = 0 UY[UY >= height] = height - 1 np.copyto(UX, mapX, where=maskImg == 0) np.copyto(UY, mapY, where=maskImg == 0) UX = UX.astype(np.float32) UY = UY.astype(np.float32) processed_image = cv2.remap(src, UX, UY, interpolation=cv2.INTER_LINEAR) return processed_image image = cv2.imread ("tests/images/klst.jpeg")processed_image = image.copy()PointX_left, PointY_left, Radius_left, Strength_left = 150, 190, 44, 19.78PointX_right, PointY_right, Radius_right, Strength_right = 244, 194, 42, 19.78processed_image = big_eye_adjust_fast (processed_image, PointX_left, PointY_left, Radius_left, Strength_left)processed_image = big_eye_adjust_fast(processed_image, PointX_right, PointY_right, Radius_right, Strength_right)cv2.imwrite("big.jpg", processed_image) Results:
At this point, I believe that everyone has a deeper understanding of "how to use pytorch expansion algorithm to achieve big eye effect," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 216
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.