cv.imread()
CV imread
2023-09-27 14:25:47 时间
cv.imread()读取图片
cv.imread('name',img) 显示图片
cv.waitKey() 窗口等待函数
import cv2
import numpy as np
import random
from PIL import Image
def random_rotate(image,
angles: list,
center = None,
scale_factor= 1.0) -> np.ndarray:
"""Rotate an image by a random angle
Args:
image (np.ndarray): Image read with OpenCV
angles (list): Rotation angle range
center (optional, tuple[int, int]): High resolution image selection center point. Default: ``None``
scale_factor (optional, float): scaling factor. Default: 1.0
Returns:
rotated_image (np.ndarray): image after rotation
"""
image_height, image_width = image.shape[:2]
if center is None:
center = (image_width // 2, image_height // 2)
# Random select specific angle
angle = random.choice(angles)
matrix = cv2.getRotationMatrix2D(center, angle, scale_factor)
rotated_image = cv2.warpAffine(image, matrix, (image_width, image_height))
return rotated_image
if __name__=='__main__':
# img=Image.open('./1.png')
# img.show()
# img=random_rotate(np.array(img),[90,45])
# img=Image.fromarray(img)
# img.show()
img=cv2.imread('./1.png')
img=random_rotate(img,angles=[45,45])
# cv2.imshow('hh',img)
# cv2.waitKey(10000)
img=Image.fromarray(img)
img.show()
注意 opencv读取的图片是array类型,图片格式是bgr。PIL读取的图片是 pil类型,图片的格式是rgb。所以两者在使用要注意相互转换,否则容易出现错误。
相关文章
- 你了解计算机视觉目标分类、识别、检测、分割任务吗,一文读懂这些CV问题
- 2022全国科技周情感计算:CV语义个性化,NLP多模态,Voice语音,人脸情绪,脑电情感
- 详解OpenCV的视频背景/前景分割(背景建模/前景提取)类cv::BackgroundSubtractorKNN,并利用它实现对道路监控视频前景/背景的提取
- OpenCV-Python中的函数cv.imread()读取到的图像的数据存储结构是怎样的?
- CV_CAST_8U(val);的意义
- 看这篇就够了——opencv与libopencv与cv_bridge的安装与使用
- SwiftUI CV视觉App之基于VisionKit扫描卡识别内容 (教程含源码)
- CV项目肢体动作识别(三)内附完整代码和详细讲解
- MatLab Load cv::Mat 导入数据
- Write cv::Mat to a file