python cv2.flip
时间: 2023-10-04 16:06:02 浏览: 49
The cv2.flip() function in Python is a method in the OpenCV library that is used to flip an image or video stream horizontally or vertically.
Syntax:
cv2.flip(src, flipCode)
Parameters:
- src: Input image or video stream.
- flipCode: The flipCode parameter specifies the axis of flipping. It can take on one of three values:
- 0: Flips the image or video stream vertically around the x-axis.
- 1: Flips the image or video stream horizontally around the y-axis.
- -1: Flips the image or video stream both vertically and horizontally.
Return Value:
The function returns the flipped image or video stream.
Example:
```python
import cv2
# Load the image
image = cv2.imread("image.jpg")
# Flip the image horizontally
flipped_image = cv2.flip(image, 1)
# Display the original and flipped images
cv2.imshow("Original Image", image)
cv2.imshow("Flipped Image", flipped_image)
cv2.waitKey(0)
```
In the above example, we load an image using the imread() function and then flip it horizontally using the cv2.flip() function with the flipCode parameter set to 1. Finally, we display both the original and flipped images using the imshow() function.