对于我的图像处理项目,我想让用户在给定的图像中选择一个点,并将该坐标作为参数来定义特定图像旋转的中心点。在下面的代码中,我定义了一个方法来围绕给定位置参数的中心旋转图像。你能帮助我理解如何让用户定义旋转中心点吗?你知道吗
In here if row_position == 1/2 and col_position == 1/4 it means
y = 1/2 * total_number_of_rows_in_image , x = 1/4 * total_number_of_columns_in_image
def rotateImage(baseImage,degree,rowPosition,colPosition):
rowsNew,colsNew,channels=baseImage.shape
centre=[rowPosition,colPosition]#these are fractional values
rotationMatrix=cv2.getRotationMatrix2D(((colsNew*centre[1]),(rowsNew*centre[0])),degree,1)
rotatedImg=cv2.warpAffine(baseImage,rotationMatrix,(colsNew,rowsNew))
return rotatedImg
您可以使用鼠标回调函数:
只需双击图像内部,将
x
和y
坐标分别存储到ix
和iy
全局变量中,然后按a
按钮调用具有中心值的rotateImage
函数,并围绕此中心旋转图像。你知道吗相关问题 更多 >
编程相关推荐