0
点赞
收藏
分享

微信扫一扫

【论文阅读】(DiTs)Scalable Diffusion Models with Transformers

向上的萝卜白菜 03-04 10:30 阅读 2
import cv2  
import numpy as np  
  
# 读取图片  
image = cv2.imread(r'D:\dmp\cat.jpg')  
height, width = image.shape[:2]  
  
# 定义三个定位点(这里假设是图片上的坐标),分别表示原点,向量1终点,向量2终点,下例表示顺时针90度
pts1 = np.float32([[100, 100], [50, 100], [100, 200]])  
  
# 计算两个向量  
v1 = pts1[1] - pts1[0]  
v2 = pts1[2] - pts1[0]  
  
# 计算点积和模长  
dot_product = np.dot(v1, v2)  
norm_v1 = np.linalg.norm(v1)  
norm_v2 = np.linalg.norm(v2)  
  
# 计算夹角(弧度)  
angle_rad = np.arccos(dot_product / (norm_v1 * norm_v2))  
angle_deg = np.degrees(angle_rad)  # 将弧度转换为角度  
  
# 确定夹角的方向  
# 如果叉积小于0,则夹角是钝角或平角,需要调整角度到-180到0之间  
cross_product = v1[0] * v2[1] - v1[1] * v2[0]  
if cross_product < 0:  
    angle_deg = -angle_deg  
  
# 映射到[-180, 180]度之间  
angle_deg = (angle_deg + 180) % 360 - 180 
  
# 定义旋转中心点(这里假设是三个点的中心点)  
center = (width // 2, height // 2)
  
# 根据角度和中心点计算旋转矩阵  
M = cv2.getRotationMatrix2D(center, angle_deg, 1)  
  
# 旋转图片  
rotated_image = cv2.warpAffine(image, M, (width, height))  
  
# 显示旋转后的图片  
cv2.imshow('Rotated Image', rotated_image)  
cv2.waitKey(0)  
cv2.destroyAllWindows()  
  
# 保存旋转后的图片(如果需要)  
# cv2.imwrite('path_to_save_rotated_image.jpg', rotated_image)

在这里插入图片描述
在这里插入图片描述

举报

相关推荐

0 条评论