#!/usr/bin/env python
# _*_ coding:utf-8 _*_
import cv2 as cv
import numpy as np
src = cv.imread("F:\miao.jpg")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input image", src)
# 宽和高
face = src[50:450, 100:400]
cv.imshow("face", face)
cv.waitKey(0)
cv.destroyAllWindows()
测试结果,如下图
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
import cv2 as cv
import numpy as np
src = cv.imread("F:\miao.jpg")
cv.namedWindow("input image", cv.WINDOW_AUTOSIZE)
cv.imshow("input image", src)
# 宽和高
face = src[50:450, 100:400]
gray = cv.cvtColor(face, cv.COLOR_BGR2GRAY)
backface = cv.cvtColor(gray, cv.COLOR_GRAY2BGR)
src[50:450, 100:400] = backface
cv.imshow("face", src)
cv.waitKey(0)
cv.destroyAllWindows()
测试结果,如下