从慕课网《opencv 》相关课程总结而来
#图片裁切
import cv2
img = cv2.imread('G:/1.jpg',1)
imgInfo = img.shape
dst = img[100:200,100:300]
cv2.imshow('image',dst)
cv2.waitKey(0)
#图片移位
#1 API的使用
#2 算法原理
#3 源代码
import cv2
import numpy as np
img = cv2.imread('G:/1.jpg',1)
cv2.imshow('src',img)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
####
matShift = np.float32([[1,0,100],[0,1,200]])#2x3
dst = cv2.warpAffine(img,matShift,(height,width))
cv2.imshow('dst',dst)
cv2.waitKey(0)
#API的原理
#[1,0,100],[0,1,200] 2x2 2x1
#[[1,0],[0,1]] 2x2 A
#[[100],[200]] 2x1 B
#xy c
#AxC+B = [[1*x +0*y],[0*x+1*y]]+[[100],[200]]
# = [[x+100],[y+200]]
#(10,20) -> (110,220)
#通过源码实现位移
import cv2
import numpy as np
img = cv2.imread('G:/1.jpg',1)
cv2.imshow('src',img)
imgInfo = img.shape
#定义一个空矩阵 与原始图片等大
dst = np.zeros(img.shape,np.uint8)
height = imgInfo[0]
width = imgInfo[1]
for i in rang