python局部图像放大
qq_33687272 人气:0import cv2 as cv import sys if __name__ == '__main__': #读取图像并判断是否读取成功 img = cv.imread('tu.jpg') #需要放大的部分 part = img[300:400,250:350] #双线性插值法 mask = cv.resize(part, (300, 300), fx=0, fy=0, interpolation=cv.INTER_LINEAR) if img is None is None: print('Failed to read picture') sys.exit() #放大后局部图的位置img[210:410,670:870] img[110:410,570:870]=mask #画框并连线 cv.rectangle(img,(250,300),(350,400),(0,255,0),1) cv.rectangle(img,(570,110),(870,410),(0,255,0),1) img = cv.line(img,(350,300),(570,110),(0,255,0)) img = cv.line(img,(350,400),(570,410),(0,255,0)) #展示结果 cv.imshow('img',img) cv.waitKey(0) cv.destroyAllWindows()
原图:
结果:
加载全部内容