import argparse
import cv2
parser = argparse.ArgumentParser()
parser.add_argument('--path',default='D:/cookbook_prac/test1.png',help='Image path')
params = parser.parse_args()
img = cv2.imread(params.path)
print('original image shape:',img.shape)
width,height = 128,56
resized_img = cv2.resize(img,(width,height))
print('resized to 128*56 image shape:',resized_img.shape)
w_mult,h_mult = 0.25,0.5
resized_img = cv2.resize(img,(0,0),resized_img,w_mult,h_mult)#这里的(0,0)什么意思啊?
print('image shape:',resized_img.shape)
w_mult,h_mult = 2,4
resized_img = cv2.resize(img,(0,0),resized_img,w_mult,h_mult,cv2.INTER_NEAREST)
print('image shape:',resized_img.shape)
img_flip_along_x = cv2.flip(img,0)
img_flip_along_y = cv2.flip(img,1)
img_flipped_xy = cv2.flip(img,-1)
cv2.imshow('original',img)
cv2.imshow('flip_along_x',img_flip_along_x)
cv2.waitKey()
cv2.imshow('flip_along_y',img_flip_along_y)
cv2.waitKey()
cv2.imshow('flip_along_xy',img_flipped_xy)
cv2.waitKey()
import argparse
import cv2
parser = argparse.ArgumentParser()
parser.add_argument('--path',default='d:/cookbook_prac/test1.png',help='Image Path')
parser.add_argument('--out_png',default='d:/cookbook_prac/compressed.png',
help='Output image path for lossless result.')
parser.add_argument('--out_jpg',default='d:/cookbook_prac/compressed.jpg',
help='Output image path for lossy result.')
params = parser.parse_args()
img = cv2.imread(params.path)
cv2.imwrite(params.out_png,img,[cv2.IMWRITE_PNG_COMPRESSION,0])
saved_img = cv2.imread(params.out_png)
assert saved_img.all() == img.all()
cv2.imwrite(params.out_jpg,img,[cv2.IMWRITE_JPEG_QUALITY,0])