我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用imutils.rotate()。
def transformations(src, choice): if choice == 0: # Rotate 90 src = cv2.rotate(src, rotateCode=cv2.ROTATE_90_CLOCKWISE) if choice == 1: # Rotate 90 and flip horizontally src = cv2.rotate(src, rotateCode=cv2.ROTATE_90_CLOCKWISE) src = cv2.flip(src, flipCode=1) if choice == 2: # Rotate 180 src = cv2.rotate(src, rotateCode=cv2.ROTATE_180) if choice == 3: # Rotate 180 and flip horizontally src = cv2.rotate(src, rotateCode=cv2.ROTATE_180) src = cv2.flip(src, flipCode=1) if choice == 4: # Rotate 90 counter-clockwise src = cv2.rotate(src, rotateCode=cv2.ROTATE_90_COUNTERCLOCKWISE) if choice == 5: # Rotate 90 counter-clockwise and flip horizontally src = cv2.rotate(src, rotateCode=cv2.ROTATE_90_COUNTERCLOCKWISE) src = cv2.flip(src, flipCode=1) return src
def rotating_example(): img = cv2.imread('./data/hi.jpg') vwriter = VideoWriterRGB('hi-video.avi') frames = 0 for angle in range(0, 360, 5): rot = imutils.rotate(img, angle=angle) cv2.imshow("Angle = %d" % (angle), rot) vwriter.addFrame(rot) frames += 1 for angle in range(360, 0, -5): rot = imutils.rotate(img, angle=angle) cv2.imshow("Angle = %d" % (angle), rot) vwriter.addFrame(rot) frames += 1 vwriter.finalise() print("Created movie with %d frames" % frames)
def transformations2(src, choice): mode = choice // 2 src = imutils.rotate(src, mode * 90) if choice % 2 == 1: src = cv2.flip(src, flipCode=1) return src