# pip install opencv-python
import cv2
#open image
img = cv2.imread("xxx.img",cv2.IMREAD_COLOR) #cv2.IMREAD_GRAYSCALE
rows,cols = img.shape
cv2.imshow("image",img)
resize = cv2.resize(img,(640, 480), interpolation = cv2.INTER_CUBIC)
key = cv2.waitKey(0)
if key == 27: #ESC
cv2.destroyAllWindows()
elif key == ord('s'):
cv2.imwrite('xxx1.jpg',resize)
cv2.destroyAllWindows()
#open save video
cap = cv2.VideoCapture('video.mp4') #cv2.VideoCapture(0) -camera
fps =int(cap.get(cv2.CAP_PROP_FPS))
size=(int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
videoWriter=cv2.VideoWriter('xxx.avi',cv2.VideoWriter_fourcc('I','4','2','0'),fps,size)
ret, frame = cap.read()
while(ret):
cv2.imshow("cap",frame)
videoWriter.write(frame)
cv2.waitKey(fps)
ret, frame = cap.read()
if 0xFF ==ord('q'):
break
cap.release()
cv2.destroyAllWindows()
#process
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
img_rgb = img_bgr[...,::-1]