import sys import cv2 import numpy as np class operating_on_images: def __init__(self,input_file='sunrise.jpg'): self.img=None self.input_file=input_file def load_imge(self): self.img = cv2.imread(self.input_file) cv2.imshow('Original', self.img) def plt_image(self): import matplotlib.pyplot as plt # plt.show() plt.imshow(self.img) plt.show() def image_Cropping(self): h, w = self.img.shape[:2] start_row, end_row = int(0.21*h), int(0.73*h) start_col, end_col= int(0.37*w), int(0.92*w) self.img_cropped =self.img[start_row:end_row, start_col:end_col] cv2.imshow('Cropped', self.img_cropped) def image_resize(self,scaling_factor=1.3): # Resizing an image img_scaled = cv2.resize(self.img, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_LINEAR) cv2.imshow('Uniform resizing', img_scaled) img_scaled = cv2.resize(self.img, (250, 400), interpolation=cv2.INTER_AREA) cv2.imshow('Skewed resizing', img_scaled) def image_save(self): # Save an image output_file = self.input_file[:-4] + '_cropped.jpg' cv2.imwrite(output_file, self.img_cropped) cv2.waitKey() test=operating_on_images() test.load_imge() # test.image_Cropping() # test.image_resize() # test.image_save() test.plt_image()
OpenCV处理图像方法实例
最新推荐文章于 2024-06-27 17:26:21 发布