笔记代码
""" ROI 感兴趣区域 """
import cv2
import numpy as np
img = cv2.imread('img.jpg')
cv2.namedWindow('Image', cv2.WINDOW_AUTOSIZE)
cv2.imshow('Image', img)
cut = img[20:200, 20:200]
img_copy = img.copy()
cv2.imshow('CUT', cut)
cut_reverse = cv2.cvtColor(cut, cv2.COLOR_BGR2GRAY)
cv2.imshow('cut reverse', cut_reverse)
cut_back = cv2.cvtColor(cut_reverse, cv2.COLOR_GRAY2BGR)
cv2.imshow('cut back', cut_back)
img[20:200, 20:200] = cut_back
cv2.imshow('changed', img)
img_copy[20:200, 20:200] = cut/2
cv2.imshow('img copy', img_copy)
cv2.waitKey(0)
cv2.destroyAllWindows()
效果截图